Repository: softlayer/softlayer-python
Pull request #1649 (2022-05-24 15:11:37)

update the firewall list
[#issue1643](https://github.com/softlayer/softlayer-python/issues/1643)

![image](https://user-images.githubusercontent.com/22535437/170070145-cedda059-ed73-4be5-a466-7b7624c235d5.png)



Patch:
diff --git a/SoftLayer/CLI/firewall/list.py b/SoftLayer/CLI/firewall/list.py
index ada678c7..f05dccc8 100644
--- a/SoftLayer/CLI/firewall/list.py
+++ b/SoftLayer/CLI/firewall/list.py
@@ -18,7 +18,7 @@ def cli(env):
     table = formatting.Table(['firewall id',
                               'type',
                               'features',
-                              'server/vlan id'])
+                              'server/vlan id'], title='Single Server Firewalls')
     fwvlans = mgr.get_firewalls()
     dedicated_firewalls = [firewall for firewall in fwvlans
                            if firewall['dedicatedFirewallFlag']]
@@ -70,7 +70,27 @@ def cli(env):
                              'hardwareId')
             ])
 
+    table_gatewalls = formatting.Table(['Id',
+                                        'firewall',
+                                        'type',
+                                        'Hostname',
+                                        'Location',
+                                        'Public Ip',
+                                        'Private Ip',
+                                        'Associated vlan',
+                                        'status'], title='Multi Vlan Firewall')
+    fw_gatewwalls = mgr.get_firewalls_gatewalls()
+
+    for gatewalls in fw_gatewwalls:
+        table_gatewalls.add_row([gatewalls['networkFirewall']['id'], gatewalls.get('name'),
+                                 gatewalls['networkFirewall']['firewallType'],
+                                 gatewalls['members'][0]['hardware']['hostname'],
+                                 gatewalls['networkFirewall']['datacenter']['name'],
+                                 gatewalls['publicIpAddress']['ipAddress'],
+                                 gatewalls['privateIpAddress']['ipAddress'],
+                                 len(gatewalls['insideVlans']), gatewalls['status']['keyName']])
     env.fout(table)
+    env.fout(table_gatewalls)
 
 
 def has_firewall_component(server):
diff --git a/SoftLayer/fixtures/SoftLayer_Account.py b/SoftLayer/fixtures/SoftLayer_Account.py
index 5eee8575..b7874496 100644
--- a/SoftLayer/fixtures/SoftLayer_Account.py
+++ b/SoftLayer/fixtures/SoftLayer_Account.py
@@ -1228,3 +1228,41 @@
     'projectedPublicBandwidthUsage': 9.88,
     'totalBandwidthAllocated': 3361
 }]
+
+getNetworkGateways = [{
+    'id': 615448,
+    'name': 'testFirewall-cgallo',
+    'networkSpace': 'BOTH',
+    'insideVlans': [],
+    'members': [
+        {
+            'id': 687820,
+            'hardware': {
+                'hostname': 'dft03.pod03.dal13'
+            }
+        }
+    ],
+    'networkFirewall': {
+        'id': 17438,
+        'datacenter': {
+            'name': 'dal13'
+        },
+        'firewallType': 'fortigate-security-appliance-10gb',
+        'rules': []
+    },
+    'privateIpAddress': {
+        'ipAddress': '10.37.115.70'
+    },
+    'publicIpAddress': {
+        'ipAddress': '67.228.206.245'
+    },
+    'publicVlan': {
+        'id': 3228726,
+        'primaryRouter': {
+            'hostname': 'fcr03a.dal13'
+        }
+    },
+    'status': {
+        'keyName': 'ACTIVE'
+    }
+}]
diff --git a/SoftLayer/managers/firewall.py b/SoftLayer/managers/firewall.py
index 44eef25a..c1ae1da4 100644
--- a/SoftLayer/managers/firewall.py
+++ b/SoftLayer/managers/firewall.py
@@ -302,3 +302,19 @@ def get_instance(self, firewall_id, mask=None):
         svc = self.client['Network_Vlan_Firewall']
 
         return svc.getObject(id=firewall_id, mask=mask)
+
+    def get_firewalls_gatewalls(self):
+        """Returns a list of all gateway firewalls (gatewalls) on the account.
+
+        returns: A list of gateway firewalls (gatewalls) on the current account.
+        """
+        mask = 'mask[id,networkSpace,name,' \
+               'networkFirewall[id,firewallType,datacenter[name]],' \
+               'status[keyName],' \
+               'insideVlans[id],' \
+               'privateIpAddress[ipAddress],' \
+               'publicVlan[id,primaryRouter[hostname]],' \
+               'publicIpAddress[ipAddress],members[id,hardware[hostname]]]'
+        _filter = {"networkGateways": {"networkFirewall": {"operation": "not null"}}}
+
+        return self.account.getNetworkGateways(mask=mask, filter=_filter)


Test patch:
diff --git a/tests/CLI/modules/firewall_tests.py b/tests/CLI/modules/firewall_tests.py
index f248b16f..2fde3855 100644
--- a/tests/CLI/modules/firewall_tests.py
+++ b/tests/CLI/modules/firewall_tests.py
@@ -16,23 +16,7 @@ def test_list_firewalls(self):
         result = self.run_command(['firewall', 'list'])
 
         self.assert_no_fail(result)
-        self.assertEqual(json.loads(result.output),
-                         [{'features': ['HA'],
-                           'firewall id': 'vlan:1234',
-                           'server/vlan id': 1,
-                           'type': 'VLAN - dedicated'},
-                          {'features': ['HA'],
-                           'firewall id': 'vlan:23456',
-                           'server/vlan id': 3,
-                           'type': 'VLAN - dedicated'},
-                          {'features': '-',
-                           'firewall id': 'vs:1234',
-                           'server/vlan id': 1,
-                           'type': 'Virtual Server - standard'},
-                          {'features': '-',
-                           'firewall id': 'server:1234',
-                           'server/vlan id': 1,
-                           'type': 'Server - standard'}])
+        self.assert_called_with('SoftLayer_Account', 'getNetworkGateways')
 
     @mock.patch('SoftLayer.CLI.formatting.confirm')
     def test_add_vs(self, confirm_mock):
diff --git a/tests/managers/firewall_tests.py b/tests/managers/firewall_tests.py
index c114a63d..783d7cbe 100644
--- a/tests/managers/firewall_tests.py
+++ b/tests/managers/firewall_tests.py
@@ -322,3 +322,7 @@ def test_edit_standard_fwl_rules(self):
         self.assert_called_with('SoftLayer_Network_Firewall_Update_Request',
                                 'createObject',
                                 args=args)
+
+    def test_get_gateways(self):
+        self.firewall.get_firewalls_gatewalls()
+        self.assert_called_with('SoftLayer_Account', 'getNetworkGateways')