How to set key to ManagedObjectReference when calling vim.cluster.DrsVmConfigInfo

Trying to code module similar to vmware_cluster_drs but for specific VMs.

I am trying to instead use drsVmConfigSpec and dasVmConfigSpec which calls vim.cluster.DasVmConfigSpec / vim.cluster.DrsVmConfigSpec (info).

info for both point to DrsVmConfigInfo and have a key property with type key ManagedObjectReference ( then can pass VirtualMachine type and moid value).

Challenge is how to set the key to a ManagedObjectReference?

See below for what works in PowerCLI:

$spec.drsVmConfigSpec[0].info.key = New-Object VMware.Vim.ManagedObjectReference

How to do same in python?

These don’t work:

.info.key = vmodl.ManagedObjectReference

.info.key = VmomiSupport.GetWsdlType(‘urn:vim25’, ‘ManagedObjectReference’)

Sample snippets of what we have tried and no success yet in setting key to be the type of ManagedObjectReference.

Also tried as array etc.

cluster_config_spec = vim.cluster.ConfigSpecEx()
cluster_config_spec.drsVmConfigSpec = vim.cluster.DrsVmConfigSpec()
cluster_config_spec.drsVmConfigSpec.info = vim.cluster.DrsVmConfigInfo()
cluster_config_spec.drsVmConfigSpec.info.key = vmodl.ManagedObjectReference
cluster_config_spec.drsVmConfigSpec.info.key.type = “VirtualMachine”
cluster_config_spec.drsVmConfigSpec.info.key.value = self.params.get(‘vm_moid’)
cluster_config_spec.drsVmConfigSpec.info.enabled = self.enable_drs
cluster_config_spec.drsVmConfigSpec.info.behavior = self.params.get(‘drs_default_vm_behavior’)

Thanks for any suggestions or solution!

Patrick

FYI - Got something to work!

Can see my VM is in VM overrides in VCenter with correct setting after running.

Code snippets below (vm_moid is the moid from vmware_guest_info output)

vm_config_spec = vim.cluster.ConfigSpecEx()
vm_config_spec.drsVmConfigSpec = [vim.cluster.DrsVmConfigSpec()]
vm_config_spec.drsVmConfigSpec[0].operation = “add”
vm_config_spec.drsVmConfigSpec[0].info = vim.cluster.DrsVmConfigInfo()
vm_config_spec.drsVmConfigSpec[0].info.key = vim.VirtualMachine(self.params.get(‘vm_moid’))
vm_config_spec.drsVmConfigSpec[0].info.behavior = self.params.get(‘drs_vm_behavior’)
vm_config_spec.drsVmConfigSpec[0].info.enabled = self.params.get(‘enable’)

try:
task = self.cluster.ReconfigureComputeResource_Task(vm_config_spec, True)
changed, result = wait_for_task(task)
. . .