Skip to content

Commit a844e1c

Browse files
Merge pull request #1498 from ATGE/issues/1480
Add gateway/firewall name to vlan detail and list command
2 parents 275fc96 + 6372aa2 commit a844e1c

File tree

4 files changed

+72
-20
lines changed

4 files changed

+72
-20
lines changed

SoftLayer/CLI/vlan/detail.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from SoftLayer.CLI import environment
88
from SoftLayer.CLI import formatting
99
from SoftLayer.CLI import helpers
10+
from SoftLayer import utils
1011

1112

1213
@click.command()
@@ -30,26 +31,24 @@ def cli(env, identifier, no_vs, no_hardware):
3031
table.align['name'] = 'r'
3132
table.align['value'] = 'l'
3233

33-
table.add_row(['id', vlan['id']])
34-
table.add_row(['number', vlan['vlanNumber']])
34+
table.add_row(['id', vlan.get('id')])
35+
table.add_row(['number', vlan.get('vlanNumber')])
3536
table.add_row(['datacenter',
36-
vlan['primaryRouter']['datacenter']['longName']])
37+
utils.lookup(vlan, 'primaryRouter', 'datacenter', 'longName')])
3738
table.add_row(['primary_router',
38-
vlan['primaryRouter']['fullyQualifiedDomainName']])
39-
table.add_row(['firewall',
40-
'Yes' if vlan['firewallInterfaces'] else 'No'])
39+
utils.lookup(vlan, 'primaryRouter', 'fullyQualifiedDomainName')])
40+
table.add_row(['Gateway/Firewall', get_gateway_firewall(vlan)])
4141
subnets = []
4242
for subnet in vlan.get('subnets', []):
4343
subnet_table = formatting.KeyValueTable(['name', 'value'])
4444
subnet_table.align['name'] = 'r'
4545
subnet_table.align['value'] = 'l'
46-
subnet_table.add_row(['id', subnet['id']])
47-
subnet_table.add_row(['identifier', subnet['networkIdentifier']])
48-
subnet_table.add_row(['netmask', subnet['netmask']])
49-
subnet_table.add_row(['gateway', subnet.get('gateway', '-')])
50-
subnet_table.add_row(['type', subnet['subnetType']])
51-
subnet_table.add_row(['usable ips',
52-
subnet['usableIpAddressCount']])
46+
subnet_table.add_row(['id', subnet.get('id')])
47+
subnet_table.add_row(['identifier', subnet.get('networkIdentifier')])
48+
subnet_table.add_row(['netmask', subnet.get('netmask')])
49+
subnet_table.add_row(['gateway', subnet.get('gateway', formatting.blank())])
50+
subnet_table.add_row(['type', subnet.get('subnetType')])
51+
subnet_table.add_row(['usable ips', subnet.get('usableIpAddressCount')])
5352
subnets.append(subnet_table)
5453

5554
table.add_row(['subnets', subnets])
@@ -81,3 +80,15 @@ def cli(env, identifier, no_vs, no_hardware):
8180
table.add_row(['hardware', 'none'])
8281

8382
env.fout(table)
83+
84+
85+
def get_gateway_firewall(vlan):
86+
"""Gets the name of a gateway/firewall from a VLAN. """
87+
88+
firewall = utils.lookup(vlan, 'networkVlanFirewall', 'fullyQualifiedDomainName')
89+
if firewall:
90+
return firewall
91+
gateway = utils.lookup(vlan, 'attachedNetworkGateway', 'name')
92+
if gateway:
93+
return gateway
94+
return formatting.blank()

SoftLayer/CLI/vlan/list.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import SoftLayer
77
from SoftLayer.CLI import environment
88
from SoftLayer.CLI import formatting
9+
from SoftLayer.CLI.vlan.detail import get_gateway_firewall
910
from SoftLayer import utils
1011

1112
COLUMNS = ['id',
1213
'number',
1314
'name',
14-
'firewall',
15+
'Gateway/Firewall',
1516
'datacenter',
1617
'hardware',
1718
'virtual_servers',
@@ -45,14 +46,14 @@ def cli(env, sortby, datacenter, number, name, limit):
4546
limit=limit)
4647
for vlan in vlans:
4748
table.add_row([
48-
vlan['id'],
49-
vlan['vlanNumber'],
49+
vlan.get('id'),
50+
vlan.get('vlanNumber'),
5051
vlan.get('name') or formatting.blank(),
51-
'Yes' if vlan['firewallInterfaces'] else 'No',
52+
get_gateway_firewall(vlan),
5253
utils.lookup(vlan, 'primaryRouter', 'datacenter', 'name'),
53-
vlan['hardwareCount'],
54-
vlan['virtualGuestCount'],
55-
vlan['totalPrimaryIpAddressCount'],
54+
vlan.get('hardwareCount'),
55+
vlan.get('virtualGuestCount'),
56+
vlan.get('totalPrimaryIpAddressCount'),
5657
])
5758

5859
env.fout(table)

SoftLayer/managers/network.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
'totalPrimaryIpAddressCount',
4444
'virtualGuestCount',
4545
'networkSpace',
46+
'networkVlanFirewall[id,fullyQualifiedDomainName,primaryIpAddress]',
47+
'attachedNetworkGateway[id,name,networkFirewall]',
4648
])
4749
DEFAULT_GET_VLAN_MASK = ','.join([
4850
'firewallInterfaces',
@@ -53,6 +55,8 @@
5355
'hardware',
5456
'subnets',
5557
'virtualGuests',
58+
'networkVlanFirewall[id,fullyQualifiedDomainName,primaryIpAddress]',
59+
'attachedNetworkGateway[id,name,networkFirewall]',
5660
])
5761

5862

tests/CLI/modules/vlan_tests.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,42 @@ def test_vlan_edit_failure(self, click):
9595
self.assert_no_fail(result)
9696
self.assert_called_with('SoftLayer_Network_Vlan', 'editObject', identifier=100)
9797

98+
def test_vlan_detail_firewall(self):
99+
vlan_mock = self.set_mock('SoftLayer_Network_Vlan', 'getObject')
100+
get_object = {
101+
'primaryRouter': {
102+
'datacenter': {'id': 1234, 'longName': 'TestDC'},
103+
'fullyQualifiedDomainName': 'fcr01.TestDC'
104+
},
105+
'id': 1234,
106+
'vlanNumber': 4444,
107+
'networkVlanFirewall': {
108+
'datacenter': {'id': 1234, 'longName': 'TestDC'},
109+
'fullyQualifiedDomainName': 'fcr01.TestDC'
110+
},
111+
}
112+
vlan_mock.return_value = get_object
113+
result = self.run_command(['vlan', 'detail', '1234'])
114+
self.assert_no_fail(result)
115+
116+
def test_vlan_detail_gateway(self):
117+
vlan_mock = self.set_mock('SoftLayer_Network_Vlan', 'getObject')
118+
get_object = {
119+
'primaryRouter': {
120+
'datacenter': {'id': 1234, 'longName': 'TestDC'},
121+
'fullyQualifiedDomainName': 'fcr01.TestDC'
122+
},
123+
'id': 1234,
124+
'vlanNumber': 4444,
125+
'attachedNetworkGateway': {
126+
'id': 54321,
127+
"name": 'support'
128+
},
129+
}
130+
vlan_mock.return_value = get_object
131+
result = self.run_command(['vlan', 'detail', '1234'])
132+
self.assert_no_fail(result)
133+
98134
def test_vlan_list(self):
99135
result = self.run_command(['vlan', 'list'])
100136
self.assert_no_fail(result)

0 commit comments

Comments
 (0)