From fb83bdffa865d5793426794d2b103841af745a14 Mon Sep 17 00:00:00 2001 From: Graham Mainwaring Date: Thu, 10 Jul 2014 23:05:23 -0400 Subject: [PATCH] Fixed tracebacks when datacenter not found, when notes not given, and when collecting facts after VM creation. Fixes #8067. --- library/cloud/vsphere_guest | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/cloud/vsphere_guest b/library/cloud/vsphere_guest index a16f3441cf..cdbee6b938 100644 --- a/library/cloud/vsphere_guest +++ b/library/cloud/vsphere_guest @@ -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.