Skip to content

Instantly share code, notes, and snippets.

@YagmurOzden
Created April 5, 2022 08:22
Show Gist options
  • Save YagmurOzden/e8325838c5ef1e3b970e0e4f6140ecd8 to your computer and use it in GitHub Desktop.
Save YagmurOzden/e8325838c5ef1e3b970e0e4f6140ecd8 to your computer and use it in GitHub Desktop.
returns a random host belonging to that cluster , vRO, vRO action, workflow, cluster, host
// VMware vRealize Orchestrator action sample
// vRA 8.4
//workflow return type: (VC:HostSystem),
// input type: cluster(string, Enter the cluster entry so that the host can be selected)
// this code below gets all clusters
var clusters =VcPlugin.getAllClusterComputeResources();
var hosts = VcPlugin.getAllHostSystems();
//this loop is to check all clusters
var list=new Array();
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