Function: Add a Firewall Rule to an Edge

by Simon Sparks · 5 September 2025

To use this function add it to the class library file named vCloudService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: vCloudService.ts

Description: Orchestrator Function to Create a Firewall Rule on an Edge

Function VclFirewallRuleCreate

public VclFirewallRuleCreate(objVclGateway: VclGateway, blnVclFirewallRuleProtocolAny: boolean, blnVclFirewallRuleProtocolTcp: boolean, blnVclFirewallRuleProtocolUdp: boolean, blnVclFirewallRuleProtocolIcmp: boolean, strVclFirewallRuleProtocolOther: string, intPort: number, strPolicy: string, strDescription: string, strIcmpSubType: string, strDestinationPortRange: string, strDestinationIp: string, objVclVmSelectionDestination: VclVmSelection, intSourcePort: number, strSourcePortRange: string, strSourceIp: string, objVclVmSelectionSource: VclVmSelection, strDirection: string, blnMatchOnTranslate: boolean): void {
    objVclGateway.updateInternalState();

    let objVclFirewallRuleProtocols: VclFirewallRuleProtocols = new VclFirewallRuleProtocols();
    objVclFirewallRuleProtocols.any = blnVclFirewallRuleProtocolAny;
    objVclFirewallRuleProtocols.tcp = blnVclFirewallRuleProtocolTcp;
    objVclFirewallRuleProtocols.udp = blnVclFirewallRuleProtocolUdp;
    objVclFirewallRuleProtocols.icmp = blnVclFirewallRuleProtocolIcmp;
    objVclFirewallRuleProtocols.other = strVclFirewallRuleProtocolOther;

    let objVclFirewallRule: VclFirewallRule = new VclFirewallRule();
    objVclFirewallRule.isEnabled = true;
    objVclFirewallRule.enableLogging = false;
    objVclFirewallRule.port = intPort;
    objVclFirewallRule.policy = strPolicy;
    objVclFirewallRule.description = strDescription;
    objVclFirewallRule.protocols = objVclFirewallRuleProtocols;
    objVclFirewallRule.icmpSubType = strIcmpSubType;
    objVclFirewallRule.destinationPortRange = strDestinationPortRange;
    objVclFirewallRule.destinationIp = strDestinationIp;
    objVclFirewallRule.destinationVm = objVclVmSelectionDestination;
    objVclFirewallRule.sourcePort = intSourcePort;
    objVclFirewallRule.sourcePortRange = strSourcePortRange;
    objVclFirewallRule.sourceIp = strSourceIp;
    objVclFirewallRule.sourceVm = objVclVmSelectionSource;
    objVclFirewallRule.direction = strDirection;
    objVclFirewallRule.matchOnTranslate = blnMatchOnTranslate;

    let objVclGatewayConfiguration: VclGatewayConfiguration = objVclGateway.configuration;

    let objVclGatewayFeatures: VclGatewayFeatures = objVclGatewayConfiguration.edgeGatewayServiceConfiguration;

    let objVclAbstractObjectSet: VclAbstractObjectSet = objVclGatewayFeatures.networkService;

    let arrVclFirewallService: VclFirewallService[] = objVclAbstractObjectSet.find(new VclFirewallService());

    let objVclFirewallService: VclFirewallService = arrVclFirewallService[0];

    objVclFirewallService.firewallRule.add(objVclFirewallRule);

    let objVclTask: VclTask = objVclGateway.update();

    this.WaitForVclTask(objVclTask, 1);
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like