from .xlate import XLATOR
-__version__ = '2.9.6'
+__version__ = '2.9.7'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
re_group = re.compile(r'^\s*groups?\s*$', re.IGNORECASE)
re_group_name = re.compile(r'^\s*name\s*$', re.IGNORECASE)
re_doublequote = re.compile(r'"')
- re_vm_path = re.compile(r'^\s*\[\s*([^\s\]]+)')
re_tf_version = re.compile(r'^\s*Terraform\s+v(\S+)', re.IGNORECASE)
raise ExpectedHandlerError(msg)
self.get_all_vms()
- # self.validate_vms()
+ self.validate_vms()
LOG.info(_("Finished step {!r}.").format('validate-yaml'))
if self.stop_at_step == 'validate-yaml':
if vs_name not in self.all_vms:
self.all_vms[vs_name] = {}
- vm_list = self.vsphere[vs_name].get_vms(re_vm, name_only=True)
- for vm_tuple in vm_list:
+ vm_list = self.vsphere[vs_name].get_vms(re_vm, name_only=True)
+ for vm_tuple in vm_list:
vm_name = vm_tuple[0]
vm_path = vm_tuple[1]
if vm_name in self.all_vms[vs_name]:
if self.verbose > 2:
msg = _("All existing VMs and templates:")
msg += '\n' + pp(self.all_vms)
+ LOG.debug(msg)
# -------------------------------------------------------------------------ยท
def exec_validate_storage(self):
if self.verbose:
print()
vs_name = vm.vsphere
+ vsphere = self.vsphere[vs_name]
vm_paths = None
if vs_name in self.all_vms:
if vm.fqdn in self.all_vms[vs_name]:
- vm_paths = self.all_vms[vs_name][vs_name]
+ vm_paths = self.all_vms[vs_name][vm.fqdn]
if vm_paths:
msg = _('[{m}] - VM is already existing in VSphere {v!r}, path {p!r}.').format(
if self.verbose:
print()
-
- vm_info = self.vsphere.get_vm(vm.name, no_error=True)
- if vm_info:
- print(
- _('[{}] - VM is already existing.').format(
- self.colored('Existing', 'YELLOW')), end='', flush=True)
- if self.verbose > 0:
- print()
+ vm_info = vsphere.get_vm(vm.fqdn, vsphere_name=vs_name, as_obj=True)
if self.verbose > 2:
- LOG.debug(_("VM info:") + "\n" + pp(vm_info))
- match = self.re_vm_path.search(vm_info['vmPathName'])
- if match:
- ds = match.group(1)
- LOG.debug(_("Datastore of VM {vm!r}: {ds!r}.").format(
- vm=vm.name, ds=ds))
- vm.datastore = ds
- vm.already_existing = True
- self.existing_vms.append(vm_info)
- else:
- LOG.error(_("Did not found datastore of existing VM {!r}.").format(vm.name))
+ LOG.debug(_("VM info:") + "\n" + pp(vm_info.as_dict(bare=True)))
+ ds = vm_info.config_path_storage
+ LOG.debug(_("Datastore of VM {vm!r}: {ds!r}.").format(vm=vm.name, ds=ds))
+ vm.datastore = ds
+ vm.already_existing = True
+ self.existing_vms.append(vm_info)
+
else:
+
print('[{}] '.format(self.colored('OK', 'GREEN')), end='', flush=True)
vm.already_existing = False
+
vms2perform.append(vm)
print()