from distutils.version import LooseVersion
+from operator import attrgetter
+
# Third party modules
import pytz
import yaml
from .xlate import XLATOR
-__version__ = '2.9.5'
+__version__ = '2.9.6'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
if self.pdns:
self.pdns.simulate = self.simulate
- if self.vsphere:
- self.vsphere.simulate = self.simulate
+ for vsphere_name in self.vsphere.keys():
+ if self.vsphere[vsphere_name]:
+ self.vsphere[vsphere_name].simulate = self.simulate
# -----------------------------------------------------------
@property
self.eval_errors).format(n=self.eval_errors)
raise ExpectedHandlerError(msg)
- self.validate_vms()
+ # self.validate_vms()
LOG.info(_("Finished step {!r}.").format('validate-yaml'))
if self.stop_at_step == 'validate-yaml':
for vm in self.vms:
+ vname = vm.vsphere
+ if vname not in clusters:
+ clusters[vname] = {}
+
if vm.cluster in clusters:
- clusters[vm.cluster].append(vm.name)
+ clusters[vname][vm.cluster].append(vm.name)
else:
- clusters[vm.cluster] = [vm.name]
+ clusters[vname][vm.cluster] = [vm.name]
- for cluster in clusters.keys():
+ for vname in clusters.keys():
+ for cluster in clusters[vname].keys():
- cl = str(cluster)
- LOG.debug(_("Checking existence of computing cluster {!r} ...").format(cl))
+ vms = clusters[vname][cluster]
- 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
+ cl = str(cluster)
+ LOG.debug(_(
+ "Checking existence of computing cluster {c!r} in VSPhere {v!r} ...").format(
+ c=cl, v=vname))
+
+ vsphere = self.vsphere[vname]
+ 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)))
+ 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))
+ self.eval_errors += 1
# -------------------------------------------------------------------------ยท
def validate_vms(self):
LOG.info(_("Validating existence of VMs in VMWare."))
vms2perform = []
- for vm in sorted(self.vms, key=lambda x: x.tf_name):
+ for vm in sorted(self.vms, key=attrgetter('tf_name')):
print(" * {} ".format(vm.fqdn), end='', flush=True)
if self.verbose: