irene_zimmerman
Contributor
Contributor

convert an object reference to VimManagedObject

Hi,

I would like to set a Custom Attribute to all VMs that contains information about HA Restart Priority. If it is set to high I want the Attribute to be "Yes" otherwise it is "No". I loop trough all clusters and get the VM specific HA Setting (Cluster default ist Medium). The Problem I have ist with converting the VM Managed Object Reference to an Object to make operations on. "convertToVimManagedObject" needs as first input the "managed object holder". What does that mean and what would it be in the code below?

var clusters = VcPlugin.allClusterComputeResources;

var newValue="No";

var restartPrio;

for (var cluster in clusters){

var config=clusters[cluster].configuration;

var dasVm = config.dasVmConfig;

for (var das in dasVm){

var tempVMMO=dasVm[das].key;

var tempVM = VcPlugin.convertToVimManagedObject(object holder,tempVMMO);

restartPrio=dasVm[das].dasSettings.restartPriority

if (restartPrio.toLowerCase()=="high"){

newValue="Yes";

}

System.getModule("com.vmware.library.vc.customattribute").setOrCreateCustomField(tempVM, "HA", newValue);

}

}

Thanks and regrds,

Irene

0 Kudos
4 Replies
admin
Immortal
Immortal

This post has an example of the conversion. I hope it would help.

http://communities.vmware.com/thread/221614?tstart=15

Sia

0 Kudos
admin
Immortal
Immortal

Hi Irene,

I expect "cluster" is what you need.

Cheers,

Rob.

irene_zimmerman
Contributor
Contributor

Hi Rob,

thanks for the hint i tried clusters[cluster] and that works.

Is the managed object holder always the object where the managed object reference is set as a property of that object?

What are possible object holders? other than cluster? I also know 'vm' and 'host' are there others?

Thanks,

Irene

0 Kudos
admin
Immortal
Immortal

In fact you can use any ManagerObject (VirtualMachine, Hosts, etc.) as an object holder

0 Kudos