Orchestrator Function: vCenter HA Enable

by Simon Sparks · 20 September 2018

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 Enable vCenter HA

Function VcCustomizationIPSettingsBuild

privateVcCustomizationIPSettingsBuild(strIpAddress:string,strSubnetMask:string,strDnsDomainName:string,arrDNSServers:string[],arrGateway:string[],strPrimaryWINS:string,strSecondaryWINS:string):VcCustomizationIPSettings{

letobjVcCustomizationFixedIp:VcCustomizationFixedIp=newVcCustomizationFixedIp();
objVcCustomizationFixedIp.ipAddress=strIpAddress;

letobjVcCustomizationIPSettings:VcCustomizationIPSettings=newVcCustomizationIPSettings();
objVcCustomizationIPSettings.dnsDomain=strDnsDomainName;
objVcCustomizationIPSettings.dnsServerList=arrDNSServers;
objVcCustomizationIPSettings.gateway=arrGateway;
objVcCustomizationIPSettings.ip=objVcCustomizationFixedIp;
objVcCustomizationIPSettings.ipV6Spec=null;
objVcCustomizationIPSettings.netBIOS=VcCustomizationNetBIOSMode["enableNetBIOS"];
objVcCustomizationIPSettings.primaryWINS=strPrimaryWINS;
objVcCustomizationIPSettings.secondaryWINS=strSecondaryWINS;
objVcCustomizationIPSettings.subnetMask=strSubnetMask;

returnobjVcCustomizationIPSettings;
}

Function: VcSdkConnectionHAEnable

publicVcSdkConnectionHAEnable(objVcVirtualMachine:VcVirtualMachine,objVcDatstorePassive:VcDatastore,objVcDatstoreWitness:VcDatastore,objVcFolder:VcFolder,strVCenterSSLThumbprint:string,strUsername:string,strPassword:string,strDnsDomainName:string="lab.cloudbuildtools.com",strPrimaryWINS:string="",strSecondaryWINS:string="",arrDNSServers:string[],objVcDistributedVirtualPortgroup:VcDistributedVirtualPortgroup,strIpAddressActive:string="",strSubnetMaskActive:string="",arrGatewayActive:string[]= [],strIpAddressPassive:string="",strSubnetMaskPassive:string="",arrGatewayPassive:string[]= [],strIpAddressWitness:string="",strSubnetMaskWitness:string="",arrGatewayWitness:string[]= []):boolean{

letobjVcSdkConnection:VcSdkConnection=objVcVirtualMachine.sdkConnection

letobjVcCustomizationIPSettingsActive:VcCustomizationIPSettings=this.VcCustomizationIPSettingsBuild(strIpAddressActive,strSubnetMaskActive,strDnsDomainName,arrDNSServers,arrGatewayActive,strPrimaryWINS,strSecondaryWINS);
letobjVcCustomizationIPSettingsPassive:VcCustomizationIPSettings=this.VcCustomizationIPSettingsBuild(strIpAddressPassive,strSubnetMaskPassive,strDnsDomainName,arrDNSServers,arrGatewayPassive,strPrimaryWINS,strSecondaryWINS);
letobjVcCustomizationIPSettingsWitness:VcCustomizationIPSettings=this.VcCustomizationIPSettingsBuild(strIpAddressWitness,strSubnetMaskWitness,strDnsDomainName,arrDNSServers,arrGatewayWitness,strPrimaryWINS,strSecondaryWINS);

letobjVcClusterNetworkConfigSpec:VcClusterNetworkConfigSpec=newVcClusterNetworkConfigSpec();
objVcClusterNetworkConfigSpec.networkPortGroup=objVcDistributedVirtualPortgroup;
objVcClusterNetworkConfigSpec.ipSettings=objVcCustomizationIPSettingsActive;

letobjVcServiceLocatorNamePassword:VcServiceLocatorNamePassword=newVcServiceLocatorNamePassword();
objVcServiceLocatorNamePassword.username=strUsername;
objVcServiceLocatorNamePassword.password=strPassword;

letobjVcServiceLocator:VcServiceLocator=newVcServiceLocator();
objVcServiceLocator.credential=objVcServiceLocatorNamePassword;
objVcServiceLocator.instanceUuid=objVcSdkConnection.instanceUuid;
objVcServiceLocator.url="https://"+objVcSdkConnection.sdkId;
objVcServiceLocator.sslThumbprint=strVCenterSSLThumbprint;

letobjVcSourceNodeSpec:VcSourceNodeSpec=newVcSourceNodeSpec();
objVcSourceNodeSpec.activeVc=objVcVirtualMachine;
objVcSourceNodeSpec.managementVc=objVcServiceLocator;

letobjVcPassiveNodeDeploymentSpec:VcPassiveNodeDeploymentSpec=newVcPassiveNodeDeploymentSpec();
objVcPassiveNodeDeploymentSpec.folder=objVcFolder;
objVcPassiveNodeDeploymentSpec.nodeName=objVcVirtualMachine.name+"-passive";
objVcPassiveNodeDeploymentSpec.ipSettings=objVcCustomizationIPSettingsPassive;
objVcPassiveNodeDeploymentSpec.datastore=objVcDatstorePassive;

letobjVcNodeDeploymentSpecWitness:VcNodeDeploymentSpec=newVcNodeDeploymentSpec();
objVcNodeDeploymentSpecWitness.folder=objVcFolder;
objVcNodeDeploymentSpecWitness.nodeName=objVcVirtualMachine.name+"-witness";
objVcNodeDeploymentSpecWitness.ipSettings=objVcCustomizationIPSettingsWitness;
objVcNodeDeploymentSpecWitness.datastore=objVcDatstoreWitness;

letobjVcVchaClusterDeploymentSpec:VcVchaClusterDeploymentSpec=newVcVchaClusterDeploymentSpec();
objVcVchaClusterDeploymentSpec.witnessDeploymentSpec=objVcNodeDeploymentSpecWitness;
objVcVchaClusterDeploymentSpec.passiveDeploymentSpec=objVcPassiveNodeDeploymentSpec;
objVcVchaClusterDeploymentSpec.activeVcNetworkConfig=objVcClusterNetworkConfigSpec;
objVcVchaClusterDeploymentSpec.activeVcSpec=objVcSourceNodeSpec;

this.objLogger.info("Starting deployment task...");

letobjVcServiceContent:VcServiceContent=this.VcSdkConnectionGetVcServiceContent(objVcSdkConnection);

letobjVcFailoverClusterConfigurator:VcFailoverClusterConfigurator=objVcServiceContent.failoverClusterConfigurator;

try{
letobjVcTask:VcTask=objVcFailoverClusterConfigurator.deployVcha_Task(objVcVchaClusterDeploymentSpec);

this.WaitForVcTaskEnd(objVcTask,2);

returntrue;
}
catch (objException){

Utilities.logException(objException,this.objLogger,"VcSdkConnectionHAEnable");

returnfalse;
}
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like