Do you know how I can get a list of all Clusters that are in a certain Datacenter?
Thanks in advance
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;
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.
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;
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
Show off!
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");
}