don't create vmware vm on ESX in maintenance mode (#37124)

* don't create vmware vm on ESX in maint mode

update vmware_guest not to try to create VM on ESXi host in maintenance mode

* update as requested
This commit is contained in:
balonik 2018-03-28 05:12:43 +02:00 committed by ansibot
parent 454096ca59
commit 371317b553

View file

@ -1489,21 +1489,11 @@ class PyVmomiHelper(PyVmomi):
self.change_detected = True
def select_host(self):
# if the user wants a cluster, get the list of hosts for the cluster and use the first one
if self.params['cluster']:
cluster = self.cache.get_cluster(self.params['cluster'])
if not cluster:
self.module.fail_json(msg='Failed to find cluster "%(cluster)s"' % self.params)
hostsystems = [x for x in cluster.host]
if not hostsystems:
self.module.fail_json(msg='No hosts found in cluster "%(cluster)s. Maybe you lack the right privileges ?"' % self.params)
# TODO: add a policy to select host
hostsystem = hostsystems[0]
else:
hostsystem = self.cache.get_esx_host(self.params['esxi_hostname'])
if not hostsystem:
self.module.fail_json(msg='Failed to find ESX host "%(esxi_hostname)s"' % self.params)
hostsystem = self.cache.get_esx_host(self.params['esxi_hostname'])
if not hostsystem:
self.module.fail_json(msg='Failed to find ESX host "%(esxi_hostname)s"' % self.params)
if hostsystem.runtime.connectionState != 'connected' or hostsystem.runtime.inMaintenanceMode:
self.module.fail_json(msg='ESXi "%(esxi_hostname)s" is in invalid state or in maintenance mode.' % self.params)
return hostsystem
def autoselect_datastore(self):