Merge pull request #8094 from ghjm/vsphere-fixes
Fixed tracebacks during VM creation. Fixes #8067.
This commit is contained in:
commit
e8e85bb0ee
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']
|
||||
esxi_hostname = esxi['hostname']
|
||||
# Datacenter managed object reference
|
||||
dcmor = [k for k,
|
||||
v in vsphere_client.get_datacenters().items() if v == datacenter][0]
|
||||
|
||||
if dcmor is None:
|
||||
dclist = [k for k,
|
||||
v in vsphere_client.get_datacenters().items() if v == datacenter]
|
||||
if dclist:
|
||||
dcmor=dclist[0]
|
||||
else:
|
||||
vsphere_client.disconnect()
|
||||
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)
|
||||
config.set_element_files(vmfiles)
|
||||
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_memoryMB(int(vm_hardware['memory_mb']))
|
||||
config.set_element_numCPUs(int(vm_hardware['num_cpus']))
|
||||
|
@ -822,9 +823,8 @@ def create_vm(vsphere_client, module, esxi, resource_pool, cluster_name, guest,
|
|||
module.fail_json(msg="Error creating vm: %s" %
|
||||
task.get_error_message())
|
||||
else:
|
||||
vm = None
|
||||
if vm_extra_config or state in ['powered_on', 'powered_off']:
|
||||
vm = vsphere_client.get_vm_by_name(guest)
|
||||
# We always need to get the vm because we are going to gather facts
|
||||
vm = vsphere_client.get_vm_by_name(guest)
|
||||
|
||||
# VM was created. If there is any extra config options specified, set
|
||||
# them here , disconnect from vcenter, then exit.
|
||||
|
|
Loading…
Reference in a new issue