from .xlate import XLATOR
-__version__ = '2.9.1'
+__version__ = '2.9.2'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
tz = pytz.timezone(tz_name)
steps = (
- 'init', 'read-yaml', 'collect-folders', 'pdns-zones', 'vmw-clusters',
+ 'init', 'read-yaml', 'pdns-zones', 'vmw-init', 'collect-folders', 'vmw-clusters',
'vmw-datastores', 'vmw-ds-clusters', 'vmw-networks', 'vmw-templates',
'validate-yaml', 'validate-storage', 'validate-iface', 'validate-dns',
'perform-dns', 'project-dir', 'tf-files', 'ensure-vmw-folders',
step_desc = {
'init': _('After initialization of all objects and handlers.'),
'read-yaml': _('After reading the given YAML file.'),
- 'collect-folders': _('After collecting all VMWare and local folders.'),
'pdns-zones': _('After retrieving all DNS zones from PowerDNS.'),
+ 'vmw-init': _('After initialisation of VSPhere handlers.'),
+ 'collect-folders': _('After collecting all VMWare and local folders.'),
'vmw-clusters': _('After collecting all VMWare clusters.'),
'vmw-datastores': _('After collecting all VMWare datastores.'),
'vmw-ds-clusters': _('After collecting all VMWare datastore clusters.'),
if self.pdns:
self.pdns.verbose = self.verbose
- if self.vsphere:
- self.vsphere.verbose = self.verbose
+ for vname in self.vsphere:
+ self.vsphere[vname].verbose = self.verbose
# -------------------------------------------------------------------------
def init_handlers(self):
except PowerDNSHandlerError as e:
raise ExpectedHandlerError(str(e))
-# try:
-# 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.vsphere_password,
-# dc=self.config.vsphere_dc, simulate=self.simulate, force=self.force,
-# terminal_has_colors=self.terminal_has_colors, initialized=True,
-# )
-#
-# self.vsphere.get_about()
-# except VSphereExpectedError as e:
-# raise ExpectedHandlerError(str(e))
-
# -------------------------------------------------------------------------
def check_terraform_version(self):
""" Checking, that the called terraform has a minimum version."""
print(self.colored('#' * (ll + 4), 'AQUA'))
print()
- self.exec_collect_folders(yaml_file)
self.exec_pdns_zones()
+ print()
+ LOG.info(_("Initialising VSPhere handlers."))
+ self.init_vspheres()
+ self.exec_collect_folders(yaml_file)
+
print()
LOG.info(_("Retrieving information from vSphere."))
LOG.info(_("Collecting all VMWare and local folders ..."))
LOG.info(_("Get vSphere datacenter ..."))
- self.vsphere.get_datacenter()
+ for vname in self.vsphere:
+ self.vsphere[vname].get_datacenter()
LOG.debug(_("Collecting vSphere folders."))
self.vsphere_folders = []
(yfile_stem, yfile_ext) = os.path.splitext(yfile_base)
self.project_name = yfile_stem
LOG.info(_("Project name is {!r}.").format(str(self.project_name)))
- if self.config.relative_tf_dir:
- LOG.debug(_("Using a relative project directory path ..."))
- self.project_dir = yfile_dir / yfile_stem
- else:
- self.project_dir = self.config.terraform_dir / yfile_stem
+ self.project_dir = yfile_dir / yfile_stem
LOG.info(_("Project directory is: {!r}.").format(str(self.project_dir)))
LOG.info(_("Finished step {!r}.").format('collect-folders'))
if self.stop_at_step == 'pdns-zones':
raise AbortExecution('pdns-zones')
+ # -------------------------------------------------------------------------·
+ def init_vspheres(self):
+
+ if self.stop_at_step == 'vmw-init':
+ self.incr_verbosity()
+
+ self._init_vspheres()
+
+ LOG.info(_("Finished step {!r}.").format('vmw-init'))
+ if self.stop_at_step == 'vmw-init':
+ raise AbortExecution('vmw-init')
+
+ # -------------------------------------------------------------------------·
+ def _init_vspheres(self):
+
+ for vm in self.vms:
+ if vm.vsphere in self.vsphere:
+ continue
+ vname = vm.vsphere
+ if vname not in self.config.vsphere:
+ msg = _("VSPhere {!r} not defined in configuration.").format(vname)
+ raise ExpectedHandlerError(msg)
+
+ try:
+ params = {
+ 'appname': self.appname,
+ 'verbose': self.verbose,
+ 'base_dir': self.base_dir,
+ 'host': self.config.vsphere[vname].host,
+ 'port': self.config.vsphere[vname].port,
+ 'user': self.config.vsphere[vname].user,
+ 'password': self.config.vsphere[vname].password,
+ 'dc': self.config.vsphere[vname].dc,
+ 'simulate': self.simulate,
+ 'force': self.force,
+ 'terminal_has_colors': self.terminal_has_colors,
+ 'initialized': True,
+ }
+ if self.verbose > 1:
+ params_out = copy.copy(params)
+ if self.verbose < 5:
+ params_out['password'] = '******'
+ msg = _("Initialising a {}-object with params:").format('VsphereServer')
+ msg += '\n' + pp(params_out)
+ LOG.debug(msg)
+
+ vsphere = VsphereServer(**params)
+ vsphere.get_about()
+ if self.verbose > 2:
+ msg = _("Created {}-object:").format('VsphereServer')
+ msg += '\n' + pp(vsphere.as_dict())
+ LOG.debug(msg)
+ self.vsphere[vname] = vsphere
+
+ except VSphereExpectedError as e:
+ raise ExpectedHandlerError(str(e))
+
# -------------------------------------------------------------------------·
def exec_vmw_clusters(self):