Skip to content

Commit c7d2abc

Browse files
Merge pull request #1475 from caberos/issue1472
add the firewall information on slcli firewall detail
2 parents 725e1ba + 39b3b2a commit c7d2abc

File tree

4 files changed

+61
-23
lines changed

4 files changed

+61
-23
lines changed

SoftLayer/CLI/firewall/detail.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,24 @@ def cli(env, identifier):
1919
mgr = SoftLayer.FirewallManager(env.client)
2020

2121
firewall_type, firewall_id = firewall.parse_id(identifier)
22+
_firewall = mgr.get_instance(firewall_id)
23+
24+
table = formatting.KeyValueTable(['name', 'value'])
25+
table.align['name'] = 'r'
26+
table.align['value'] = 'l'
27+
28+
table.add_row(['id', _firewall.get('id')])
29+
table.add_row(['primaryIpAddress', _firewall.get('primaryIpAddress')])
30+
table.add_row(['datacenter', utils.lookup(_firewall, 'datacenter', 'longName')])
31+
table.add_row(['networkVlan', utils.lookup(_firewall, 'networkVlan', 'name')])
32+
table.add_row(['networkVlaniD', utils.lookup(_firewall, 'networkVlan', 'id')])
33+
2234
if firewall_type == 'vlan':
2335
rules = mgr.get_dedicated_fwl_rules(firewall_id)
2436
else:
2537
rules = mgr.get_standard_fwl_rules(firewall_id)
26-
27-
env.fout(get_rules_table(rules))
38+
table.add_row(['rules', get_rules_table(rules)])
39+
env.fout(table)
2840

2941

3042
def get_rules_table(rules):

SoftLayer/fixtures/SoftLayer_Network_Vlan_Firewall.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
},
88
"id": 3130,
99
"primaryIpAddress": "192.155.239.146",
10+
"datacenter": {
11+
"id": 265592,
12+
"longName": "Amsterdam 1",
13+
"name": "ams01",
14+
"statusId": 2
15+
},
1016
"networkVlan": {
1117
"accountId": 307608,
1218
"id": 371028,
1319
"primarySubnetId": 536252,
20+
"name": 'testvlan',
1421
"vlanNumber": 1489,
1522
"firewallInterfaces": [
1623
{

SoftLayer/managers/firewall.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,15 @@ def edit_standard_fwl_rules(self, firewall_id, rules):
290290
template = {'networkComponentFirewallId': firewall_id, 'rules': rules}
291291

292292
return rule_svc.createObject(template)
293+
294+
def get_instance(self, firewall_id, mask=None):
295+
"""Get the firewall information
296+
297+
:param integer firewall_id: the instance ID of the standard firewall
298+
"""
299+
if not mask:
300+
mask = 'mask[datacenter,networkVlan]'
301+
302+
svc = self.client['Network_Vlan_Firewall']
303+
304+
return svc.getObject(id=firewall_id, mask=mask)

tests/CLI/modules/firewall_tests.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,35 @@ def test_add_server(self, confirm_mock):
5858
def test_detail(self):
5959
result = self.run_command(['firewall', 'detail', 'vlan:1234'])
6060
self.assert_no_fail(result)
61+
json_result = json.loads(result.output)
62+
self.assertEqual(json_result['rules'][0]['action'], 'permit')
6163
self.assertEqual(json.loads(result.output),
62-
[{'#': 1,
63-
'action': 'permit',
64-
'dest': 'any on server:80-80',
65-
'dest_mask': '255.255.255.255',
66-
'protocol': 'tcp',
67-
'src_ip': '0.0.0.0',
68-
'src_mask': '0.0.0.0'},
69-
{'#': 2,
70-
'action': 'permit',
71-
'dest': 'any on server:1-65535',
72-
'dest_mask': '255.255.255.255',
73-
'protocol': 'tmp',
74-
'src_ip': '193.212.1.10',
75-
'src_mask': '255.255.255.255'},
76-
{'#': 3,
77-
'action': 'permit',
78-
'dest': 'any on server:80-800',
79-
'dest_mask': '255.255.255.255',
80-
'protocol': 'tcp',
81-
'src_ip': '0.0.0.0',
82-
'src_mask': '0.0.0.0'}])
64+
{'datacenter': 'Amsterdam 1',
65+
'id': 3130,
66+
'networkVlan': 'testvlan',
67+
'networkVlaniD': 371028,
68+
'primaryIpAddress': '192.155.239.146',
69+
'rules': [{'#': 1,
70+
'action': 'permit',
71+
'dest': 'any on server:80-80',
72+
'dest_mask': '255.255.255.255',
73+
'protocol': 'tcp',
74+
'src_ip': '0.0.0.0',
75+
'src_mask': '0.0.0.0'},
76+
{'#': 2,
77+
'action': 'permit',
78+
'dest': 'any on server:1-65535',
79+
'dest_mask': '255.255.255.255',
80+
'protocol': 'tmp',
81+
'src_ip': '193.212.1.10',
82+
'src_mask': '255.255.255.255'},
83+
{'#': 3,
84+
'action': 'permit',
85+
'dest': 'any on server:80-800',
86+
'dest_mask': '255.255.255.255',
87+
'protocol': 'tcp',
88+
'src_ip': '0.0.0.0',
89+
'src_mask': '0.0.0.0'}]})
8390

8491
@mock.patch('SoftLayer.CLI.formatting.confirm')
8592
def test_cancel_firewall(self, confirm_mock):

0 commit comments

Comments
 (0)