VMWarevRAvRO

Retrieve Custom Properties of vCAC VM from vC:VirtualMachine

This method of retrieving custom properties accesses them directly from the vcac entities (the data sources) by finding custom properties that are ‘linked’ to the virtual machine. This is really useful when you need to use custom properties in your workflows. Note that the Extensibility Lifecycle properties do not affect how this works and you will be able to retrieve all custom properties, including hidden ones.

I have provided the code can be used to retrieve all of the following:

  • Blueprint Id;
  • Blueprint Name;
  • Component Id;
  • Cloned From (the template that was used for the new vm);
  • Compute Resource Name (Host/Cluster);
  • Guest Customization specification used;
  • CPU count, memory size;
  • disk sizes, total disk usage, disk device Id;
  • Attached networks;
  • Guest OS Identifier;
  • Host Name;
  • Storage Cluster Name;
  • vCenter Folder;
  • Virtual Machine UUID;
  • Reservation Policy ID.

    /**
    * Gets the custom properties that are associated with the provided vcac virtual machine.
    * @param {vc:VirtualMachine} vcVm – The virtaul machine of vCenter.
    */

    var vcVmName = vcVm.name;

    var vcacHost = Server.findAllForType(“vCAC:VCACHost”)[0];

    var vmProperties = new Properties();

    System.log (“vcVm.config.instanceUuid : ” + vcVm.config.instanceUuid);

    var vcacVMEntity = System.getModule(“com.vmware.library.vcac”).getVirtualMachineByExternalRefId(vcacHost, vcVm.config.instanceUuid);

    var properties = vcacVMEntity.getLink(vcacHost, “VirtualMachineProperties”);

    for(var i = 0 ;i < properties.length; i++){

       var PropertyName = properties[i].getProperty(“PropertyName”);

       var PropertyValue = properties[i].getProperty(“PropertyValue”);

      System.debug(PropertyName  + “: ” + PropertyValue  );

      vmProperties.put(propertyName, propertyValue);

    }

    System.debug(“VM Properties ” + vmProperties);

Tags

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also

Close
Close