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

**URL:** <https://forum.ansible.com/t/how-to-set-key-to-managedobjectreference-when-calling-vim-cluster-drsvmconfiginfo/37293>\
**Category:** Ansible Developer\
**Tags:** vmware\
**Created:** [November 2, 2022, 3:32pm UTC](https://forum.ansible.com/t/how-to-set-key-to-managedobjectreference-when-calling-vim-cluster-drsvmconfiginfo/37293 "2022-11-02T15:32:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![canadapatrick](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@canadapatrick](https://forum.ansible.com/u/canadapatrick)\
**Post date:** [November 2, 2022, 3:32pm UTC](https://forum.ansible.com/t/how-to-set-key-to-managedobjectreference-when-calling-vim-cluster-drsvmconfiginfo/37293/1 "2022-11-02T15:32:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![canadapatrick](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@canadapatrick](https://forum.ansible.com/u/canadapatrick)\
**Post date:** [November 2, 2022, 9:26pm UTC](https://forum.ansible.com/t/how-to-set-key-to-managedobjectreference-when-calling-vim-cluster-drsvmconfiginfo/37293/2 "2022-11-02T21:26:47Z")

</div>

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)  
. . .
