Hello All,
Back again for insight from those of you that have built server provisioning workflows before.
I have my data center and cluster i want to deploy VM too.
I'm trying to determine best way to obtain the following items.
1. ESXi host that is online. (I can deploy a VM too)
2. Resource pool for cluster/ESXi host I'm deploying on. Should only be 1 as we don't use resource pools in our environments.
Any insight on how i would go about getting this information?
Hi,
Not sure if this is the 'best' way but here is some sample code showing how to enumerate and dump online hosts and the resource pool of a cluster. The input parameter is the variable cluster of type VC:ClusterComputeResource
The code considers a host to be 'online' if it is powered on and not put in maintenance mode. If you have different definition for 'online', you can modify the filter condition accordingly.
// All hosts in the cluster
var hosts = cluster.host;
// You said you have a single resource pool, so it can be fetched directly from the cluster
var respool = cluster.resourcePool;
// Filter the 'online' hosts
var hostsOn = hosts.filter(function(host) {
return host.runtime.powerState == VcHostSystemPowerState.poweredOn
&& host.runtime.inMaintenanceMode == false;
})
// Dump the names of the online hosts and the resource pool
for each (var host in hostsOn) {
System.log("host: " + host.name);
}
System.log("resource pool: " + respool.name);
Hi,
Not sure if this is the 'best' way but here is some sample code showing how to enumerate and dump online hosts and the resource pool of a cluster. The input parameter is the variable cluster of type VC:ClusterComputeResource
The code considers a host to be 'online' if it is powered on and not put in maintenance mode. If you have different definition for 'online', you can modify the filter condition accordingly.
// All hosts in the cluster
var hosts = cluster.host;
// You said you have a single resource pool, so it can be fetched directly from the cluster
var respool = cluster.resourcePool;
// Filter the 'online' hosts
var hostsOn = hosts.filter(function(host) {
return host.runtime.powerState == VcHostSystemPowerState.poweredOn
&& host.runtime.inMaintenanceMode == false;
})
// Dump the names of the online hosts and the resource pool
for each (var host in hostsOn) {
System.log("host: " + host.name);
}
System.log("resource pool: " + respool.name);