VMware: Fix mark as virtual machine method (#40521)

Choose resource pool by using get_resource_pool rather than select_resource_pool_by_name

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/38144/head
Abhijeet Kasurde 6 years ago committed by GitHub
parent 4a98802b52
commit 4dac5bed83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2198,13 +2198,32 @@ class PyVmomiHelper(PyVmomi):
# Mark Template as VM # Mark Template as VM
elif not self.params['is_template'] and self.current_vm_obj.config.template: elif not self.params['is_template'] and self.current_vm_obj.config.template:
if self.params['resource_pool']: resource_pool = self.get_resource_pool()
resource_pool = self.select_resource_pool_by_name(self.params['resource_pool']) kwargs = dict(pool=resource_pool)
if resource_pool is None: if self.params.get('esxi_hostname', None):
self.module.fail_json(msg='Unable to find resource pool "%(resource_pool)s"' % self.params) host_system_obj = self.select_host()
kwargs.update(host=host_system_obj)
self.current_vm_obj.MarkAsVirtualMachine(pool=resource_pool) try:
self.current_vm_obj.MarkAsVirtualMachine(**kwargs)
except vim.fault.InvalidState as invalid_state:
self.module.fail_json(msg="Virtual machine is not marked"
" as template : %s" % to_native(invalid_state.msg))
except vim.fault.InvalidDatastore as invalid_ds:
self.module.fail_json(msg="Converting template to virtual machine"
" operation cannot be performed on the"
" target datastores: %s" % to_native(invalid_ds.msg))
except vim.fault.CannotAccessVmComponent as cannot_access:
self.module.fail_json(msg="Failed to convert template to virtual machine"
" as operation unable access virtual machine"
" component: %s" % to_native(cannot_access.msg))
except vmodl.fault.InvalidArgument as invalid_argument:
self.module.fail_json(msg="Failed to convert template to virtual machine"
" due to : %s" % to_native(invalid_argument.msg))
except Exception as generic_exc:
self.module.fail_json(msg="Failed to convert template to virtual machine"
" due to generic error : %s" % to_native(generic_exc))
# Automatically update VMWare UUID when converting template to VM. # Automatically update VMWare UUID when converting template to VM.
# This avoids an interactive prompt during VM startup. # This avoids an interactive prompt during VM startup.
@ -2217,8 +2236,6 @@ class PyVmomiHelper(PyVmomi):
self.change_detected = True self.change_detected = True
change_applied = True change_applied = True
else:
self.module.fail_json(msg="Resource pool must be specified when converting template to VM!")
vm_facts = self.gather_facts(self.current_vm_obj) vm_facts = self.gather_facts(self.current_vm_obj)
return {'changed': change_applied, 'failed': False, 'instance': vm_facts} return {'changed': change_applied, 'failed': False, 'instance': vm_facts}

Loading…
Cancel
Save