Function: vCenter Host System Firewall Ruleset Toggle

by Simon Sparks · 2 February 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: FirewallRulesetEnable

public FirewallRulesetEnable(objVcHostSystem: VcHostSystem, strRulesetName: string): boolean {

    let blnResult: boolean = this.FirewallRulesetToggle(objVcHostSystem, strRulesetName, "Enable");

    return blnResult;
}

Public Function: FirewallRulesetDisable

public FirewallRulesetDisable(objVcHostSystem: VcHostSystem, strRulesetName: string): boolean {

    let blnResult: boolean = this.FirewallRulesetToggle(objVcHostSystem, strRulesetName, "Disable");

    return blnResult;
}

Private Function: FirewallRulesetToggle

private FirewallRulesetToggle(objVcHostSystem: VcHostSystem, strRulesetName: string, strAction: "Enable" | "Disable"): boolean {

    try {
        let objVcHostConfigManager: VcHostConfigManager = objVcHostSystem.configManager;

        let objVcHostFirewallSystem: VcHostFirewallSystem = objVcHostConfigManager.firewallSystem;

        this.objLogger.info(`Attempting to ${strAction} Firewall Ruleset on vCenter Host: '${objVcHostSystem.name}'...`);

        if (strAction === "Enable") {
            objVcHostFirewallSystem.enableRuleset(strRulesetName);
        }
        else if (strAction === "Disable") {
            objVcHostFirewallSystem.disableRuleset(strRulesetName);
        }

        this.objLogger.info(`Succesfully ${strAction}d Firewall Ruleset on vCenter Host: '${objVcHostSystem.name}'. `);

        return true;
    }
    catch (objException) { 
        this.objLogger.info(`Failed to ${strAction} Firewall Ruleset on vCenter Host: '${objVcHostSystem.name}'. `);

        return false;
    }
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like