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
0 commit comments