Skip to content

Commit f06731f

Browse files
author
Nathan Beittenmiller
committed
Merge pull request softlayer#246 from sudorandom/issue-244
Adds VLAN name filter
2 parents 086889d + 12206b1 commit f06731f

5 files changed

Lines changed: 158 additions & 143 deletions

File tree

SoftLayer/CLI/modules/globalip.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from SoftLayer import NetworkManager
1717
from SoftLayer.CLI import (
18-
CLIRunnable, Table, FormattedItem, confirm, no_going_back)
18+
CLIRunnable, Table, FormattedItem, confirm, no_going_back, resolve_id)
1919
from SoftLayer.CLI.helpers import CLIAbort, SequentialOutput
2020

2121

@@ -33,8 +33,9 @@ class GlobalIpAssign(CLIRunnable):
3333

3434
def execute(self, args):
3535
mgr = NetworkManager(self.client)
36-
37-
global_ip_id = mgr.resolve_global_ip_ids(args.get('<identifier>'))
36+
global_ip_id = resolve_id(mgr.resolve_global_ip_ids,
37+
args.get('<identifier>'),
38+
name='global ip')
3839
if not global_ip_id:
3940
raise CLIAbort("Unable to find global IP record for " +
4041
args['<identifier>'])
@@ -53,7 +54,9 @@ class GlobalIpCancel(CLIRunnable):
5354

5455
def execute(self, args):
5556
mgr = NetworkManager(self.client)
56-
global_ip_id = mgr.resolve_global_ip_ids(args.get('<identifier>'))
57+
global_ip_id = resolve_id(mgr.resolve_global_ip_ids,
58+
args.get('<identifier>'),
59+
name='global ip')
5760

5861
if args['--really'] or no_going_back(global_ip_id):
5962
mgr.cancel_global_ip(global_ip_id)
@@ -172,8 +175,9 @@ class GlobalIpUnassign(CLIRunnable):
172175

173176
def execute(self, args):
174177
mgr = NetworkManager(self.client)
175-
176-
global_ip_id = mgr.resolve_global_ip_ids(args.get('<identifier>'))
178+
global_ip_id = resolve_id(mgr.resolve_global_ip_ids,
179+
args.get('<identifier>'),
180+
name='global ip')
177181
if not global_ip_id:
178182
raise CLIAbort("Unable to find global IP record for " +
179183
args['<identifier>'])

SoftLayer/CLI/modules/subnet.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
from SoftLayer import NetworkManager
1717
from SoftLayer.CLI import (
18-
CLIRunnable, Table, KeyValueTable, FormattedItem, confirm, no_going_back)
18+
CLIRunnable, Table, KeyValueTable, FormattedItem, confirm, no_going_back,
19+
resolve_id)
1920
from SoftLayer.CLI.helpers import CLIAbort, SequentialOutput
2021

2122

@@ -31,7 +32,9 @@ class SubnetCancel(CLIRunnable):
3132

3233
def execute(self, args):
3334
mgr = NetworkManager(self.client)
34-
subnet_id = mgr.resolve_subnet_ids(args.get('<identifier>'))
35+
subnet_id = resolve_id(mgr.resolve_subnet_ids,
36+
args.get('<identifier>'),
37+
name='subnet')
3538

3639
if args['--really'] or no_going_back(subnet_id):
3740
mgr.cancel_subnet(subnet_id)
@@ -122,8 +125,9 @@ class SubnetDetail(CLIRunnable):
122125

123126
def execute(self, args):
124127
mgr = NetworkManager(self.client)
125-
126-
subnet_id = mgr.resolve_subnet_ids(args.get('<identifier>'))
128+
subnet_id = resolve_id(mgr.resolve_subnet_ids,
129+
args.get('<identifier>'),
130+
name='subnet')
127131
subnet = mgr.get_subnet(subnet_id)
128132

129133
t = KeyValueTable(['Name', 'Value'])

SoftLayer/CLI/modules/vlan.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# :license: MIT, see LICENSE for more details.
1212

1313
from SoftLayer import NetworkManager
14-
from SoftLayer.CLI import CLIRunnable, Table, KeyValueTable
14+
from SoftLayer.CLI import CLIRunnable, Table, KeyValueTable, blank, resolve_id
1515

1616

1717
class VlanDetail(CLIRunnable):
@@ -29,7 +29,10 @@ class VlanDetail(CLIRunnable):
2929
def execute(self, args):
3030
mgr = NetworkManager(self.client)
3131

32-
vlan = mgr.get_vlan(args.get('<identifier>'))
32+
vlan_id = resolve_id(mgr.resolve_vlan_ids,
33+
args.get('<identifier>'),
34+
'VLAN')
35+
vlan = mgr.get_vlan(vlan_id)
3336

3437
t = KeyValueTable(['Name', 'Value'])
3538
t.align['Name'] = 'r'
@@ -98,29 +101,32 @@ class VlanList(CLIRunnable):
98101
hardware, ccis, networking
99102
100103
Filters:
101-
-d DC, --datacenter=DC datacenter shortname (sng01, dal05, ...)
102-
-n NUM, --number=NUM VLAN number
104+
-d DC, --datacenter=DC datacenter shortname (sng01, dal05, ...)
105+
-n NUM, --number=NUM VLAN number
106+
--name=NAME VLAN name
103107
"""
104108
action = 'list'
105109

106110
def execute(self, args):
107111
mgr = NetworkManager(self.client)
108112

109113
t = Table([
110-
'id', 'number', 'datacenter', 'IPs', 'hardware', 'ccis',
114+
'id', 'number', 'datacenter', 'name', 'IPs', 'hardware', 'ccis',
111115
'networking', 'firewall'
112116
])
113117
t.sortby = args.get('--sortby') or 'id'
114118

115119
vlans = mgr.list_vlans(
116120
datacenter=args.get('--datacenter'),
117-
vlan_number=args.get('--number')
121+
vlan_number=args.get('--number'),
122+
name=args.get('--name'),
118123
)
119124
for vlan in vlans:
120125
t.add_row([
121126
vlan['id'],
122127
vlan['vlanNumber'],
123128
vlan['primaryRouter']['datacenter']['name'],
129+
vlan.get('name') or blank(),
124130
vlan['totalPrimaryIpAddressCount'],
125131
len(vlan['hardware']),
126132
len(vlan['virtualGuests']),

0 commit comments

Comments
 (0)