12
12
13
13
@click .command (cls = SoftLayer .CLI .command .SLCommand , )
14
14
@click .argument ('identifier' )
15
- @click .option ('--no-vs' ,
16
- is_flag = True ,
15
+ @click .option ('--no-vs' , is_flag = True ,
17
16
help = "Hide virtual server listing" )
18
- @click .option ('--no-hardware' ,
19
- is_flag = True ,
17
+ @click .option ('--no-hardware' , is_flag = True ,
20
18
help = "Hide hardware listing" )
21
- @click .option ('--no-trunks' ,
22
- is_flag = True ,
19
+ @click .option ('--no-trunks' , is_flag = True ,
23
20
help = "Hide devices with trunks" )
24
21
@environment .pass_env
25
22
def cli (env , identifier , no_vs , no_hardware , no_trunks ):
@@ -28,11 +25,24 @@ def cli(env, identifier, no_vs, no_hardware, no_trunks):
28
25
29
26
vlan_id = helpers .resolve_id (mgr .resolve_vlan_ids , identifier , 'VLAN' )
30
27
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]]]]]"""
28
+ mask = """mask[
29
+ firewallInterfaces, primaryRouter[id, fullyQualifiedDomainName, datacenter[longName]],
30
+ totalPrimaryIpAddressCount,
31
+ networkSpace, id, vlanNumber, fullyQualifiedName, name,
32
+ hardware[id, hostname, domain, primaryIpAddress, primaryBackendIpAddress, tagReferences],
33
+ subnets[id, networkIdentifier, netmask, gateway, subnetType, usableIpAddressCount],
34
+ virtualGuests[id, hostname, domain, primaryIpAddress, primaryBackendIpAddress],
35
+ networkVlanFirewall[id,fullyQualifiedDomainName,primaryIpAddress],
36
+ attachedNetworkGateway[id,name,networkFirewall],
37
+ networkComponentTrunks[
38
+ networkComponent[
39
+ downlinkComponent[
40
+ networkComponentGroup[membersDescription],
41
+ hardware[tagReferences]
42
+ ]
43
+ ]
44
+ ]
45
+ ]"""
36
46
37
47
vlan = mgr .get_vlan (vlan_id , mask = mask )
38
48
@@ -42,10 +52,8 @@ def cli(env, identifier, no_vs, no_hardware, no_trunks):
42
52
43
53
table .add_row (['id' , vlan .get ('id' )])
44
54
table .add_row (['number' , vlan .get ('vlanNumber' )])
45
- table .add_row (['datacenter' ,
46
- utils .lookup (vlan , 'primaryRouter' , 'datacenter' , 'longName' )])
47
- table .add_row (['primary_router' ,
48
- utils .lookup (vlan , 'primaryRouter' , 'fullyQualifiedDomainName' )])
55
+ table .add_row (['datacenter' , utils .lookup (vlan , 'primaryRouter' , 'datacenter' , 'longName' )])
56
+ table .add_row (['primary_router' , utils .lookup (vlan , 'primaryRouter' , 'fullyQualifiedDomainName' )])
49
57
table .add_row (['Gateway/Firewall' , get_gateway_firewall (vlan )])
50
58
51
59
if vlan .get ('subnets' ):
@@ -93,19 +101,25 @@ def cli(env, identifier, no_vs, no_hardware, no_trunks):
93
101
trunks = filter_trunks (vlan .get ('networkComponentTrunks' ))
94
102
trunks_table = formatting .Table (['device' , 'port' , 'tags' ])
95
103
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' ))])
104
+ trunks_table .add_row (get_trunk_row (trunk ))
102
105
table .add_row (['trunks' , trunks_table ])
103
106
else :
104
107
table .add_row (['trunks' , '-' ])
105
108
106
109
env .fout (table )
107
110
108
111
112
+ def get_trunk_row (trunk : dict ) -> list :
113
+ """Parses a vlan trunk and returns a table row for it"""
114
+ dl_component = utils .lookup (trunk , 'networkComponent' , 'downlinkComponent' )
115
+ row = [
116
+ utils .lookup (dl_component , 'hardware' , 'fullyQualifiedDomainName' ),
117
+ utils .lookup (dl_component , 'networkComponentGroup' , 'membersDescription' ),
118
+ formatting .tags (utils .lookup (dl_component , 'hardware' , 'tagReferences' ))
119
+ ]
120
+ return row
121
+
122
+
109
123
def get_gateway_firewall (vlan ):
110
124
"""Gets the name of a gateway/firewall from a VLAN. """
111
125
0 commit comments