Orchestrator Function: Add a DRS VM Group and a DRS VM Affinity Rule

by Simon Sparks · 27 February 2014

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

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

Filename: vCenterServerService.ts

Description: Orchestrator Function to add a DRS VM Group and a DRS VM Affinity Rule.

Function AddVcVirtualMachineToVcClusterVmGroup

publicAddVcVirtualMachineToVcClusterVmGroup(objVcClusterComputeResource:VcClusterComputeResource,objVcVirtualMachine:VcVirtualMachine,strVmGroupName:string,strDataCenterName:string):void{

letarrVcVirtualMachine:VcVirtualMachine[]= [];
arrVcVirtualMachine.push(objVcVirtualMachine);

letobjVcClusterVmGroup:VcClusterVmGroup=newVcClusterVmGroup();
objVcClusterVmGroup.name=strDataCenterName+" -"+strVmGroupName;
objVcClusterVmGroup.userCreated=true;
objVcClusterVmGroup.vm=arrVcVirtualMachine;

letobjVcClusterGroupSpec:VcClusterGroupSpec=newVcClusterGroupSpec();
objVcClusterGroupSpec.info=objVcClusterVmGroup;
objVcClusterGroupSpec.operation=VcArrayUpdateOperation.add;

letarrVcClusterGroupSpec:VcClusterGroupSpec[]= [];
arrVcClusterGroupSpec.push(objVcClusterGroupSpec);

letobjVcClusterVmHostRuleInfo:VcClusterVmHostRuleInfo=newVcClusterVmHostRuleInfo();
objVcClusterVmHostRuleInfo.enabled=true;
objVcClusterVmHostRuleInfo.mandatory=false;
objVcClusterVmHostRuleInfo.userCreated=true;
objVcClusterVmHostRuleInfo.name=strDataCenterName+" Affinity -"+strVmGroupName;
objVcClusterVmHostRuleInfo.affineHostGroupName=strDataCenterName;
objVcClusterVmHostRuleInfo.vmGroupName=strDataCenterName+" -"+strVmGroupName;

letobjVcClusterRuleSpec:VcClusterRuleSpec=newVcClusterRuleSpec();
objVcClusterRuleSpec.info=objVcClusterVmHostRuleInfo;
objVcClusterRuleSpec.operation=VcArrayUpdateOperation.add;

letarrVcClusterRulesSpec:VcClusterRuleSpec[]= [];
arrVcClusterRulesSpec.push(objVcClusterRuleSpec);

letobjVcClusterConfigSpecEx:VcClusterConfigSpecEx=newVcClusterConfigSpecEx();
objVcClusterConfigSpecEx.groupSpec=arrVcClusterGroupSpec;
objVcClusterConfigSpecEx.rulesSpec=arrVcClusterRulesSpec;

letobjVcTask:VcTask=objVcClusterComputeResource.reconfigureCluster_Task(objVcClusterConfigSpecEx,true);

this.WaitForVcTaskEnd(objVcTask,1);
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like