VMware Cloud Community
ccurry
Contributor
Contributor

Return custom values through vCenter Orchestrator API

I'm looking to remotely query my vCenter installation for a list of snapshots related to a particular VM. I have tried using the Perl SDK, but it returns a SOAP request error that I haven't been able to find a fix for. I would prefer using the vCenter Orchestrator to return an array of snapshots in an XML/JSON file, but I can't find any API calls that will do this. The closest I can find is returning the log of a specific workflow. Is there any way of getting a list of VM snapshots to an external host on demand?

I am running vCenter 5.5 and vCO 5.5. Thanks in advance for any help.

Reply
0 Kudos
4 Replies
dvatov
VMware Employee
VMware Employee

Take a look at vSphere API docs - vSphere 6.0 Documentation Center‌ for VirtualMachine. What you need is probably rootSnapshot property. You have the same objects exposed in vCO as described in vSphere documentation.

Reply
0 Kudos
ccurry
Contributor
Contributor

From what I can tell, I do need the rootSnapshot property, but I need to first get an instance of VirtualMachine. It looks as though the only methods that return a VirtualMachine do so as part of an action, I can't find any that will simply return a VM by name. Am I missing something?

Reply
0 Kudos
dvatov
VMware Employee
VMware Employee

Take a look at the attached sample workflows - you can use them to get a VM by name with regex.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

Here is somewhat simpler code to search VMs by name that does not use property collector directly:

var vmName = "vcova"; // sample VM name name to search for

//var xpath = "xpath:name='" + vmName + "'";  // XPath expression for VM name exactly matching the given string

//var xpath = "xpath://name[starts-with(.,'"  + vmName +"')]";  // XPath expression for VM name starting with the given string

var xpath = "xpath:name[contains(.,'"  + vmName +"')]";  // XPath expression for VM name containing the given string as a substring

var vms = VcPlugin.getAllVirtualMachines(null, xpath);

if (vms == null) {

  System.log("No VMs found");

} else {

  for each (var vm in vms) {

    System.log("Found VM: " + vm.name);

  }

}

Reply
0 Kudos