reubenur-rahman / vmware-pyvmomi-examples

The example codes are written using the VMware official python library pyvmomi
Apache License 2.0
89 stars 60 forks source link

Sample code for disabling vmotion on a VM? #9

Closed mmumshad closed 7 years ago

mmumshad commented 7 years ago

Do you have sample code for disabling vmotion on a single VM? I am trying to deploy a VM from a template, and when it powers on, I need to be able to disable vmotion for a period of time, until it finishes customization. Appreciate any help.

reubenur-rahman commented 7 years ago

You have to reconfigure cluster to disable DRS automation for that particular VM.

drs_vm_config_info = vim.cluster.DrsVmConfigInfo()
drs_vm_config_info.key = vm
drs_vm_config_info.enabled = False
drs_vm_config_info.behavior = vim.cluster.DrsConfigInfo.DrsBehavior.manual

drs_config_spec = vim.cluster.DrsVmConfigSpec()
drs_config_spec.operation = vim.option.ArrayUpdateSpec.Operation.add
drs_config_spec.info = drs_vm_config_info
cluster_spec_ex = vim.cluster.ConfigSpecEx()
cluster_spec_ex.drsVmConfigSpec = [drs_config_spec]

cluster.ReconfigureComputeResource_Task(cluster_spec_ex, True)

Note: You may also need to add an affinity rule.

mmumshad commented 7 years ago

@rreubenur Thank you very much!!! This helped a lot!!