VMware Cloud Community
rwk1982
Enthusiast
Enthusiast

Find vCenter VM by instanceUUID

A vRA VM is linked with a vCenter VM by the "instanceUUID". For Example if you like to change something on the VM in the "Compute post provision" State you can extract the UUID from:
 
inputProperties.customProperties.instanceUUID
 
and use this Code to get vCenter VM:
 
Input: InstanceUuid
Input Type: String
 
Return Type: VC:VirtualMachine

 

var vc_uuid = InstanceUuid

var vm2return = null
var arr_results = []

for each (vcenter in VcPlugin.allSdkConnections) {

	var results = vcenter.searchIndex.findAllByUuid(null,vc_uuid,true,true)

    for each (item in results) {

        arr_results.push(item)

    }
	
}

if (arr_results.length = 1) {
    
    vm2return = arr_results[0]

} else if (arr_results.length > 1) {

    System.log("Duplicated Instance UUID found!")

} else {

    System.log("Nothing found...")

}

return vm2return

 

Drink coffee.. Do stupid things faster with more energy...
0 Replies