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'
@@ -79,6 +88,21 @@ def cli(env, identifier, no_vs, no_hardware):
7988 else :
8089 table .add_row (['hardware' , 'none' ])
8190
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' , 'none' ])
105+
82106 env .fout (table )
83107
84108
@@ -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