Fixed tracebacks when datacenter not found, when notes not given, and when collecting facts after VM creation. Fixes #8067.
This commit is contained in:
parent
a320c02c81
commit
fb83bdffa8
1 changed files with 8 additions and 8 deletions
|
@ -604,10 +604,11 @@ def create_vm(vsphere_client, module, esxi, resource_pool, cluster_name, guest,
|
||||||
datacenter = esxi['datacenter']
|
datacenter = esxi['datacenter']
|
||||||
esxi_hostname = esxi['hostname']
|
esxi_hostname = esxi['hostname']
|
||||||
# Datacenter managed object reference
|
# Datacenter managed object reference
|
||||||
dcmor = [k for k,
|
dclist = [k for k,
|
||||||
v in vsphere_client.get_datacenters().items() if v == datacenter][0]
|
v in vsphere_client.get_datacenters().items() if v == datacenter]
|
||||||
|
if dclist:
|
||||||
if dcmor is None:
|
dcmor=dclist[0]
|
||||||
|
else:
|
||||||
vsphere_client.disconnect()
|
vsphere_client.disconnect()
|
||||||
module.fail_json(msg="Cannot find datacenter named: %s" % datacenter)
|
module.fail_json(msg="Cannot find datacenter named: %s" % datacenter)
|
||||||
|
|
||||||
|
@ -710,7 +711,7 @@ def create_vm(vsphere_client, module, esxi, resource_pool, cluster_name, guest,
|
||||||
vmfiles.set_element_vmPathName(datastore_name)
|
vmfiles.set_element_vmPathName(datastore_name)
|
||||||
config.set_element_files(vmfiles)
|
config.set_element_files(vmfiles)
|
||||||
config.set_element_name(guest)
|
config.set_element_name(guest)
|
||||||
if vm_extra_config['notes'] is not None:
|
if 'notes' in vm_extra_config:
|
||||||
config.set_element_annotation(vm_extra_config['notes'])
|
config.set_element_annotation(vm_extra_config['notes'])
|
||||||
config.set_element_memoryMB(int(vm_hardware['memory_mb']))
|
config.set_element_memoryMB(int(vm_hardware['memory_mb']))
|
||||||
config.set_element_numCPUs(int(vm_hardware['num_cpus']))
|
config.set_element_numCPUs(int(vm_hardware['num_cpus']))
|
||||||
|
@ -822,8 +823,7 @@ def create_vm(vsphere_client, module, esxi, resource_pool, cluster_name, guest,
|
||||||
module.fail_json(msg="Error creating vm: %s" %
|
module.fail_json(msg="Error creating vm: %s" %
|
||||||
task.get_error_message())
|
task.get_error_message())
|
||||||
else:
|
else:
|
||||||
vm = None
|
# We always need to get the vm because we are going to gather facts
|
||||||
if vm_extra_config or state in ['powered_on', 'powered_off']:
|
|
||||||
vm = vsphere_client.get_vm_by_name(guest)
|
vm = vsphere_client.get_vm_by_name(guest)
|
||||||
|
|
||||||
# VM was created. If there is any extra config options specified, set
|
# VM was created. If there is any extra config options specified, set
|
||||||
|
|
Loading…
Reference in a new issue