Page 1 of 1

vRA get vSphere VM from vCAC VM

Posted: Tue Dec 01, 2015 2:39 pm
by leefriend
Often the need arises to interact with a vRA VM through the vSphere layer. This code finds the vSphere VM from the vCAC VM object.

Input parameters:
- vCACVm type vCAC:VirtualMachine

Output parameters:
- vSphereVm type VC:VirtualMachine

Code: Select all

var sdkConnections = VcPlugin.allSdkConnections;
for(var i in sdkConnections){
    var host = sdkConnections[i];
    // this uses contains in the xpath - in individual cases it might require more specific xpath criteria
    var vSphereVms = host.getAllVirtualMachines(null, "xpath:contains(name, '" + vCACVm.getEntity().getProperty("VirtualMachineName") + "')");
    // example assumes only 1 VM will be found
    vSphereVm = vSphereVms[0];