From 4b8891d0395ac2a1d9e37590db8976493d12c25f Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 17 Jun 2022 16:53:33 +0200 Subject: [PATCH] Substituting the vsphere objects from fb_tools.vsphere to the separate fb_vmware module --- bin/create-vmware-template | 2 +- etc/create-vmware-template.ini.default | 4 ++++ lib/cr_vmware_tpl/app.py | 16 +++++++------- lib/cr_vmware_tpl/config.py | 28 ++++++------------------- lib/cr_vmware_tpl/handler.py | 29 +++++++++++++++++--------- 5 files changed, 38 insertions(+), 41 deletions(-) diff --git a/bin/create-vmware-template b/bin/create-vmware-template index 63745de..38e7507 100755 --- a/bin/create-vmware-template +++ b/bin/create-vmware-template @@ -52,7 +52,7 @@ app.initialized = True if app.verbose > 2: print("{c}-Object:\n{a}".format(c=app.__class__.__name__, a=app)) -app() +# app() sys.exit(0) diff --git a/etc/create-vmware-template.ini.default b/etc/create-vmware-template.ini.default index b90dca3..a5e3e7d 100644 --- a/etc/create-vmware-template.ini.default +++ b/etc/create-vmware-template.ini.default @@ -76,6 +76,10 @@ # root_dir = /var/lib/cobbler +# templates_tir = templates + +# snippets_dir = snippets + # profile = # profile_repos = pp-centos8-baseos diff --git a/lib/cr_vmware_tpl/app.py b/lib/cr_vmware_tpl/app.py index 6bbf6b1..302cdd5 100644 --- a/lib/cr_vmware_tpl/app.py +++ b/lib/cr_vmware_tpl/app.py @@ -38,7 +38,7 @@ from .xlate import __base_dir__ as __xlate_base_dir__ from .xlate import __mo_file__ as __xlate_mo_file__ from .xlate import XLATOR, LOCALE_DIR, DOMAIN -__version__ = '1.3.1' +__version__ = '1.4.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -260,10 +260,10 @@ class CrTplApplication(BaseApplication): self.perform_arg_parser_vmware() - if not self.config.password: + if not self.config.vsphere_info.password: prompt = (_('Enter password for host {h!r} and user {u!r}:') + ' ').format( - h=self.config.vsphere_host, u=self.config.vsphere_user) - self.config.password = getpass.getpass(prompt=prompt) + h=self.config.vsphere_info.host, u=self.config.vsphere_info.user) + self.config.vsphere_info.password = getpass.getpass(prompt=prompt) self.handler = CrTplHandler( appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, @@ -375,13 +375,13 @@ class CrTplApplication(BaseApplication): """ if self.args.host: - self.config.vsphere_host = self.args.host + self.config.vsphere_info.host = self.args.host if self.args.port: - self.config.vsphere_port = self.args.port + self.config.vsphere_info.port = self.args.port if self.args.user: - self.config.vsphere_user = self.args.user + self.config.vsphere_info.user = self.args.user if self.args.password: - self.config.password = self.args.password + self.config.vsphere_info.password = self.args.password if self.args.cluster: self.config.vsphere_cluster = self.args.cluster if self.args.folder: diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index 51161bf..1df33fc 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -120,12 +120,7 @@ class CrTplConfiguration(BaseConfiguration): self.os_id = self.default_os_id - self.vsphere_host = self.default_vsphere_host - self.vsphere_port = self.default_vsphere_port - self.vsphere_user = self.default_vsphere_user self.vsphere_cluster = self.default_vsphere_cluster - self.dc = self.default_dc - self.password = None self.folder = self.default_folder self.template_name = self.default_template_name self.data_size_gb = self.default_data_size_gb @@ -143,11 +138,6 @@ class CrTplConfiguration(BaseConfiguration): self.vmware_cfg_version = self.default_vmware_cfg_version self.os_version = self.default_os_version - self.vsphere_info = VSPhereConfigInfo( - host=self.default_vsphere_host, port=self.default_vsphere_port, dc=self.default_dc, - use_https=True, user=self.default_vsphere_user, - appname=self.appname, verbose=self.verbose, base_dir=self.base_dir) - self.storage_cluster = self.default_storage_cluster self.tpl_vm_domain = self.default_tpl_vm_domain @@ -183,6 +173,12 @@ class CrTplConfiguration(BaseConfiguration): encoding=encoding, config_dir=config_dir, config_file=config_file, initialized=False, ) + self.vsphere_info = VSPhereConfigInfo( + host=self.default_vsphere_host, port=self.default_vsphere_port, dc=self.default_dc, + use_https=True, user=self.default_vsphere_user, + appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, + initialized=True) + self.private_ssh_key = str(self.base_dir.joinpath('keys', self.ssh_privkey)) if initialized: @@ -258,13 +254,6 @@ class CrTplConfiguration(BaseConfiguration): else: res['root_password'] = '********' - res['password'] = None - if self.password: - if self.verbose > 4: - res['password'] = self.password - else: - res['password'] = '*******' - return res # ------------------------------------------------------------------------- @@ -328,19 +317,15 @@ class CrTplConfiguration(BaseConfiguration): for (key, value) in config.items(section_name): if key.lower() == 'host': - self.vsphere_host = value self.vsphere_info.host = value continue elif key.lower() == 'port': - self.vsphere_port = int(value) self.vsphere_info.port = value continue elif key.lower() == 'user': - self.vsphere_user = value self.vsphere_info.user = value continue elif key.lower() == 'password': - self.password = value self.vsphere_info.password = value continue elif key.lower() == 'cluster': @@ -349,7 +334,6 @@ class CrTplConfiguration(BaseConfiguration): elif key.lower() == 'folder': self.folder = value elif key.lower() == 'dc': - self.dc = value self.vsphere_info.dc = value elif key.lower() == 'max_nr_templates_stay': diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index fbfaa05..f5f97ce 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -32,11 +32,14 @@ from fb_tools.errors import HandlerError, ExpectedHandlerError from fb_tools.handler import BaseHandler -from fb_tools.vsphere.errors import VSphereExpectedError -from fb_tools.vsphere.errors import VSphereDatacenterNotFoundError -from fb_tools.vsphere.server import VsphereServer -from fb_tools.vsphere.iface import VsphereVmInterface -from fb_tools.vsphere.ds import VsphereDatastore +from fb_vmware.errors import VSphereExpectedError +from fb_vmware.errors import VSphereDatacenterNotFoundError + +# from fb_tools.vsphere.server import VsphereServer +from fb_vmware.connect import VsphereConnection + +from fb_vmware.iface import VsphereVmInterface +from fb_vmware.datastore import VsphereDatastore from . import print_section_start, print_section_end @@ -46,7 +49,7 @@ from .cobbler import Cobbler from .xlate import XLATOR -__version__ = '1.9.0' +__version__ = '2.0.0' LOG = logging.getLogger(__name__) TZ = pytz.timezone('Europe/Berlin') @@ -147,13 +150,19 @@ class CrTplHandler(BaseHandler): self.postinstall_errors = None self.cobbler = None - self.vsphere = VsphereServer( + self.vsphere = VsphereConnection( + self.config.vsphere_info, cluster=self.config.vsphere_cluster, appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, - host=self.config.vsphere_host, port=self.config.vsphere_port, - user=self.config.vsphere_user, password=self.config.password, - dc=self.config.dc, cluster=self.config.vsphere_cluster, auto_close=True, simulate=self.simulate, force=self.force, tz=TZ, terminal_has_colors=self.terminal_has_colors, initialized=False) + +# self.vsphere = VsphereServer( +# appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, +# host=self.config.vsphere_host, port=self.config.vsphere_port, +# user=self.config.vsphere_user, password=self.config.password, +# dc=self.config.dc, cluster=self.config.vsphere_cluster, +# auto_close=True, simulate=self.simulate, force=self.force, tz=TZ, +# terminal_has_colors=self.terminal_has_colors, initialized=False) self.cluster = None self.cobbler = Cobbler( -- 2.39.5