Orchestrator Function: vCenter Cluster Compute Resource Get Best VcHostSystem

by Simon Sparks · 5 January 2026

To use this function add it to the class library file named vCenterServerService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: vCenterServerService.ts

Public Function: VcClusterComputeResourceGetBestVcHostSystem

publicVcClusterComputeResourceGetBestVcHostSystem(objVcClusterComputeResource:VcClusterComputeResource):VcHostSystem{
letarrVcHostSystem:VcHostSystem[]=this.VcHostSystemGetAllByVcClusterComputeResource(objVcClusterComputeResource);

arrVcHostSystem.sort((objVcHostSystemA:VcHostSystem,objVcHostSystemB:VcHostSystem):1| -1|0=>{

letobjVcHostListSummaryA:VcHostListSummary=objVcHostSystemA.summary;
letobjVcHostListSummaryB:VcHostListSummary=objVcHostSystemB.summary;

letobjVcHostListSummaryQuickStatsA:VcHostListSummaryQuickStats=objVcHostListSummaryA.quickStats;
letobjVcHostListSummaryQuickStatsB:VcHostListSummaryQuickStats=objVcHostListSummaryB.quickStats;

if (objVcHostListSummaryQuickStatsA.overallCpuUsage<objVcHostListSummaryQuickStatsB.overallCpuUsage){
return-1;
}elseif (objVcHostListSummaryQuickStatsA.overallCpuUsage>objVcHostListSummaryQuickStatsB.overallCpuUsage){
return1;
}
return0;
});

if (arrVcHostSystem.length!=null&&arrVcHostSystem.length>1){
letobjVcHostSystemUsable:VcHostSystem=arrVcHostSystem.pop();

this.objLogger.info(`We have chosen to use VcHostSystem '${objVcHostSystemUsable.name}' which has an overall CPU usage of '${objVcHostSystemUsable.summary.quickStats.overallCpuUsage}' MHz to perform the compute and storage vMotion.`);

returnobjVcHostSystemUsable;
}
else{
returnnull;
}
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like