/**
* Returns the names of all VMs in a cluster as array of strings.
*
* Checked with release 8.14.1 and 8.18.0
*/
function getAllVmsOfCluster(datacenterName, clusterName) {
/**
* @function getAllVmsOfCluster
* @param {string} datacenterName
* @param {string} clusterName
* @returns {Array.<string>}
*/
var vmNames = [];
var datacenters = VcPlugin.getAllDatacenters([], datacenterName);
datacenters.forEach( function(datacenter) {
var children = datacenter.hostFolder.childEntity;
children.forEach( function(child) {
if (
child.vimType === "ClusterComputeResource" &&
child.name === clusterName
) {
child.host.forEach( function(host) {
host.vm.forEach( function(vm) {
vmNames.push(vm.name);
});
});
}
});
});
return vmNames.sort();
}
var vmNames = getAllVmsOfCluster("myDatacenter", "myCluster");
// Example for the HOL
// var vmNames = getAllVmsOfCluster(
// "mgmt-datacenter-01",
// "mgmt-cluster-01"
// );
|