Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support migrate VM in vmware_guest module #2082

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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