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 f852997
Show file tree
Hide file tree
Showing 2 changed files with 13 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.
11 changes: 11 additions & 0 deletions plugins/modules/vmware_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3227,6 +3227,17 @@ 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 = self.current_vm_obj.MigrateVM_Task(self.get_resource_pool(), requested_host, "defaultPriority")
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 f852997

Please sign in to comment.