from .xlate import XLATOR
-__version__ = '1.3.3'
+__version__ = '1.3.4'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
self._min_root_size_gb = self.default_min_root_size_gb
self._guest_id = self.default_guest_id
self.excluded_ds = []
+ self.used_templates = []
super(VsphereConfig, self).__init__(
appname=appname, verbose=verbose, version=version,
if value is None:
self._template_name = self.default_template_name
return
- val = str(value).strip()
+ val = str(value).strip().lower()
if val == '':
self._template_name = self.default_template_name
else:
from .xlate import XLATOR
-__version__ = '2.9.4'
+__version__ = '2.9.5'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
self.incr_verbosity()
for vname in self.vsphere:
+ LOG.debug(_("Searching for clusters in VSPhere {!r} ...").format(vname))
self.vsphere[vname].get_clusters()
LOG.info(_("Finished step {!r}.").format('vmw-clusters'))
self.incr_verbosity()
for vname in self.vsphere:
+ LOG.debug(_("Searching for datastores in VSPhere {!r} ...").format(vname))
self.vsphere[vname].get_datastores()
LOG.info(_("Finished step {!r}.").format('vmw-datastores'))
self.incr_verbosity()
for vname in self.vsphere:
+ LOG.debug(_("Searching for datastore clusters in VSPhere {!r} ...").format(vname))
self.vsphere[vname].get_ds_clusters()
LOG.info(_("Finished step {!r}.").format('vmw-ds-clusters'))
self.incr_verbosity()
for vname in self.vsphere:
+ LOG.debug(_("Searching for networks in VSPhere {!r} ...").format(vname))
self.vsphere[vname].get_networks()
if self.eval_errors:
msg = ngettext(
LOG.info(_("Exploring all vSphere templates ..."))
- template_names = []
- if self.config.template_name:
- template_names.append(self.config.template_name)
+ for vname in self.vsphere:
- for vm in self.vms:
- template_name = vm.vm_template
- if template_name:
- if template_name not in template_names:
- template_names.append(template_name)
- else:
- LOG.error(_("VM {!r} has not template defined.").format(vm.name))
- self.eval_errors += 1
+ if vname not in self.vsphere_templates:
+ self.vsphere_templates[vname] = {}
- LOG.debug(_("All vSphere templates to explore:") + "\n" + pp(template_names))
+ self.config.vsphere[vname].used_templates = []
- for template_name in template_names:
+ for vm in self.vms:
+ template_name = vm.vm_template
+ if template_name:
+ if template_name not in self.config.vsphere[vname].used_templates:
+ self.config.vsphere[vname].used_templates.append(template_name)
+ else:
+ LOG.error(_("VM {!r} has not template defined.").format(vm.name))
+ self.eval_errors += 1
- vm_info = self.vsphere.get_vm(template_name)
- if vm_info:
- tname = template_name.lower()
- if tname not in self.vsphere_templates:
- self.vsphere_templates[tname] = vm_info
- else:
- self.eval_errors += 1
+ msg = _("All {} VSPhere templates to explore:").format(vname)
+ msg += "\n" + pp(self.config.vsphere[vname].used_templates)
+ LOG.debug(msg)
+
+ for template_name in self.config.vsphere[vname].used_templates:
+
+ if template_name in self.vsphere_templates[vname]:
+ continue
+
+ LOG.debug(_("Searching for template {t!r} in VSPhere {v!r} ...").format(
+ t=template_name, v=vname))
+ re_vm = re.compile(r'^' + re.escape(template_name) + r'$', re.IGNORECASE)
+ vm_list = self.vsphere[vname].get_vms(re_vm, as_obj=True, stop_at_found=True)
+ if vm_list:
+ vm = vm_list[0]
+ tname = vm.name.lower()
+ if tname not in self.vsphere_templates[vname]:
+ self.vsphere_templates[vname][template_name] = vm
+ else:
+ LOG.error(_("Template {t!r} not found in VSPhere {v!r}.").format(
+ t=template_name, v=vname))
+ self.eval_errors += 1
if self.verbose > 2:
- LOG.debug(_("All explored vSphere templates:") + "\n" + pp(self.vsphere_templates))
+ msg = _("All explored vSphere templates:")
+ out_dict = {}
+ for vname in self.vsphere_templates:
+ out_dict[vname] = {}
+ for tname in self.vsphere_templates[vname]:
+ out_dict[vname][tname] = self.vsphere_templates[vname][tname].as_dict()
+ msg += "\n" + pp(out_dict)
+ LOG.debug(msg)
# -------------------------------------------------------------------------ยท
def validate_clusters(self):