Hi Community,
I try to build an resource action to modify vm compute and memory values. For both I want to set the current values as default values. I created a vRO Action that I want to use as "external source" but now I am wondering how to get the virtual machine object from vRA?
Can anybody give me a hint?
Many thanks in advance,
Dex
Sorry I mixed up vCenter UUID with Provider ID, so I modified my answer as you need the UUID of the VM and not the UUID of vCenter.
I have updated my previous reply with the correct screenshot.
Here is a code snippet that can get the VcVm object out of UUID:
var vms = VcPlugin.getAllVirtualMachines(null, "xpath:instanceId='" + uuid + "'");
System.log("Number of VMs found with uuid " + uuid + ": " + vms.length);
if (vms.length) {
System.log("VM name: " + vms[0].name);
System.log("VM CPU count: " + vms[0].config.hardware.numCPU);
}
And the produced logs:
any reason you are not utilising the resize option OOB ?
I need the ability to schedule the modification and send some mail notifications and so on.
create an action that takes the vCenter UUID and returns cpu or ram value by vcenter UUID
Here is mine, a fake action:
Now you need to edit your resource action to use it as a default value, by assigning the property of VM object:
The result:
sripting.log:
2022-05-16 15:25:59.475+0000 INFO {|__SYSTEM|vro-gateway-PI9Tb4JdsJ3u8iIR:063bb2a6-03da-400c-a5a9-366221e018ea} [SCRIPTING_LOG] [script: com.test/getRam] (com.test/getRam) 501930aa-7fb3-84e8-5c99-520dbd603127
Hi Xian,
thanks for your reply. I built such action and now added vCenter UUID from Resource properties.
But is there any way to get the VM UUID to use one these action to get the VM Object?
with that I want to use vm.config.hardware.numCPU to get the LIVE data.
Sorry I mixed up vCenter UUID with Provider ID, so I modified my answer as you need the UUID of the VM and not the UUID of vCenter.
I have updated my previous reply with the correct screenshot.
Here is a code snippet that can get the VcVm object out of UUID:
var vms = VcPlugin.getAllVirtualMachines(null, "xpath:instanceId='" + uuid + "'");
System.log("Number of VMs found with uuid " + uuid + ": " + vms.length);
if (vms.length) {
System.log("VM name: " + vms[0].name);
System.log("VM CPU count: " + vms[0].config.hardware.numCPU);
}
And the produced logs:
Hey Xian,
thanks alot, this works perfectly.
Btw, is there any documentation about all available fields in Resource properties?