VMware Cloud Community
BWinchell
Enthusiast
Enthusiast
Jump to solution

List all Resource Pools that are part of a ESXi cluster

Hello,

I am trying to get a piece of code working that will list all the resource pools that are present in a ESXi cluster.

  • I know I can find what resource pool a VM resides to.  I do not want that.

// Find a matching resource pool on an ESXi hosts

  var esxiCluster = esxiHost.parent;

  var esxiClusterResourcePools = esxiCluster.resourcePool_ResourcePool;

  System.log("what is the ESXi cluster: " + esxiCluster.name);

  System.log("vimtype: " + esxiCluster.vimType);

  System.log("what pools exists: " + esxiClusterResourcePools);

So I know the vimType will come back with what I expect (ClusterComputeResource).  The issue I have is the object "resourcePool" refers to the root resource pool (in my case it is "resources").

What I want is all the DRS resource pools we have setup.  I need something like "resourcePool_ResourcePool.children".

Any help is appreciated.

Thanks

B

1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Check if this sample code works for your case:

var esxiCluster = esxiHost.parent; 

var esxiClusterResourcePools = esxiCluster.resourcePool_ResourcePool; 

var pools = System.getModule("com.vmware.library.vc.resourcePool").getAllChildResourcePool(esxiClusterResourcePools);

// dump names of child pools

for each (var pool in pools) {

  System.log(pool.name);

}

View solution in original post

0 Kudos
7 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Check if this sample code works for your case:

var esxiCluster = esxiHost.parent; 

var esxiClusterResourcePools = esxiCluster.resourcePool_ResourcePool; 

var pools = System.getModule("com.vmware.library.vc.resourcePool").getAllChildResourcePool(esxiClusterResourcePools);

// dump names of child pools

for each (var pool in pools) {

  System.log(pool.name);

}

0 Kudos
BWinchell
Enthusiast
Enthusiast
Jump to solution

Thanks IIian.  Not exactly sure how I missed that one.

B

0 Kudos
BWinchell
Enthusiast
Enthusiast
Jump to solution

I did find another solution to this query.  I was close before but no cigar:smileycry:

var esxiClusterResourcePools = esxiCluster.resourcePool.resourcePool_ResourcePool;

*** Above is actually incorrect.  Will only return the 1st level of resource pools *** - See IIian's reply below

iiliev
VMware Employee
VMware Employee
Jump to solution

The solutions are not equivalent; they may return different results if there are resource pools that are children of other resource pools.

The variant in reply #1 recursively scans the entire resource pool tree hierarchy. The variant in reply #3 returns only the top-level resource pools and doesn't scan recursively for child resource pools. In my environment, it means 44 vs 15 resource pools found.

0 Kudos
BWinchell
Enthusiast
Enthusiast
Jump to solution

Very correct.  Good catch.

Can you get 2 correct answers for the same string? :smileylaugh:

0 Kudos
GBartsch
Enthusiast
Enthusiast
Jump to solution

So I actually like that...

I'm writing a workflow where I don't care to get ALL of the Resource Pools, but just those at the same level I'm checking.

The interesting part is that I can use #3 to do that, which is pretty helpful if you don't care of there are other pools with the same name nested up other resource pools.

(In other words: I want to only see whats directly under Resources, and if the pool I want does not exist at the top-level, create it.  [Even if there are pools nested under other top-level pools.])

I think you may have helped me with this annoying issue. 

0 Kudos
Paragbhardwaj19
Enthusiast
Enthusiast
Jump to solution

I need to do the same thing but could not understand below line

var esxiClusterResourcePools = esxiCluster.resourcePool_ResourcePool;

when i use this code it get fail with below error

 Error in (Workflow:Cluster_per_VM / Scriptable task (item1)#2) TypeError: Cannot read property "resourcePool_ResourcePool" from undefined

 

Can someone please explain what this ".resourcepool_Resourcepool."

 

Thanks

Parag

0 Kudos