From: Frank Brehm Date: Thu, 23 May 2024 08:44:33 +0000 (+0200) Subject: Renaming variable X-Git-Tag: 1.9.1^2~21 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=a9b1cf5054f5371807281faad8ec5afda7930ef3;p=pixelpark%2Fcreate-terraform.git Renaming variable --- diff --git a/lib/create_terraform/app.py b/lib/create_terraform/app.py index dbbe855..5a10649 100644 --- a/lib/create_terraform/app.py +++ b/lib/create_terraform/app.py @@ -42,7 +42,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.3' +__version__ = '1.3.4' LOG = logging.getLogger(__name__) SIGNAL_NAMES = { @@ -530,20 +530,20 @@ class CrTfApplication(BaseApplication): msg = _("No {} given.").format(_('vSphere user name')) raise ExpectedHandlerError(msg) - for vname in self.handler.vsphere.keys(): + for vsphere_name in self.handler.vsphere.keys(): LOG.debug(_("Setting user for vSphere {vs!r} to {usr!r}.").format( - vs=vname, usr=self.handler.vsphere_user)) + vs=vsphere_name, usr=self.handler.vsphere_user)) # Dirty, but else a change of fb_tools would be necessary (later) - self.handler.vsphere[vname]._user = self.handler.vsphere_user + self.handler.vsphere[vsphere_name]._user = self.handler.vsphere_user print('') need_nl = False if not self.handler.vsphere_password: # Get the name of the first (and hopefully only) VSphere - vname = None + vsphere_name = None for vn in self.handler.vsphere.keys(): - vname = vn + vsphere_name = vn break if need_nl: @@ -551,18 +551,18 @@ class CrTfApplication(BaseApplication): prompt = self.colored(_("User password of {!r}").format( self.handler.vsphere_user), 'AQUA') item = _('Password for user {u!r} of vSphere {n} on {h!r}').format( - u=self.handler.vsphere_user, n=vname, h=self.config.vsphere[vname].host) + u=self.handler.vsphere_user, n=vsphere_name, h=self.config.vsphere[vsphere_name].host) item = self.colored(item, 'AQUA') self.handler.vsphere_password = self.get_secret(prompt=prompt, item_name=item) if not self.handler.vsphere_password: msg = _("No {} given.").format(_('password of vSphere user')) raise ExpectedHandlerError(msg) - for vname in self.handler.vsphere.keys(): + for vsphere_name in self.handler.vsphere.keys(): LOG.debug(_("Setting passwort of vSphere {vs!r} user {usr!r}.").format( - vs=vname, usr=self.handler.vsphere_user)) + vs=vsphere_name, usr=self.handler.vsphere_user)) # Dirty, but else a change of fb_tools would be necessary (later) - self.handler.vsphere[vname]._password = self.handler.vsphere_password + self.handler.vsphere[vsphere_name]._password = self.handler.vsphere_password print('') need_nl = False diff --git a/lib/create_terraform/config.py b/lib/create_terraform/config.py index f917f4d..b69d34b 100644 --- a/lib/create_terraform/config.py +++ b/lib/create_terraform/config.py @@ -32,7 +32,7 @@ from .vs_config import VsphereConfig from .xlate import XLATOR -__version__ = '1.9.0' +__version__ = '1.9.1' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -414,15 +414,15 @@ class CrTfConfiguration(BaseConfiguration): # ------------------------------------------------------------------------- def init_vsphere_defaults(self): - for vname in self.default_vsphere_defs.keys(): + for vsphere_name in self.default_vsphere_defs.keys(): - vs_data = self.default_vsphere_defs[vname] + vs_data = self.default_vsphere_defs[vsphere_name] params = { 'appname': self.appname, 'verbose': self.verbose, 'base_dir': self.base_dir, - 'name': vname, + 'name': vsphere_name, 'host': vs_data['host'], 'port': vs_data['port'], 'dc': vs_data['dc'], @@ -437,7 +437,7 @@ class CrTfConfiguration(BaseConfiguration): if self.verbose > 2: LOG.debug(_("Created object:") + '\n' + pp(vsphere.as_dict())) - self.vsphere[vname] = vsphere + self.vsphere[vsphere_name] = vsphere # ------------------------------------------------------------------------- def as_dict(self, short=True, show_secrets=False): diff --git a/lib/create_terraform/handler/first.py b/lib/create_terraform/handler/first.py index 2c81e97..03185b1 100644 --- a/lib/create_terraform/handler/first.py +++ b/lib/create_terraform/handler/first.py @@ -32,7 +32,7 @@ from ..terraform.disk import TerraformDisk from ..xlate import XLATOR -__version__ = '0.1.0' +__version__ = '0.1.1' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -54,8 +54,8 @@ class CrTfHandlerFirstMixin(): if self.pdns: self.pdns.verbose = self.verbose - for vname in self.vsphere: - self.vsphere[vname].verbose = self.verbose + for vsphere_name in self.vsphere: + self.vsphere[vsphere_name].verbose = self.verbose # ------------------------------------------------------------------------- def init_handlers(self): diff --git a/lib/create_terraform/handler/vmware.py b/lib/create_terraform/handler/vmware.py index 4e847cc..262ed98 100644 --- a/lib/create_terraform/handler/vmware.py +++ b/lib/create_terraform/handler/vmware.py @@ -33,7 +33,7 @@ from ..slim_vm import SlimVm from ..xlate import XLATOR -__version__ = '0.2.0' +__version__ = '0.2.1' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -52,8 +52,8 @@ class CrTfHandlerVmwMixin(): LOG.info(_("Collecting all VMWare and local folders ...")) LOG.info(_("Get vSphere datacenter ...")) - for vname in self.vsphere: - self.vsphere[vname].get_datacenter() + for vsphere_name in self.vsphere: + self.vsphere[vsphere_name].get_datacenter() LOG.debug(_("Collecting used vSphere folders.")) self.vsphere_folders = [] @@ -108,17 +108,17 @@ class CrTfHandlerVmwMixin(): # Test for multiple VSphere references found_vspheres = [] for vm in self.vms: - vname = vm.vsphere - if vname not in found_vspheres: - found_vspheres.append(vname) + vsphere_name = vm.vsphere + if vsphere_name not in found_vspheres: + found_vspheres.append(vsphere_name) if len(found_vspheres) > 1: yaml_file_rel = os.path.relpath(str(yaml_file), os.getcwd()) msg = _("There is only one, unique VSPhere definition allowed in a project file.") msg += '\n' msg += _("In {f!r} were found {nr} different VSPhere definitions:").format( f=yaml_file_rel, nr=len(found_vspheres)) - for vname in sorted(found_vspheres, key=str.lower): - msg += '\n * {!r}'.format(vname) + for vsphere_name in sorted(found_vspheres, key=str.lower): + msg += '\n * {!r}'.format(vsphere_name) raise ExpectedHandlerError(msg) self._init_vspheres() @@ -133,19 +133,19 @@ class CrTfHandlerVmwMixin(): for vm in self.vms: if vm.vsphere in self.vsphere: continue - vname = vm.vsphere - LOG.debug(_("Initializing VSphere {!r} ...").format(vname)) - if vname not in self.config.vsphere: - msg = _("VSPhere {!r} not defined in configuration.").format(vname) + vsphere_name = vm.vsphere + LOG.debug(_("Initializing VSphere {!r} ...").format(vsphere_name)) + if vsphere_name not in self.config.vsphere: + msg = _("VSPhere {!r} not defined in configuration.").format(vsphere_name) raise ExpectedHandlerError(msg) - if not self.vsphere_user and self.config.vsphere[vname].user: + if not self.vsphere_user and self.config.vsphere[vsphere_name].user: LOG.debug(_("Setting {st} to {what!r}.").format( - st='handler.vsphere_user', what=self.config.vsphere[vname].user)) - self.vsphere_user = self.config.vsphere[vname].user - if not self.vsphere_password and self.config.vsphere[vname].password: + st='handler.vsphere_user', what=self.config.vsphere[vsphere_name].user)) + self.vsphere_user = self.config.vsphere[vsphere_name].user + if not self.vsphere_password and self.config.vsphere[vsphere_name].password: LOG.debug(_("Setting {}.").format('handler.vsphere_password')) - self.vsphere_password = self.config.vsphere[vname].password + self.vsphere_password = self.config.vsphere[vsphere_name].password try: params = { @@ -161,8 +161,8 @@ class CrTfHandlerVmwMixin(): connect_info = VSPhereConfigInfo( appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, - host=self.config.vsphere[vname].host, port=self.config.vsphere[vname].port, - dc=self.config.vsphere[vname].dc, user=self.vsphere_user, + host=self.config.vsphere[vsphere_name].host, port=self.config.vsphere[vsphere_name].port, + dc=self.config.vsphere[vsphere_name].dc, user=self.vsphere_user, password=self.vsphere_password, initialized=True) params['connect_info'] = connect_info @@ -176,7 +176,7 @@ class CrTfHandlerVmwMixin(): LOG.debug(msg) vsphere = VsphereConnection(**params) - self.vsphere[vname] = vsphere + self.vsphere[vsphere_name] = vsphere except VSphereExpectedError as e: raise ExpectedHandlerError(str(e)) @@ -187,11 +187,11 @@ class CrTfHandlerVmwMixin(): if self.stop_at_step == 'vmw-test': self.incr_verbosity() - for vname in self.vsphere.keys(): + for vsphere_name in self.vsphere.keys(): try: - vsphere = self.vsphere[vname] + vsphere = self.vsphere[vsphere_name] vsphere.get_about() if self.verbose > 2: @@ -237,9 +237,9 @@ class CrTfHandlerVmwMixin(): if self.stop_at_step == 'vmw-clusters': self.incr_verbosity() - for vname in self.vsphere: - LOG.debug(_("Searching for clusters in VSPhere {!r} ...").format(vname)) - self.vsphere[vname].get_clusters() + for vsphere_name in self.vsphere: + LOG.debug(_("Searching for clusters in VSPhere {!r} ...").format(vsphere_name)) + self.vsphere[vsphere_name].get_clusters() LOG.info(_("Finished step {!r}.").format('vmw-clusters')) if self.stop_at_step == 'vmw-clusters': @@ -272,10 +272,10 @@ class CrTfHandlerVmwMixin(): nr_total = 0 - for vname in self.vsphere: - LOG.debug(_("Searching for datastores in VSPhere {!r} ...").format(vname)) - self.vsphere[vname].get_datastores() - nr_total += len(self.vsphere[vname].datastores.keys()) + for vsphere_name in self.vsphere: + LOG.debug(_("Searching for datastores in VSPhere {!r} ...").format(vsphere_name)) + self.vsphere[vsphere_name].get_datastores() + nr_total += len(self.vsphere[vsphere_name].datastores.keys()) if nr_total: msg = ngettext("Found one datastore.", "Found {n} datastores.", nr_total) @@ -295,10 +295,10 @@ class CrTfHandlerVmwMixin(): if self.stop_at_step == 'vmw-ds-clusters': self.incr_verbosity() - for vname in self.vsphere: - LOG.debug(_("Searching for datastore clusters in VSPhere {!r} ...").format(vname)) - self.vsphere[vname].get_ds_clusters() - nr_total += len(self.vsphere[vname].ds_clusters.keys()) + for vsphere_name in self.vsphere: + LOG.debug(_("Searching for datastore clusters in VSPhere {!r} ...").format(vsphere_name)) + self.vsphere[vsphere_name].get_ds_clusters() + nr_total += len(self.vsphere[vsphere_name].ds_clusters.keys()) if nr_total: msg = ngettext( @@ -319,14 +319,14 @@ class CrTfHandlerVmwMixin(): if self.stop_at_step == 'vmw-networks': self.incr_verbosity() - for vname in self.vsphere: - LOG.debug(_("Searching for networks in VSPhere {!r} ...").format(vname)) - self.vsphere[vname].get_networks() + for vsphere_name in self.vsphere: + LOG.debug(_("Searching for networks in VSPhere {!r} ...").format(vsphere_name)) + self.vsphere[vsphere_name].get_networks() if self.eval_errors: msg = ngettext( "Found one error in exploring vSphere {v!r} resources.", "Found {n} errors in exploring vSphere {v!r} resources.", - self.eval_errors).format(n=self.eval_errors, v=vname) + self.eval_errors).format(n=self.eval_errors, v=vsphere_name) raise ExpectedHandlerError(msg) LOG.info(_("Finished step {!r}.").format('vmw-networks')) @@ -538,36 +538,36 @@ class CrTfHandlerVmwMixin(): for vm in self.vms: - vname = vm.vsphere - if vname not in clusters: - clusters[vname] = {} + vsphere_name = vm.vsphere + if vsphere_name not in clusters: + clusters[vsphere_name] = {} if vm.cluster in clusters: - clusters[vname][vm.cluster].append(vm.name) + clusters[vsphere_name][vm.cluster].append(vm.name) else: - clusters[vname][vm.cluster] = [vm.name] + clusters[vsphere_name][vm.cluster] = [vm.name] - for vname in clusters.keys(): - for cluster in clusters[vname].keys(): + for vsphere_name in clusters.keys(): + for cluster in clusters[vsphere_name].keys(): - vms = clusters[vname][cluster] + vms = clusters[vsphere_name][cluster] cl = str(cluster) LOG.debug(_( "Checking existence of computing cluster {c!r} in VSPhere {v!r} ...").format( - c=cl, v=vname)) + c=cl, v=vsphere_name)) - vsphere = self.vsphere[vname] + vsphere = self.vsphere[vsphere_name] vmw_cluster = vsphere.get_cluster_by_name(cl) if vmw_cluster: if self.verbose > 1: LOG.debug(_( "Found computing cluster {cl!r} in VSPhere {v!r} (defined for VMs " - "{vms}).").format(cl=vmw_cluster.name, v=vname, vms=pp(vms))) + "{vms}).").format(cl=vmw_cluster.name, v=vsphere_name, vms=pp(vms))) else: LOG.error(_( "Computing cluster {cl!r} (defined for VMs {vms}) in VSPhere {v!r} not " - "found.").format(cl=cl, vms=pp(vms), v=vname)) + "found.").format(cl=cl, vms=pp(vms), v=vsphere_name)) self.eval_errors += 1 # -------------------------------------------------------------------------·