VMware Cloud Community
DexG83
Enthusiast
Enthusiast
Jump to solution

vsphere.machine Resource Action - use vRO action as external source to get current cpu and memory

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

Labels (2)
1 Solution

Accepted Solutions
xian_
Expert
Expert
Jump to solution

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:

2022-05-17 08:32:34.020 +02:00 INFO Number of VMs found with uuid 501930aa-7fb3-84e8-5c99-520dbd603127: 1
2022-05-17 08:32:34.022 +02:00 INFO VM name: vm008
2022-05-17 08:32:34.023 +02:00 INFO VM CPU count: 2

View solution in original post

6 Replies
Ankush11s
VMware Employee
VMware Employee
Jump to solution

any reason you are not utilising the resize option OOB ?

Reply
0 Kudos
DexG83
Enthusiast
Enthusiast
Jump to solution

I need the ability to schedule the modification and send some mail notifications and so on.

Reply
0 Kudos
xian_
Expert
Expert
Jump to solution

create an action that takes the vCenter UUID and returns cpu or ram value by vcenter UUID

Here is mine, a fake action:

xian__0-1652713989967.png

 

Now you need to edit your resource action to use it as a default value, by assigning the property of VM object:

The result:

xian__3-1652768863360.png

 

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

xian__2-1652714805272.png

 

Reply
0 Kudos
DexG83
Enthusiast
Enthusiast
Jump to solution

Hi Xian,

thanks for your reply. I built such action and now added vCenter UUID from Resource properties.

DexG83_0-1652759282680.png

But is there any way to get the VM UUID to use one these action to get the VM Object?

DexG83_1-1652760129980.png

with that I want to use vm.config.hardware.numCPU to get the LIVE data.

Reply
0 Kudos
xian_
Expert
Expert
Jump to solution

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:

2022-05-17 08:32:34.020 +02:00 INFO Number of VMs found with uuid 501930aa-7fb3-84e8-5c99-520dbd603127: 1
2022-05-17 08:32:34.022 +02:00 INFO VM name: vm008
2022-05-17 08:32:34.023 +02:00 INFO VM CPU count: 2
DexG83
Enthusiast
Enthusiast
Jump to solution

Hey Xian,

thanks alot, this works perfectly.

Btw, is there any documentation about all available fields in Resource properties?

Reply
0 Kudos