VMware Cloud Community
MakeItWork
Enthusiast
Enthusiast

How to get a list of vCloud vCNS rules

Good afternoon,

I'm trying to build a workflow to grab a list of FW rules on an Edge device using the vCloud vCO plug in.

I can get the edge name (using some examples from the load balancer package), but can't figure out how to extend that to grab this list of rules.

Here is the code I have so far.

// var vApp input parameter

var objVclOrgVdcNetwork = arrOrgVdcNetworks[0];

//System.log("Org vDC Network Name: " + objVclOrgVdcNetwork.name);

var arrOrgVdcGateway = objVclAdminVdc.getGateways();

// Assumes that there is only 1 Gateway per Org vDC

gateway = arrOrgVdcGateway[0];

gateway.updateInternalState();

var vcdHost = gateway.getHost();

System.log("vCloud Host: "+ vcdHost.url);

System.log("Edge Gateway : " + gateway.name);


It's probably easy, but I'm not a programmer by trade.

Thank you

Visit us at http://www.cloudnutz.com and twitter @cloudnutz
0 Kudos
1 Reply
MakeItWork
Enthusiast
Enthusiast

Not the prettiest code in the world, but it works.

// var vApp from input

// Need to retrieve Gateway object for the vApp

var objVclAdminVdc = vApp.parent.toAdminObject();

//System.log("Org vDC Name: " + objVclAdminVdc.name);

var arrOrgVdcNetworks = objVclAdminVdc.getOrgVdcNetworks();

// Assumes that there is only 1 Org vDC network

var objVclOrgVdcNetwork = arrOrgVdcNetworks[0];

//System.log("Org vDC Network Name: " + objVclOrgVdcNetwork.name);

var arrOrgVdcGateway = objVclAdminVdc.getGateways();

// Assumes that there is only 1 Gateway per Org vDC

gateway = arrOrgVdcGateway[0];

gateway.updateInternalState();

// var vcdHost = gateway.getHost();

// System.log("vCloud Host: "+vcdHost.url);

System.log("Edge Gateway NAME: " + gateway.name);

// Get gateway configuration

var gatewayConfiguration = gateway.configuration;

if (gatewayConfiguration.edgeGatewayServiceConfiguration == null) {

    gatewayConfiguration.edgeGatewayServiceConfiguration = new VclGatewayFeatures();

}

var serviceSet = gatewayConfiguration.edgeGatewayServiceConfiguration.networkService;

// Only interested in FW service

var services = serviceSet.find(new VclFirewallService());

if (services.length == 0) {

    throw 'Firewall service not found on gateway: ' + gateway.name;

}

System.log("Default Action is " + services[0].defaultAction);

// Enumerate the rule list

var arrRulesFW = (services[0].firewallRule);

// System.log("Number of rules " + arrRulesFW.size());

var ruleList = arrRulesFW.enumerate();

var ruleCount = 1;

for each (var rules in ruleList) {

    var str1 = "Rule number " + ruleCount + "\t";

    str1 += "Descr:  " + rules.description + "\t";

    str1 += "Dest IP: " + rules.destinationIp + "\t";

    str1 += "Dest Range: " +rules.destinationPortRange + "\t";

    str1 += "Logging: " + rules.enableLogging + "\t";

    str1 += "Enabled:  " +rules.isEnabled + "\t";

    str1 += "Policy: " + rules.policy + "\t";

    str1 += "Source IP: " +rules.sourceIp + "\t";

    str1 += "Source Port: " + rules.sourcePort + "\t";

    ruleCount += 1;

    System.log(str1);

};

Visit us at http://www.cloudnutz.com and twitter @cloudnutz
0 Kudos