Skip to content

Commit

Permalink
Support migrate VM in vmware_guest module
Browse files Browse the repository at this point in the history
  • Loading branch information
bardielle committed May 23, 2024
1 parent f349b2a commit b9821fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/2081-migrate_vm_in_vmware_guest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- vmware_guest - supporting migrate VM if the requested ESXi hostname was updated.
16 changes: 16 additions & 0 deletions plugins/modules/vmware_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3227,6 +3227,22 @@ def reconfigure_vm(self):
if task.info.state == 'error':
return {'changed': self.change_applied, 'failed': True, 'msg': task.info.error.msg, 'op': 'reconfig'}

# Migrate VM:
current_host = self.current_vm_obj.summary.runtime.host
requested_host = self.cache.get_esx_host(self.params['esxi_hostname']) if self.params[
'esxi_hostname'] else None
if requested_host and current_host != requested_host:
task = None
try:
task = self.current_vm_obj.MigrateVM_Task(self.get_resource_pool(), requested_host, "defaultPriority")
except vim.fault.RestrictedVersion as e:
self.module.fail_json(msg="Failed to reconfigure virtual machine due to"
" product versioning restrictions: %s" % to_native(e.msg))
self.wait_for_task(task)
if task.info.state == 'error':
return {'changed': self.change_applied, 'failed': True, 'msg': task.info.error.msg,
'op': 'reconfig'}

# Rename VM
if self.params['uuid'] and self.params['name'] and self.params['name'] != self.current_vm_obj.config.name:
self.tracked_changes['name'] = self.params['name']
Expand Down

0 comments on commit b9821fd

Please sign in to comment.