You can use the finder methods in the vCenter plug-in to query for vCenter inventory objects. You can use XPath expressions to define search parameters.

The vCenter plug-in includes a set of object finder methods such as getAllDatastores(), getAllResourcePools(), findAllForType(). You can use these methods to access the inventories of the vCenter instances that are connected to your Automation Orchestrator server and search for objects by ID, name, or other properties.

For performance reasons, the finder methods do not return any properties for the queried objects, unless you specify a set of properties in the search query.

You can consult an online version of the Scripting API for the vCenter plug-in on the Orchestrator documentation home page.

Important: The queries based on XPath expressions might impact the Automation Orchestrator performance because the finder method returns all objects of a given type on the vCenter side and the query filters are applied on the vCenter plug-in side.

Using XPath Expressions with the vCenter Plug-In Examples

When you invoke a finder method, you can use expressions based on the XPath query language. The search returns all the inventory objects that match the XPath expressions. If you want to query for any properties, you can include them to the search script in the form of a string array.

The following JavaScript example uses the VcPlugin scripting object and an XPath expression to return the names of all datastore objects that are part of the vCenter managed objects and contain the string ds in their names.

var datastores = VcPlugin.getAllDatastores(null, "xpath:name[contains(.,'ds')]");
for each (datastore in datastores){
     System.log(datastore.name); 
 }

The same XPath expression can be invoked by using the Server scripting object and the findAllForType finder method.

var datastores = Server.findAllForType("VC:Datastore", "xpath:name[contains(.,'ds')]");
for each (datastore in datastores){
     System.log(datastore.name); 
 }

The following script example returns the names of all host system objects whose ID starts with the digit 1.

var hosts = VcPlugin.getAllHostSystems(null, "xpath:id[starts-with(.,'1')]");
for each (host in hosts){
     System.log(host.name); 
}

The following script returns the names and IDs of all data center objects that contain the string DC, in upper- or lower-case letters, in their names. The script also retrieves the tag property.

var datacenters = VcPlugin.getAllDatacenters(['tag'], "xpath:name[contains(translate(., 'DC', 'dc'), 'dc')]");
for each (datacenter in datacenters){
     System.log(datacenter.name + " "  +  datacenter.id); 
}