Skip to content

Commit 78585f3

Browse files
Merge pull request #1721 from softlayer/issue1718
Add Devices with Trunks to vlan detail
2 parents ed803f6 + f511ff3 commit 78585f3

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

SoftLayer/CLI/vlan/detail.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,23 @@
1818
@click.option('--no-hardware',
1919
is_flag=True,
2020
help="Hide hardware listing")
21+
@click.option('--no-trunks',
22+
is_flag=True,
23+
help="Hide devices with trunks")
2124
@environment.pass_env
22-
def cli(env, identifier, no_vs, no_hardware):
25+
def cli(env, identifier, no_vs, no_hardware, no_trunks):
2326
"""Get details about a VLAN."""
24-
2527
mgr = SoftLayer.NetworkManager(env.client)
2628

2729
vlan_id = helpers.resolve_id(mgr.resolve_vlan_ids, identifier, 'VLAN')
28-
vlan = mgr.get_vlan(vlan_id)
30+
31+
mask = """mask[firewallInterfaces,primaryRouter[id, fullyQualifiedDomainName, datacenter],
32+
totalPrimaryIpAddressCount,networkSpace,billingItem,hardware,subnets,virtualGuests,
33+
networkVlanFirewall[id,fullyQualifiedDomainName,primaryIpAddress],attachedNetworkGateway[id,name,networkFirewall],
34+
networkComponentTrunks[networkComponent[downlinkComponent[networkComponentGroup[membersDescription],
35+
hardware[tagReferences]]]]]"""
36+
37+
vlan = mgr.get_vlan(vlan_id, mask=mask)
2938

3039
table = formatting.KeyValueTable(['name', 'value'])
3140
table.align['name'] = 'r'
@@ -51,7 +60,7 @@ def cli(env, identifier, no_vs, no_hardware):
5160
# subnets.append(subnet_table)
5261
table.add_row(['subnets', subnet_table])
5362
else:
54-
table.add_row(['subnets', 'none'])
63+
table.add_row(['subnets', '-'])
5564

5665
server_columns = ['hostname', 'domain', 'public_ip', 'private_ip']
5766

@@ -65,7 +74,7 @@ def cli(env, identifier, no_vs, no_hardware):
6574
vsi.get('primaryBackendIpAddress')])
6675
table.add_row(['vs', vs_table])
6776
else:
68-
table.add_row(['vs', 'none'])
77+
table.add_row(['vs', '-'])
6978

7079
if not no_hardware:
7180
if vlan.get('hardware'):
@@ -77,7 +86,22 @@ def cli(env, identifier, no_vs, no_hardware):
7786
hardware.get('primaryBackendIpAddress')])
7887
table.add_row(['hardware', hw_table])
7988
else:
80-
table.add_row(['hardware', 'none'])
89+
table.add_row(['hardware', '-'])
90+
91+
if not no_trunks:
92+
if vlan.get('networkComponentTrunks'):
93+
trunks = filter_trunks(vlan.get('networkComponentTrunks'))
94+
trunks_table = formatting.Table(['device', 'port', 'tags'])
95+
for trunk in trunks:
96+
trunks_table.add_row([utils.lookup(trunk, 'networkComponent', 'downlinkComponent',
97+
'hardware', 'fullyQualifiedDomainName'),
98+
utils.lookup(trunk, 'networkComponent', 'downlinkComponent',
99+
'networkComponentGroup', 'membersDescription'),
100+
formatting.tags(utils.lookup(trunk, 'networkComponent', 'downlinkComponent',
101+
'hardware', 'tagReferences'))])
102+
table.add_row(['trunks', trunks_table])
103+
else:
104+
table.add_row(['trunks', '-'])
81105

82106
env.fout(table)
83107

@@ -92,3 +116,14 @@ def get_gateway_firewall(vlan):
92116
if gateway:
93117
return gateway
94118
return formatting.blank()
119+
120+
121+
def filter_trunks(trunks):
122+
"""Filter duplicates devices with trunks of the vlan."""
123+
trunk_filters = []
124+
hardware_id = []
125+
for trunk in trunks:
126+
if utils.lookup(trunk, 'networkComponent', 'downlinkComponent', 'hardwareId') not in hardware_id:
127+
trunk_filters.append(trunk)
128+
hardware_id.append(utils.lookup(trunk, 'networkComponent', 'downlinkComponent', 'hardwareId'))
129+
return trunk_filters

SoftLayer/managers/network.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,21 @@ def get_subnet(self, subnet_id, **kwargs):
429429

430430
return self.subnet.getObject(id=subnet_id, **kwargs)
431431

432-
def get_vlan(self, vlan_id):
432+
def get_vlan(self, vlan_id, mask=None):
433433
"""Returns information about a single VLAN.
434434
435-
:param int id: The unique identifier for the VLAN
435+
:param int vlan_id: The unique identifier for the VLAN
436+
:param string mask: mask for request
436437
:returns: A dictionary containing a large amount of information about
437438
the specified VLAN.
438-
439439
"""
440-
return self.vlan.getObject(id=vlan_id, mask=DEFAULT_GET_VLAN_MASK)
440+
441+
if mask:
442+
_mask = mask
443+
else:
444+
_mask = DEFAULT_GET_VLAN_MASK
445+
446+
return self.vlan.getObject(id=vlan_id, mask=_mask)
441447

442448
def list_global_ips(self, version=None, identifier=None, **kwargs):
443449
"""Returns a list of all global IP address records on the account.

0 commit comments

Comments
 (0)