VMware Cloud Community
TimDScott
Enthusiast
Enthusiast
Jump to solution

Determining vcenter / data center & resource pool from VC:VirtualMachine object

Hi All,

I'm working on a workflow that takes an input of type VC:VirtualMachine, then runs different processes depending on the vm's vcenter / data center & resource pool values.

What I don't know is the best way to get hold of these 3 values. Can anyone help?

Thanks in advance!

Tim.

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi Tim,

Here is some sample code (the input is variable vm of type VC:VirtualMachine):

// find resource pool

System.log("resource pool: " + vm.resourcePool);

// find datacenter

var p = vm.parent;

while (p != null) {

  if (p instanceof VcDatacenter) {

    System.log("datacenter: " + p);

    break;

  }

  p = p.parent;

}

// find vCenter connection

System.log("vcenter: " + vm.sdkConnection);

View solution in original post

Reply
0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi Tim,

Here is some sample code (the input is variable vm of type VC:VirtualMachine):

// find resource pool

System.log("resource pool: " + vm.resourcePool);

// find datacenter

var p = vm.parent;

while (p != null) {

  if (p instanceof VcDatacenter) {

    System.log("datacenter: " + p);

    break;

  }

  p = p.parent;

}

// find vCenter connection

System.log("vcenter: " + vm.sdkConnection);

Reply
0 Kudos
TimDScott
Enthusiast
Enthusiast
Jump to solution

Perfect, thank you!

Reply
0 Kudos