Skip to content

Commit 2f36387

Browse files
committed
Support migrate VM in vmware_guest module
1 parent f349b2a commit 2f36387

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- vmware_guest - supporting migrate VM if the requested ESXi hostname was updated.

plugins/modules/vmware_guest.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,16 +3217,27 @@ def reconfigure_vm(self):
32173217
if self.module.check_mode:
32183218
self.change_applied = True
32193219
else:
3220-
task = None
3221-
try:
3222-
task = self.current_vm_obj.ReconfigVM_Task(spec=self.configspec)
3223-
except vim.fault.RestrictedVersion as e:
3224-
self.module.fail_json(msg="Failed to reconfigure virtual machine due to"
3225-
" product versioning restrictions: %s" % to_native(e.msg))
3220+
task = self.current_vm_obj.ReconfigVM_Task(spec=self.configspec)
32263221
self.wait_for_task(task)
32273222
if task.info.state == 'error':
32283223
return {'changed': self.change_applied, 'failed': True, 'msg': task.info.error.msg, 'op': 'reconfig'}
32293224

3225+
# Migrate VM:
3226+
current_host = self.current_vm_obj.summary.runtime.host
3227+
requested_host = self.cache.get_esx_host(self.params['esxi_hostname']) if self.params[
3228+
'esxi_hostname'] else None
3229+
if requested_host and current_host != requested_host:
3230+
task = None
3231+
try:
3232+
task = self.current_vm_obj.MigrateVM_Task(self.get_resource_pool(), requested_host, "defaultPriority")
3233+
except vim.fault.RestrictedVersion as e:
3234+
self.module.fail_json(msg="Failed to reconfigure virtual machine due to"
3235+
" product versioning restrictions: %s" % to_native(e.msg))
3236+
self.wait_for_task(task)
3237+
if task.info.state == 'error':
3238+
return {'changed': self.change_applied, 'failed': True, 'msg': task.info.error.msg,
3239+
'op': 'reconfig'}
3240+
32303241
# Rename VM
32313242
if self.params['uuid'] and self.params['name'] and self.params['name'] != self.current_vm_obj.config.name:
32323243
self.tracked_changes['name'] = self.params['name']

0 commit comments

Comments
 (0)