Skip to content

Instantly share code, notes, and snippets.

@YagmurOzden
Last active December 24, 2021 06:14
Show Gist options
  • Save YagmurOzden/63d77d1f0b0cca61aed8760cdedced73 to your computer and use it in GitHub Desktop.
Save YagmurOzden/63d77d1f0b0cca61aed8760cdedced73 to your computer and use it in GitHub Desktop.
returns a random host belonging to that cluster (VMware vRO action)
// VMware vRealize Orchestrator action sample
// vRA 8.4
//action input type: cluster (string, Enter the cluster entry so that the host can be selected)
//action return type: VC:HostSystem
// this code below gets all clusters
var clusters =VcPlugin.getAllClusterComputeResources();
// this code below gets all hosts
var hosts = VcPlugin.getAllHostSystems();
var list=new Array();
//this loop is to check all clusters
for (i in clusters){
if (cluster==clusters[i].name){
for(j in hosts){
for(var y=0 ; y< clusters[i].host.length;y++){
//System.log(y+" :"+ clusters[i].host[y].name)
if(hosts[j].name==clusters[i].host[y].name){
list.push(hosts[j]);
}
}
}
}
}
var randomHost=list[Math.floor(Math.random() * list.length)];
System.log("Get cluster's host action finished. this action returns a random host belonging to that cluster. Host: "+randomHost.name)
return randomHost;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment