self.project_dir = None
self.project_name = None
+ self.all_vms = {}
self.existing_vms = []
self.start_dir = Path(os.getcwd())
self.eval_errors).format(n=self.eval_errors)
raise ExpectedHandlerError(msg)
+ self.get_all_vms()
self.validate_vms()
LOG.info(_("Finished step {!r}.").format('validate-yaml'))
if self.stop_at_step == 'validate-yaml':
raise AbortExecution('validate-yaml')
+ # -------------------------------------------------------------------------·
+ def get_all_vms(self):
+
+ LOG.info(_("Got a list of all VMs and templates ..."))
+ self.all_vms = {}
+ re_vm = re.compile(r'.*')
+
+ for vs_name in self.vsphere:
+
+ 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_name = vm_tuple[0]
+ vm_path = vm_tuple[1]
+ if vm_name in self.all_vms[vs_name]:
+ self.all_vms[vs_name][vm_name].append(vm_path)
+ else:
+ self.all_vms[vs_name][vm_name] = [vm_path]
+
+ if self.verbose > 2:
+ msg = _("All existing VMs and templates:")
+ msg += '\n' + pp(self.all_vms)
+
# -------------------------------------------------------------------------·
def exec_validate_storage(self):
for vm in self.vms:
- if vm.cluster in clusters:
- clusters[vm.cluster].append(vm.name)
+ if vm.vsphere not in clusters:
+ clusters[vm.vsphere] = {}
+
+ if vm.cluster in clusters[vm.vsphere]:
+ clusters[vm.vsphere][vm.cluster].append(vm.name)
else:
- clusters[vm.cluster] = [vm.name]
+ clusters[vm.vsphere][vm.cluster] = [vm.name]
- for cluster in clusters.keys():
+ for vsname in clusters.keys():
+ for cluster in clusters[vsname].keys():
- cl = str(cluster)
- LOG.debug(_("Checking existence of computing cluster {!r} ...").format(cl))
+ cl = str(cluster)
+ LOG.debug(_("Checking existence of computing cluster {!r} ...").format(cl))
- vmw_cluster = self.vsphere.get_cluster_by_name(cl)
- if vmw_cluster:
- if self.verbose > 2:
- LOG.debug(
- _("Found computing cluster {cl!r} (defined for VMs {vms}).").format(
- cl=vmw_cluster.name, vms=pp(clusters[cluster])))
- else:
- LOG.error(
- _("Computing cluster {cl!r} (defined for VMs {vms}) not found.").format(
- cl=cl, vms=pp(clusters[cluster])))
- self.eval_errors += 1
+ vmw_cluster = self.vsphere[vsname].get_cluster_by_name(cl)
+ if vmw_cluster:
+ if self.verbose > 2:
+ LOG.debug(
+ _("Found computing cluster {cl!r} (defined for VMs {vms}).").format(
+ cl=vmw_cluster.name, vms=pp(clusters[cluster])))
+ else:
+ LOG.error(
+ _("Computing cluster {cl!r} (defined for VMs {vms}) not found.").format(
+ cl=cl, vms=pp(clusters[cluster])))
+ self.eval_errors += 1
# -------------------------------------------------------------------------·
def validate_vms(self):
print(" * {} ".format(vm.fqdn), end='', flush=True)
if self.verbose:
print()
+ vs_name = vm.vsphere
+
+ 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]
+
+ if vm_paths:
+ msg = _('[{m}] - VM is already existing in VSphere {v!r}, path {p!r}.').format(
+ m=self.colored('Existing', 'YELLOW'), v=vs_name, p=pp(vm_paths))
+ print(msg, end='', flush=True)
+ if self.verbose:
+ print()
+
vm_info = self.vsphere.get_vm(vm.name, no_error=True)
if vm_info: