BillStreet00
Enthusiast
Enthusiast

List Custom Properties for Day 2 Actions

We have a process that promotes a VM from dev to operating by "stamping" a project code into a custom property. Each project code allows for a specific number of VM's to be promoted. I am trying to get a list every VM under management, verify if it has this custom property, then evaluate the value. There are several thousand VM's under management. My thought was to read all of the VM's into an array and loop through it.  As a result I have a question.  How can I pull all of the vm's and their custom properties in an array?  I know how to dig around on VM's during provisioning however I can't seem to find a way to get this list on VM's that have already been provisioned.

3 Replies
qc4vmware
Virtuoso
Virtuoso

I use this query to grab a list of managed vms

var vCACVms = Server.findAllForType("vCAC:VirtualMachine", "VirtualMachineName ne '[NONE]' and IsManaged eq true");

You will need to loop through and get the properties for each.  I've attached an action I put together to grab these.  It takes an optional host as an input along with the vm.

If you want all the vms and the custom properties in some sort of an array you'll need to make an array of properties or create some sort of object that is indexed in some way that makes sense.  Since you have the vms I'm not totally sure why you'd need to create an array of the vm's and the properties exactly but what I just described is how you'd need to do it.

Paul

0 Kudos
BillStreet00
Enthusiast
Enthusiast

Thanks Paul, this is what I ended up with.

var vmList = Server.findAllForType("vCAC:VirtualMachine");

var i = 0;

for each (var vm in vmList){

     var entity = System.getModule("com.vmware.library.vcac").getPropertiesFromVirtualMachine(host,vm);

     var vmProps = entity.get("MY CUSTOM PROP");

          if(vmProps){

              ++i;

          }

}

System.log("I found " +i+" instances.");

Since not all of my vm's will have this custom property stamped on it, I am checking to see if it exists then I will evaluate it.  Right now I am just counting.  The System.getModule tosses everything out to the console for now.  I want to stop that so I can log whats actually going on.

qc4vmware
Virtuoso
Virtuoso

Looks good... That module is pretty basic so it will be easy to copy it and prune the logging out.

0 Kudos