Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 258290

Re: Finding Virtual Machines based on a property

$
0
0

Some small additions to filter the value directly in the query and optionally get all the properties for the vm results

 

function findVirtualMachinesWithPropertyValue(vcacHost, propertyName, propertyValue, getProperties) {     return vCACEntityManager.readModelEntitiesBySystemQuery(          vcacHost.id,          "ManagementModelEntities.svc",          "VirtualMachineProperties",          "PropertyName eq '" + propertyName + "' and PropertyValue eq '" + propertyValue + "'"     ).reduce(function (vms, propertyEntity) {          // get the VirtualMachineEntity          var virtualMachine = propertyEntity.getLink(vcacHost, "VirtualMachine").shift()          var result = { vm: virtualMachine, properties: new Properties() }          // optionally create a properties object containing the vms properties          if (getProperties) {               virtualMachine.getLink(host, "VirtualMachineProperties").forEach(function (prop) {                    result.properties.put(prop.getProperty("PropertyName"), prop.getProperty("PropertyValue"))               })          }          return vms.concat(result)     }, [])
}

 

Called like

 

var results = findVirtualMachinesWithPropertyValue(host, "__Cafe.Root.Request.Id", "some-uuid-here", true)

 

each result contains the vm entity and properties


Viewing all articles
Browse latest Browse all 258290

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>