Skip to content

Commit 6091974

Browse files
caberoscaberos
authored andcommitted
fix the team code review comments
1 parent 548d090 commit 6091974

File tree

4 files changed

+75
-8
lines changed

4 files changed

+75
-8
lines changed

SoftLayer/CLI/loadbal/order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def order_options(env, datacenter):
135135

136136
# Vlan/Subnet Lookups
137137
mask = "mask[networkVlan,podName,addressSpace]"
138-
subnets = net_mgr.list_subnets(mask=mask)
138+
subnets = net_mgr.list_subnets(datacenter=dc_name, network_space='PRIVATE', mask=mask)
139139
subnet_table = formatting.Table(['Id', 'Subnet', 'Vlan'], title='Private subnet')
140140

141141
for subnet in subnets:

SoftLayer/CLI/subnet/list.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@
2121
'IPs',
2222
'hardware',
2323
'vs']))
24+
@click.option('--datacenter', '-d',
25+
help="Filter by datacenter shortname (sng01, dal05, ...)")
26+
@click.option('--identifier', help="Filter by network identifier")
27+
@click.option('--subnet-type', '-t', help="Filter by subnet type")
28+
@click.option('--network-space', help="Filter by network space")
29+
@click.option('--ipv4', '--v4', is_flag=True, help="Display only IPv4 subnets")
30+
@click.option('--ipv6', '--v6', is_flag=True, help="Display only IPv6 subnets")
2431
@environment.pass_env
25-
def cli(env, sortby):
32+
def cli(env, sortby, datacenter, identifier, subnet_type, network_space, ipv4, ipv6):
2633
"""List subnets."""
2734

2835
mgr = SoftLayer.NetworkManager(env.client)
@@ -33,7 +40,19 @@ def cli(env, sortby):
3340
])
3441
table.sortby = sortby
3542

36-
subnets = mgr.list_subnets()
43+
version = 0
44+
if ipv4:
45+
version = 4
46+
elif ipv6:
47+
version = 6
48+
49+
subnets = mgr.list_subnets(
50+
datacenter=datacenter,
51+
version=version,
52+
identifier=identifier,
53+
subnet_type=subnet_type,
54+
network_space=network_space,
55+
)
3756

3857
for subnet in subnets:
3958
table.add_row([
@@ -43,7 +62,7 @@ def cli(env, sortby):
4362
utils.lookup(subnet,
4463
'networkVlan',
4564
'networkSpace') or formatting.blank(),
46-
utils.lookup(subnet, 'datacenter', 'name', ) or formatting.blank(),
65+
utils.lookup(subnet, 'datacenter', 'name',) or formatting.blank(),
4766
subnet['networkVlanId'],
4867
subnet['ipAddressCount'],
4968
len(subnet['hardware']),

SoftLayer/managers/network.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,15 +470,45 @@ def list_global_ips(self, version=None, identifier=None, **kwargs):
470470
kwargs['filter'] = _filter.to_dict()
471471
return self.account.getGlobalIpRecords(**kwargs)
472472

473-
def list_subnets(self, **kwargs):
473+
def list_subnets(self, identifier=None, datacenter=None, version=0,
474+
subnet_type=None, network_space=None, **kwargs):
474475
"""Display a list of all subnets on the account.
475476
476477
This provides a quick overview of all subnets including information
477478
about data center residence and the number of devices attached.
479+
480+
:param string identifier: If specified, the list will only contain the
481+
subnet matching this network identifier.
482+
:param string datacenter: If specified, the list will only contain
483+
subnets in the specified data center.
484+
:param int version: Only returns subnets of this version (4 or 6).
485+
:param string subnet_type: If specified, it will only returns subnets
486+
of this type.
487+
:param string network_space: If specified, it will only returns subnets
488+
with the given address space label.
489+
:param dict \\*\\*kwargs: response-level options (mask, limit, etc.)
478490
"""
479491
if 'mask' not in kwargs:
480492
kwargs['mask'] = DEFAULT_SUBNET_MASK
481493

494+
_filter = utils.NestedDict(kwargs.get('filter') or {})
495+
496+
if identifier:
497+
_filter['subnets']['networkIdentifier'] = (
498+
utils.query_filter(identifier))
499+
if datacenter:
500+
_filter['subnets']['datacenter']['name'] = (
501+
utils.query_filter(datacenter))
502+
if version:
503+
_filter['subnets']['version'] = utils.query_filter(version)
504+
if subnet_type:
505+
_filter['subnets']['subnetType'] = utils.query_filter(subnet_type)
506+
507+
if network_space:
508+
_filter['subnets']['networkVlan']['networkSpace'] = (
509+
utils.query_filter(network_space))
510+
511+
kwargs['filter'] = _filter.to_dict()
482512
kwargs['iter'] = True
483513
return self.client.call('Account', 'getSubnets', **kwargs)
484514

tests/managers/network_tests.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,29 @@ def test_list_global_ips_with_filter(self):
310310
filter=_filter)
311311

312312
def test_list_subnets_default(self):
313-
result = self.network.list_subnets()
314-
313+
result = self.network.list_subnets(
314+
identifier='10.0.0.1',
315+
datacenter='dal00',
316+
version=4,
317+
subnet_type='PRIMARY',
318+
network_space='PUBLIC',
319+
)
315320
self.assertEqual(result, fixtures.SoftLayer_Account.getSubnets)
321+
_filter = {
322+
'subnets': {
323+
'networkIdentifier': {'operation': '_= 10.0.0.1'},
324+
'datacenter': {
325+
'name': {'operation': '_= dal00'}
326+
},
327+
'version': {'operation': 4},
328+
'subnetType': {'operation': '_= PRIMARY'},
329+
'networkVlan': {'networkSpace': {'operation': '_= PUBLIC'}},
330+
}
331+
}
332+
316333
self.assert_called_with('SoftLayer_Account', 'getSubnets',
317-
mask='mask[%s]' % network.DEFAULT_SUBNET_MASK)
334+
mask='mask[%s]' % network.DEFAULT_SUBNET_MASK,
335+
filter=_filter)
318336

319337
def test_list_subnets_with_filters(self):
320338
result = self.network.list_subnets()

0 commit comments

Comments
 (0)