Orchestrator Function: Find a DRS Group ( Virtual Machine ) and Add New Virtual Machines

by Simon Sparks · 18 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 Find a Virtual Machine DRS Group and Add New Virtual Machines

Function AddVcVirtualMachineToExistingVcClusterVmGroup

publicAddVcVirtualMachineToExistingVcClusterVmGroup(objVcClusterComputeResource:VcClusterComputeResource,arrVcVirtualMachineNew:VcVirtualMachine[],strVcClusterVmGroupName:string,strDataCenterName:string):void{

letobjVcClusterConfigInfoEx:VcClusterConfigInfoEx=objVcClusterComputeResource.configurationExasVcClusterConfigInfoEx;

letarrVcClusterGroupInfo:VcClusterGroupInfo[]=objVcClusterConfigInfoEx.group;

letarrVcClusterVmGroup:VcClusterVmGroup[]=arrVcClusterGroupInfo.filter((objVcClusterGroupInfo:VcClusterGroupInfo):objVcClusterGroupInfoisVcClusterVmGroup=>{

returnobjVcClusterGroupInfoinstanceofVcClusterVmGroup;

});

letobjVcClusterVmGroup:VcClusterVmGroup=arrVcClusterVmGroup.find((objVcClusterVmGroup:VcClusterVmGroup):boolean=>{

returnobjVcClusterVmGroup.name==strVcClusterVmGroupName;

});

letarrVcVirtualMachine:VcVirtualMachine[]=objVcClusterVmGroup.vm;

arrVcVirtualMachine=arrVcVirtualMachine.concat(arrVcVirtualMachineNew);

objVcClusterVmGroup.vm=arrVcVirtualMachine;

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

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

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

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