self.vsphere_folders = []
+ self.vsphere_user = None
+ self.vsphere_password = None
+
self.used_networks = {}
self.used_dc_clusters = {}
self.used_datastores = {}
self.vsphere = None
# -------------------------------------------------------------------------
- def __call__(self, yaml_file):
- """Executing the underlying action."""
+ def first_call(self, yaml_file):
+ """First steps until reading the YAML file."""
if not self.initialized:
raise HandlerError(_("{}-object not initialized.").format(self.__class__.__name__))
self.exec_read_yaml(yaml_file)
+ print()
+ LOG.info(_("Initialising VSPhere handlers."))
+ self.init_vspheres(yaml_file)
+
+ return True
+
+ except AbortExecution as e:
+ LOG.warn(str(e))
+ return false
+
+ # -------------------------------------------------------------------------
+ def __call__(self, yaml_file):
+ """Executing the underlying action."""
+
+ if not self.initialized:
+ raise HandlerError(_("{}-object not initialized.").format(self.__class__.__name__))
+
+ try:
+
if self.simulate:
print()
msg_a = _("Simulation mode")
self.exec_pdns_zones()
print()
- LOG.info(_("Initialising VSPhere handlers."))
- self.init_vspheres(yaml_file)
+ LOG.info(_("Cpllecting first information from vSPhere."))
+ self.test_vsphere_handlers()
self.exec_collect_folders(yaml_file)
self.assign_default_vmw_values()
msg = _("VSPhere {!r} not defined in configuration.").format(vname)
raise ExpectedHandlerError(msg)
- vsphere_user = self.config.vsphere[vname].user
- vsphere_password = self.config.vsphere[vname].password
-
- if not vsphere_user:
- msg = '\n' + _("Please input the {}:").format(self.colored(
- _('vSphere user name'), 'AQUA'))
- print(msg)
- vsphere_user = input(_('vSphere user name') + ': ')
- if vsphere_user == '':
- msg = _("No {} given.").format(_('vSphere user name'))
- raise ExpectedHandlerError(msg)
-
- if not vsphere_password:
- prompt = _("User password")
- item = _('Password for user {u!r} of vSphere {n} on {h!r}').format(
- u=vsphere_user, n=vname, h=self.config.vsphere[vname].host)
- vsphere_password = self.get_secret(prompt=prompt, item_name=item)
+ if not self.vsphere_user and self.config.vsphere[vname].user:
+ self.vsphere_user = self.config.vsphere[vname].user
+ if not self.vsphere_password and self.config.vsphere[vname].password:
+ self.vsphere_password = self.config.vsphere[vname].password
try:
params = {
'base_dir': self.base_dir,
'host': self.config.vsphere[vname].host,
'port': self.config.vsphere[vname].port,
- 'user': vsphere_user,
- 'password': vsphere_password,
+ 'user': self.vsphere_user,
+ 'password': self.vsphere_password,
'dc': self.config.vsphere[vname].dc,
'simulate': self.simulate,
'force': self.force,
LOG.debug(msg)
vsphere = VsphereServer(**params)
+ self.vsphere[vname] = vsphere
+
+ except VSphereExpectedError as e:
+ raise ExpectedHandlerError(str(e))
+
+ # -------------------------------------------------------------------------ยท
+ def test_vsphere_handlers(self):
+
+ for vname in self.vsphere.keys():
+
+ try:
+
+ vsphere = self.vsphere[vname]
+
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))