Function: vCenter Host System Firewall Ruleset Allowed IPs Toggle

by Simon Sparks · 23 March 2026

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;
}
TypeScript

Public Function: FirewallRulesetAllowedIPsDisable

publicFirewallRulesetAllowedIPsDisable(objVcHostSystem:VcHostSystem,strRulesetName:string):boolean{

letblnReturn:boolean=this.FirewallRulesetAllowedIPsToggle(objVcHostSystem,strRulesetName, []);

returnblnReturn;
}
TypeScript

Private 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;
}
}
TypeScript

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like