VMware: Autoselect datastore only from the given cluster/ESXi (#43435)
* Autoselect DS only from the given cluster/esxi * Run tests only on real vCenter
This commit is contained in:
parent
5942e7f2a2
commit
a8ef5d5034
3 changed files with 88 additions and 72 deletions
|
@ -139,7 +139,7 @@ def find_object_by_name(content, name, obj_type, folder=None, recurse=True):
|
|||
|
||||
def find_cluster_by_name(content, cluster_name, datacenter=None):
|
||||
|
||||
if datacenter:
|
||||
if datacenter and hasattr(datacenter, 'hostFolder'):
|
||||
folder = datacenter.hostFolder
|
||||
else:
|
||||
folder = content.rootFolder
|
||||
|
|
|
@ -2158,10 +2158,24 @@ class PyVmomiHelper(PyVmomi):
|
|||
if len(self.params['disk']) != 0:
|
||||
# TODO: really use the datastore for newly created disks
|
||||
if 'autoselect_datastore' in self.params['disk'][0] and self.params['disk'][0]['autoselect_datastore']:
|
||||
datastores = []
|
||||
|
||||
if self.params['cluster']:
|
||||
cluster = self.find_cluster_by_name(self.params['cluster'], self.content)
|
||||
|
||||
for host in cluster.host:
|
||||
for mi in host.configManager.storageSystem.fileSystemVolumeInfo.mountInfo:
|
||||
if mi.volume.type == "VMFS":
|
||||
datastores.append(self.cache.find_obj(self.content, [vim.Datastore], mi.volume.name))
|
||||
elif self.params['esxi_hostname']:
|
||||
host = self.find_hostsystem_by_name(self.params['esxi_hostname'])
|
||||
|
||||
for mi in host.configManager.storageSystem.fileSystemVolumeInfo.mountInfo:
|
||||
if mi.volume.type == "VMFS":
|
||||
datastores.append(self.cache.find_obj(self.content, [vim.Datastore], mi.volume.name))
|
||||
else:
|
||||
datastores = self.cache.get_all_objs(self.content, [vim.Datastore])
|
||||
datastores = [x for x in datastores if self.cache.get_parent_datacenter(x).name == self.params['datacenter']]
|
||||
if datastores is None or len(datastores) == 0:
|
||||
self.module.fail_json(msg="Unable to find a datastore list when autoselecting")
|
||||
|
||||
datastore_freespace = 0
|
||||
for ds in datastores:
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
# Copyright: (c) 2019, Noe Gonzalez <noe.a.gonzalez@gmail.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
- when: vcsim is not defined
|
||||
block:
|
||||
- name: create new VM
|
||||
vmware_guest:
|
||||
validate_certs: False
|
||||
|
|
Loading…
Reference in a new issue