To use this function add it to the class library file named PluginVCHostSystemService.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: PluginVCHostSystemService.ts
Public Function: FirewallRulesetAllowedIPsEnable
publicFirewallRulesetAllowedIPsEnable(objVcHostSystem:VcHostSystem,strRulesetName:string,arrAllowedIPs:string[]):boolean{
letblnReturn:boolean=this.FirewallRulesetAllowedIPsToggle(objVcHostSystem,strRulesetName,arrAllowedIPs);
returnblnReturn;
}TypeScriptPublic Function: FirewallRulesetAllowedIPsDisable
publicFirewallRulesetAllowedIPsDisable(objVcHostSystem:VcHostSystem,strRulesetName:string):boolean{
letblnReturn:boolean=this.FirewallRulesetAllowedIPsToggle(objVcHostSystem,strRulesetName, []);
returnblnReturn;
}TypeScriptPrivate Function: FirewallRulesetAllowedIPsToggle
privateFirewallRulesetAllowedIPsToggle(objVcHostSystem:VcHostSystem,strRulesetName:string,arrAllowedIPs:string[]):boolean{
try{
letobjVcHostConfigManager:VcHostConfigManager=objVcHostSystem.configManager;
letobjVcHostFirewallSystem:VcHostFirewallSystem=objVcHostConfigManager.firewallSystem;
this.objLogger.info(`Attempting to Set Allowed IPs to${JSON.stringify(arrAllowedIPs)} on Firewall Ruleset '${strRulesetName}' on vCenter Host: '${objVcHostSystem.name}'...`);
letobjVcHostFirewallRulesetIpList:VcHostFirewallRulesetIpList=newVcHostFirewallRulesetIpList();
objVcHostFirewallRulesetIpList.allIp=true;
if (arrAllowedIPs===null||arrAllowedIPs.length===0){
objVcHostFirewallRulesetIpList.ipAddress= [];
}
elseif (arrAllowedIPs.length>0){
objVcHostFirewallRulesetIpList.ipAddress=arrAllowedIPs;
}
letobjVcHostFirewallRulesetRulesetSpec:VcHostFirewallRulesetRulesetSpec=newVcHostFirewallRulesetRulesetSpec();
objVcHostFirewallRulesetRulesetSpec.allowedHosts=objVcHostFirewallRulesetIpList;
objVcHostFirewallSystem.updateRuleset(strRulesetName,objVcHostFirewallRulesetRulesetSpec)
this.objLogger.info(`Succesfully Set Allowed IPs to${JSON.stringify(arrAllowedIPs)} on Firewall Ruleset '${strRulesetName}' on vCenter Host: '${objVcHostSystem.name}'...`);
returntrue;
}
catch (objException){
this.objLogger.info(`Failed to Set Allowed IPs to${JSON.stringify(arrAllowedIPs)} on Firewall Ruleset '${strRulesetName}' on vCenter Host: '${objVcHostSystem.name}'...`);
returnfalse;
}
}TypeScriptDiscover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
