from .xlate import XLATOR
-__version__ = '2.9.8'
+__version__ = '2.9.9'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
self.vsphere_folders = []
- self.used_networks = []
+ self.used_networks = {}
self.used_dc_clusters = {}
- self.used_datastores = []
+ self.used_datastores = {}
self.project_dir = None
self.project_name = None
def validate_storages(self):
self._validate_ds_clusters()
- # self._validate_datastores()
+ self._validate_datastores()
if self.verbose:
if self.used_dc_clusters:
else:
LOG.debug(_("No datastore clusters are used."))
if self.used_datastores:
- out = '\n'.join(map(lambda x: ' * {}'.format(x), self.used_datastores))
+ out_lines = []
+ for vs_name in self.used_datastores:
+ for ds in self.used_datastores[vs_name]:
+ out_lines.append(' * VSphere {v!r}: {ds}'.format(v=vs_name, ds=ds))
+ out = '\n'.join(out_lines)
LOG.debug(_("Used datastors:") + "\n" + out)
else:
LOG.debug(_("No datastores are used."))
disk = vm.disks[unit_number]
needed_gb += disk.size_gb
+ vs_name = vm.vsphere
+ vsphere = self.vsphere[vs_name]
+
vm_cluster = None
- for cluster in self.vsphere.clusters:
+ for cluster in vsphere.clusters:
if cluster.name.lower() == vm.cluster.lower():
vm_cluster = cluster
break
if vm.datastore:
found = False
- for ds_name in self.vsphere.datastores:
+ found_ds_name = None
+ for ds_name in vsphere.datastores:
if ds_name.lower() == vm.datastore.lower():
if self.verbose > 2:
- LOG.debug(_("Found datastore {d!r} for VM {n!r}.").format(
- n=vm.name, d=vm.datastore))
+ LOG.debug(_("Found datastore {d!r} for VM {n!r} in VSPhere {v!r}.").format(
+ n=vm.name, d=vm.datastore, v=vs_name))
if ds_name not in vm_cluster.datastores:
LOG.warn(_("Datastore {d!r} not available in cluster {c!r}.").format(
d=ds_name, c=vm.cluster))
LOG.debug(_("Setting datastore for VM {n!r} to {d!r} ...").format(
n=vm.name, d=ds_name))
vm.datastore = ds_name
- ds = self.vsphere.datastores[ds_name]
+ ds = vsphere.datastores[ds_name]
if ds.avail_space_gb < needed_gb:
LOG.error(_(
"Datastore {d!r} has not sufficient space for storage of VM "
else:
ds.calculated_usage += needed_gb
found = True
+ found_ds_name = ds_name
break
if not found:
- LOG.error(_("Datastore {d!r} of VM {n!r} not found.").format(
- n=vm.name, d=vm.datastore))
+ LOG.error(_("Datastore {d!r} of VM {n!r} not found in VSPhere {v!r}.").format(
+ n=vm.name, d=vm.datastore, v=vs_name))
self.eval_errors += 1
+ if vs_name not in self.used_datastores:
+ self.used_datastores[vs_name] = []
+ if found_ds_name not in self.used_datastores[vs_name]:
+ self.used_datastores[vs_name].append(found_ds_name)
return
- ds_name = self.vsphere.datastores.find_ds(
+ ds_name = vsphere.datastores.find_ds(
needed_gb, vm.ds_type, use_ds=copy.copy(vm_cluster.datastores), no_k8s=True)
if ds_name:
- LOG.debug(_("Found datastore {d!r} for VM {v!r}.").format(d=ds_name, v=vm.name))
+ LOG.debug(_("Found datastore {d!r} for VM {n!r} in VSPhere {v!r}.").format(
+ d=ds_name, n=vm.name, v=vs_name))
vm.datastore = ds_name
- if ds_name not in self.used_datastores:
- self.used_datastores.append(ds_name)
+ if vs_name not in self.used_datastores:
+ self.used_datastores[vs_name] = []
+ if ds_name not in self.used_datastores[vs_name]:
+ self.used_datastores[vs_name].append(ds_name)
else:
self.eval_errors += 1