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
private VcCustomizationIPSettingsBuild(strIpAddress: string, strSubnetMask: string, strDnsDomainName: string, arrDNSServers: string[], arrGateway: string[], strPrimaryWINS: string, strSecondaryWINS: string): VcCustomizationIPSettings {
let objVcCustomizationFixedIp: VcCustomizationFixedIp = new VcCustomizationFixedIp();
objVcCustomizationFixedIp.ipAddress = strIpAddress;
let objVcCustomizationIPSettings: VcCustomizationIPSettings = new VcCustomizationIPSettings();
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;
return objVcCustomizationIPSettings;
}Function: VcSdkConnectionHAEnable
public VcSdkConnectionHAEnable(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 {
let objVcSdkConnection: VcSdkConnection = objVcVirtualMachine.sdkConnection
let objVcCustomizationIPSettingsActive: VcCustomizationIPSettings = this.VcCustomizationIPSettingsBuild(strIpAddressActive, strSubnetMaskActive, strDnsDomainName, arrDNSServers, arrGatewayActive, strPrimaryWINS, strSecondaryWINS);
let objVcCustomizationIPSettingsPassive: VcCustomizationIPSettings = this.VcCustomizationIPSettingsBuild(strIpAddressPassive, strSubnetMaskPassive, strDnsDomainName, arrDNSServers, arrGatewayPassive, strPrimaryWINS, strSecondaryWINS);
let objVcCustomizationIPSettingsWitness: VcCustomizationIPSettings = this.VcCustomizationIPSettingsBuild(strIpAddressWitness, strSubnetMaskWitness, strDnsDomainName, arrDNSServers, arrGatewayWitness, strPrimaryWINS, strSecondaryWINS);
let objVcClusterNetworkConfigSpec: VcClusterNetworkConfigSpec = new VcClusterNetworkConfigSpec();
objVcClusterNetworkConfigSpec.networkPortGroup = objVcDistributedVirtualPortgroup;
objVcClusterNetworkConfigSpec.ipSettings = objVcCustomizationIPSettingsActive;
let objVcServiceLocatorNamePassword: VcServiceLocatorNamePassword = new VcServiceLocatorNamePassword();
objVcServiceLocatorNamePassword.username = strUsername;
objVcServiceLocatorNamePassword.password = strPassword;
let objVcServiceLocator: VcServiceLocator = new VcServiceLocator();
objVcServiceLocator.credential = objVcServiceLocatorNamePassword;
objVcServiceLocator.instanceUuid = objVcSdkConnection.instanceUuid;
objVcServiceLocator.url = "https://" + objVcSdkConnection.sdkId;
objVcServiceLocator.sslThumbprint = strVCenterSSLThumbprint;
let objVcSourceNodeSpec: VcSourceNodeSpec = new VcSourceNodeSpec();
objVcSourceNodeSpec.activeVc = objVcVirtualMachine;
objVcSourceNodeSpec.managementVc = objVcServiceLocator;
let objVcPassiveNodeDeploymentSpec: VcPassiveNodeDeploymentSpec = new VcPassiveNodeDeploymentSpec();
objVcPassiveNodeDeploymentSpec.folder = objVcFolder;
objVcPassiveNodeDeploymentSpec.nodeName = objVcVirtualMachine.name + "-passive";
objVcPassiveNodeDeploymentSpec.ipSettings = objVcCustomizationIPSettingsPassive;
objVcPassiveNodeDeploymentSpec.datastore = objVcDatstorePassive;
let objVcNodeDeploymentSpecWitness: VcNodeDeploymentSpec = new VcNodeDeploymentSpec();
objVcNodeDeploymentSpecWitness.folder = objVcFolder;
objVcNodeDeploymentSpecWitness.nodeName = objVcVirtualMachine.name + "-witness";
objVcNodeDeploymentSpecWitness.ipSettings = objVcCustomizationIPSettingsWitness;
objVcNodeDeploymentSpecWitness.datastore = objVcDatstoreWitness;
let objVcVchaClusterDeploymentSpec: VcVchaClusterDeploymentSpec = new VcVchaClusterDeploymentSpec();
objVcVchaClusterDeploymentSpec.witnessDeploymentSpec = objVcNodeDeploymentSpecWitness;
objVcVchaClusterDeploymentSpec.passiveDeploymentSpec = objVcPassiveNodeDeploymentSpec;
objVcVchaClusterDeploymentSpec.activeVcNetworkConfig = objVcClusterNetworkConfigSpec;
objVcVchaClusterDeploymentSpec.activeVcSpec = objVcSourceNodeSpec;
this.objLogger.info("Starting deployment task...");
let objVcServiceContent: VcServiceContent = this.VcSdkConnectionGetVcServiceContent(objVcSdkConnection);
let objVcFailoverClusterConfigurator: VcFailoverClusterConfigurator = objVcServiceContent.failoverClusterConfigurator;
try {
let objVcTask: VcTask = objVcFailoverClusterConfigurator.deployVcha_Task(objVcVchaClusterDeploymentSpec);
this.WaitForVcTaskEnd(objVcTask, 2);
return true;
}
catch (objException) {
Utilities.logException(objException, this.objLogger, "VcSdkConnectionHAEnable");
return false;
}
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
