I am quite new to vRO and developing a automation where I need to find datacenter using only VMName.
I am able to do it using, iterating all the datacenter and looking for my VMName.
var myDatacenters = VcPlugin.getAllDatacenters();
System.log(myDatacenters.length);
var bFound = false;
for each (dc in myDatacenters)
{
var allVMs = System.getModule('com.vmware.library.vc.datacenter').getAllVMsOfDatacenter(dc);
for each (vm in allVMs)
{
if (vm.name == vmname)
{
DataCenterName = dc.name;
System.log("Found the datacenter for VM "+vmname+" : "+DataCenterName);
return DataCenterName;
}
}//innerfor
}//outerfor
But this doesn't seem to be efficient way as number of VMs will grwo and this lookup will become lot slower.
Can somebody help me with better approach to find the Datacenter name using VmName?
thanks,
Sushant