I have a very large workflow that determines the best host to deploy a new virtual machine on. I am trying to determine what that logic would look like. The best scenario that I can come up with is something like this:
/** input A cluster object New memory for a vm New vcpu for a vm */
var bestHost = null;
var hosts = cluster.hosts;
hosts.sort(function(a,b){ if(a.summary.runtime.quickstates.overallCpuUsage != b.a.summary.runtime.quickstates.overallCpuUsage) return a.summary.runtime.quickstates.overallCpuUsage - b.summary.runtime.quickstates.overallCpuUsage; else return a.summary.runtime.quickstates.overallMemoryUsage - b.summary.runtime.quickstates.overallMemoryUsage});
hosts.reverse();
for each(var host in hosts)
{
if(host.cpu + new cpu < capacity) //psuedo code
continue;
if(host.memory + new memory < capacity) //psuedo code
bestHost = host;
}