0
votes

I've been trying for several days to get the API Service {'Network_Firewall_Update_Request_Rule'].createObject working without success. I did get the firewallManager edit_dedicated_fwl_rules working but now want the Service to work too. I've looked throughout the web for an answer and could not find one.

My question is what is the syntax of the arguments to pass to the Service createObject for the Firewall Rules? Do you have an example?

The command being used is:

client = SoftLayer.create_client_from_env(username=user, api_key=api)
client['Network_Firewall_Update_Request_Rule'].createObject(id=12345, [{'action': 'permit'}])

yes, I know I need more rule statements for a create. This returns "SyntaxError: non-keyword arg after keyword arg" because of the "id=".

Putting the "id=" at the end of the API: client['Network_Firewall_Update_Request_Rule'].createObject([{'action': 'permit'}], id=12345) then the error is "Either a component ID or an ACL ID must be supplied."

If I remove the "id=" and only have client['Network_Firewall_Update_Request_Rule'].createObject(12345, [{'action': 'permit'}])

then the error is "Either a component ID or an ACL ID must be supplied."

I know I must have the "id=" as this command works:

client['Network_Firewall_Update_Request'].getRules(id=12345)

But with the Manager API command fw.edit_dedicated_fwl_rules(12345, [{'action': 'permit'}])

there is no "id=" as this creates the rule successfully.

Thanks for any help.

1

1 Answers

0
votes

check this post:

I need to create a softlayer network firewall rule through REST API

Well a REST example to create a rule is like this:

POST https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Network_Firewall_Update_Request/createObjec

Payload:

{
  "parameters": [
    {
      "networkComponentFirewallId": 72605,
      "rules": [
        {
          "action": "permit",
          "destinationIpAddress": "159.8.52.188",
          "destinationIpCidr": 32,
          "destinationPortRangeEnd": 122,
          "destinationPortRangeStart": 12,
          "notes": "This is a test",
          "orderValue": 1,
          "protocol": "tcp",
          "sourceIpAddress": "10.10.10.0",
          "sourceIpCidr": 32,
          "version": 4
        }
      ]
    }
  ]
}

You need to replace all the value according the configuration that you need.

Now you need to get the "networkComponentFirewallId" for the request above, that can be get like this:

GET https://$USERID:[email protected]/rest/v3/SoftLayer_Virtual_Guest/$VSIID/getFirewallServiceComponent

Using Python the example above will be something like this:

client['Network_Firewall_Update_Request_Rule'].createObject(
 {
          "networkComponentFirewallId": 72605,
          "rules": [
            {
              "action": "permit",
              "destinationIpAddress": "159.8.52.188",
              "destinationIpCidr": 32,
              "destinationPortRangeEnd": 122,
              "destinationPortRangeStart": 12,
              "notes": "This is a test",
              "orderValue": 1,
              "protocol": "tcp",
              "sourceIpAddress": "10.10.10.0",
              "sourceIpCidr": 32,
              "version": 4
            }
          ]
        }
)

and to get the "networkComponentFirewallId" property:

client['Virtual_Guest'].getFirewallServiceComponent(id=VirtualGuest)

Note that the examples above are to edit the rules of a firewall attached to a VSI.

In order to create a rule for a dedicated firewal in a VLAN this is the request:

client['Network_Firewall_Update_Request_Rule'].createObject(
{
    "firewallContextAccessControlListId": 3092,
    "rules": [{
        "action": "permit",
        "destinationIpAddress": "any",
        "destinationIpCidr": 32,
        "destinationIpSubnetMask": "255.255.255.255",
        "destinationPortRangeEnd": 65535,
        "destinationPortRangeStart": 1,
        "id": 5669281,
        "orderValue": 1,
        "protocol": "tcp",
        "sourceIpAddress": "0.0.0.0",
        "sourceIpCidr": 0,
        "sourceIpSubnetMask": "0.0.0.0",
        "status": "allow_edit",
        "version": 4
    }]
}
)

Now how to get the value for "firewallContextAccessControlListId", you need to use this:

client['SoftLayer_Network_Vlan'].getFirewallInterfaces(id=vlanId, mask="mask[firewallContextAccessControlLists]")

The method above will return the interfaces outside and inside, currenlty only you can set the rules for the outsitde inteface

Regards