From 4cb3e87ca4fe0b73a71dc1ce2175340c88fab073 Mon Sep 17 00:00:00 2001 From: jctanner Date: Mon, 19 Sep 2016 16:25:44 -0400 Subject: [PATCH] vmware_guest: do not assume disk params contain a datastore (#2974) * vmware_guest: do not assume disk params contain a datastore * Fix missed line during connection refactor --- .../modules/extras/cloud/vmware/vmware_guest.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/extras/cloud/vmware/vmware_guest.py b/lib/ansible/modules/extras/cloud/vmware/vmware_guest.py index 9b699b37c23..0daac9c3723 100644 --- a/lib/ansible/modules/extras/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/extras/cloud/vmware/vmware_guest.py @@ -294,7 +294,7 @@ class PyVmomiHelper(object): folder_path = None if uuid: - vm = self.si.content.searchIndex.FindByUuid(uuid=uuid, vmSearch=True) + vm = self.content.searchIndex.FindByUuid(uuid=uuid, vmSearch=True) elif folder: @@ -532,14 +532,19 @@ class PyVmomiHelper(object): hostsystem = get_obj(self.content, [vim.HostSystem], self.params['esxi_hostname']) # set the destination datastore in the relocation spec + datastore_name = None + datastore = None if self.params['disk']: - datastore_name = self.params['disk'][0]['datastore'] - datastore = get_obj(self.content, [vim.Datastore], datastore_name) - else: + if 'datastore' in self.params['disk'][0]: + datastore_name = self.params['disk'][0]['datastore'] + datastore = get_obj(self.content, [vim.Datastore], datastore_name) + if not datastore: # use the template's existing DS disks = [x for x in template.config.hardware.device if isinstance(x, vim.vm.device.VirtualDisk)] datastore = disks[0].backing.datastore datastore_name = datastore.name + if not datastore: + self.module.fail_json(msg="Failed to find a matching datastore") # create the relocation spec relospec = vim.vm.RelocateSpec()