5 Replies Latest reply on Jul 1, 2019 4:53 AM by Daniel Langenhan

    vCO - get all clusters in a datacenter

    stangrig Lurker

      Do you know how I can get a list of all Clusters that are in a certain Datacenter?

       

      Thanks in advance

        • 1. Re: vCO - get all clusters in a datacenter
          qc4vmware Master

          VcPlugin.getAllClusterComputeResources() .  You can add an XPath query as a filtering mechanism or loop through the results and see if the datacenter matches what you are looking for.

          1 person found this helpful
          • 2. Re: vCO - get all clusters in a datacenter
            Burke- Virtuoso
            VMware Employees

            This scriptable task code can do that...

            Input: datacenter (VC:Datacenter)

            Output: clusters (Array/VC:ClusterComputeResource)

            Script:

            var clusters = new Array;
            var folder = datacenter.hostFolder;
            var children = folder.childEntity;
            for each (child in children){
                if (child instanceof VcClusterComputeResource){
                    clusters.push(child);
                    System.debug("Cluster added: "+child.name);
                }
            }
            
            

            If the above code is to be used in an action rather than a scriptable task, just add the following as the first line (helpful when used in Presentation settings:

            if(datacenter == null) return null;
            

            And this to the last line:

            return clusters;
            
            • 3. Re: vCO - get all clusters in a datacenter
              stangrig Lurker

              Perfect! Just missing return

               

              var clusters = new Array; 

              var folder = datacenter.hostFolder; 

              var children = folder.childEntity; 

              for each (child in children){ 

                  if (child instanceof VcClusterComputeResource){ 

                      clusters.push(child); 

                      System.debug("Cluster added: "+child.name); 

                  } 

              return clusters

              • 5. Re: vCO - get all clusters in a datacenter
                Daniel Langenhan Enthusiast

                Hi,

                 

                late but...here is a function that recursively searches (if there are more folders in between the Cluster and the Datacenter)

                 

                function getChildren(folder){
                    for each (child in folder.childEntity){ 
                        if (child instanceof VcClusterComputeResource){ 
                            output.push(child);             
                            System.debug("Cluster added: "+child.name); 
                        } 
                        if (child instanceof VcFolder){
                            System.debug("found folder "+child.name);
                            getChildren(child);
                        }
                    }
                    return output;
                }   
                
                if (datacenter){
                    var output = new Array; 
                    return getChildren(datacenter.hostFolder);
                } else {
                    throw ("no Datacenter provided");
                }   
                
                1 person found this helpful