ericr999
Enthusiast
Enthusiast

Retrieve related objects to ESX, DSCluster, DS. etc

Jump to solution

Hello,

I'm looking to replicated the functionnality found in vCenter that helps find a related object.

Like now I'd like to see all the ESX Clusters linked to a Datastore Cluster. I can't seem to find a relation, and now I'm browsing through the MOB and I'm getting a headache! I can't seem to find a good pattern that would always work to retrieve that info.

Anyone else tried that before ?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee

Hi,

Something like the following should work. Its input is the variable dsc - the datastore cluster, aka storage pod

for each (var datastore in dsc.childEntity) {

  for each (var h in datastore.host) {

    var p = h.key.parent;

    while (p != null && !(p instanceof VcClusterComputeResource)) {

      p = p.parent;

    }

    if (p != null) {

      System.log("cluster: " + p.name);

    }

  }

}

What the code does is to enumerate all datastores in the datastore cluster (outer for), then enumerate all host systems for the given datastore (inner for), then for each host system find its cluster by walking up the parents path.

View solution in original post

0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee

Hi,

Something like the following should work. Its input is the variable dsc - the datastore cluster, aka storage pod

for each (var datastore in dsc.childEntity) {

  for each (var h in datastore.host) {

    var p = h.key.parent;

    while (p != null && !(p instanceof VcClusterComputeResource)) {

      p = p.parent;

    }

    if (p != null) {

      System.log("cluster: " + p.name);

    }

  }

}

What the code does is to enumerate all datastores in the datastore cluster (outer for), then enumerate all host systems for the given datastore (inner for), then for each host system find its cluster by walking up the parents path.

View solution in original post

0 Kudos
ericr999
Enthusiast
Enthusiast

Ilian, you always have the right solution for me! Smiley Happy

Also, I'm still learning the vSphere API, do you have a suggestion of books/courses that could help me improve my programming skills in that area ?

I'm not a super guru in coding either, I know my way around, but most of the time I spend time looking on the web to search for suggestions.

Thanks again for your precious help!

0 Kudos