Skip to content

Commit 62515bd

Browse files
authored
Adds filter for subnet address space (manager and CLI) (softlayer#733)
* Adds filter for subnet address space (manager and CLI) Closes softlayer#732. * Fixes tests for subnet listing and detailing
1 parent def654a commit 62515bd

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

SoftLayer/CLI/subnet/list.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
type=click.Choice(['id',
1616
'identifier',
1717
'type',
18+
'address_space',
1819
'datacenter',
1920
'vlan_id',
2021
'IPs',
@@ -24,17 +25,19 @@
2425
help="Filter by datacenter shortname (sng01, dal05, ...)")
2526
@click.option('--identifier', help="Filter by network identifier")
2627
@click.option('--subnet-type', '-t', help="Filter by subnet type")
28+
@click.option('--address-space', help="Filter by address space")
2729
@click.option('--v4', '--ipv4', is_flag=True, help="Display only IPv4 subnets")
2830
@click.option('--v6', '--ipv6', is_flag=True, help="Display only IPv6 subnets")
2931
@environment.pass_env
30-
def cli(env, sortby, datacenter, identifier, subnet_type, ipv4, ipv6):
32+
def cli(env, sortby, datacenter, identifier, subnet_type, address_space,
33+
ipv4, ipv6):
3134
"""List subnets."""
3235

3336
mgr = SoftLayer.NetworkManager(env.client)
3437

3538
table = formatting.Table([
36-
'id', 'identifier', 'type', 'datacenter', 'vlan_id', 'IPs',
37-
'hardware', 'vs',
39+
'id', 'identifier', 'type', 'address_space', 'datacenter', 'vlan_id',
40+
'IPs', 'hardware', 'vs',
3841
])
3942
table.sortby = sortby
4043

@@ -49,13 +52,15 @@ def cli(env, sortby, datacenter, identifier, subnet_type, ipv4, ipv6):
4952
version=version,
5053
identifier=identifier,
5154
subnet_type=subnet_type,
55+
address_space=address_space,
5256
)
5357

5458
for subnet in subnets:
5559
table.add_row([
5660
subnet['id'],
5761
'%s/%s' % (subnet['networkIdentifier'], str(subnet['cidr'])),
5862
subnet.get('subnetType', formatting.blank()),
63+
subnet.get('addressSpace', formatting.blank()),
5964
utils.lookup(subnet, 'datacenter', 'name',) or formatting.blank(),
6065
subnet['networkVlanId'],
6166
subnet['ipAddressCount'],

SoftLayer/managers/network.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
DEFAULT_SUBNET_MASK = ','.join(['hardware',
1414
'datacenter',
1515
'ipAddressCount',
16-
'virtualGuests'])
16+
'virtualGuests',
17+
'addressSpace'])
1718
DEFAULT_VLAN_MASK = ','.join([
1819
'firewallInterfaces',
1920
'hardwareCount',
@@ -244,7 +245,7 @@ def list_global_ips(self, version=None, identifier=None, **kwargs):
244245
return self.account.getGlobalIpRecords(**kwargs)
245246

246247
def list_subnets(self, identifier=None, datacenter=None, version=0,
247-
subnet_type=None, **kwargs):
248+
subnet_type=None, address_space=None, **kwargs):
248249
"""Display a list of all subnets on the account.
249250
250251
This provides a quick overview of all subnets including information
@@ -257,6 +258,8 @@ def list_subnets(self, identifier=None, datacenter=None, version=0,
257258
:param int version: Only returns subnets of this version (4 or 6).
258259
:param string subnet_type: If specified, it will only returns subnets
259260
of this type.
261+
:param string address_space: If specified, it will only returns subnets
262+
with the given address space label.
260263
:param dict \\*\\*kwargs: response-level options (mask, limit, etc.)
261264
"""
262265
if 'mask' not in kwargs:
@@ -277,6 +280,9 @@ def list_subnets(self, identifier=None, datacenter=None, version=0,
277280
else:
278281
# This filters out global IPs from the subnet listing.
279282
_filter['subnets']['subnetType'] = {'operation': '!= GLOBAL_IP'}
283+
if address_space:
284+
_filter['subnets']['addressSpace'] = utils.query_filter(
285+
address_space)
280286

281287
kwargs['filter'] = _filter.to_dict()
282288

tests/managers/network_tests.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
import SoftLayer
88
from SoftLayer import fixtures
9+
from SoftLayer.managers import network
910
from SoftLayer import testing
1011

1112

@@ -182,33 +183,33 @@ def test_list_subnets_default(self):
182183

183184
self.assertEqual(result, fixtures.SoftLayer_Account.getSubnets)
184185
_filter = {'subnets': {'subnetType': {'operation': '!= GLOBAL_IP'}}}
185-
mask = 'mask[hardware,datacenter,ipAddressCount,virtualGuests]'
186186
self.assert_called_with('SoftLayer_Account', 'getSubnets',
187-
mask=mask,
187+
mask='mask[%s]' % network.DEFAULT_SUBNET_MASK,
188188
filter=_filter)
189189

190190
def test_list_subnets_with_filters(self):
191191
result = self.network.list_subnets(
192192
identifier='10.0.0.1',
193193
datacenter='dal00',
194-
subnet_type='PRIMARY',
195194
version=4,
195+
subnet_type='PRIMARY',
196+
address_space='PUBLIC',
196197
)
197198

198199
self.assertEqual(result, fixtures.SoftLayer_Account.getSubnets)
199200
_filter = {
200201
'subnets': {
202+
'networkIdentifier': {'operation': '_= 10.0.0.1'},
201203
'datacenter': {
202204
'name': {'operation': '_= dal00'}
203205
},
204206
'version': {'operation': 4},
205207
'subnetType': {'operation': '_= PRIMARY'},
206-
'networkIdentifier': {'operation': '_= 10.0.0.1'}
208+
'addressSpace': {'operation': '_= PUBLIC'},
207209
}
208210
}
209-
mask = 'mask[hardware,datacenter,ipAddressCount,virtualGuests]'
210211
self.assert_called_with('SoftLayer_Account', 'getSubnets',
211-
mask=mask,
212+
mask='mask[%s]' % network.DEFAULT_SUBNET_MASK,
212213
filter=_filter)
213214

214215
def test_list_vlans_default(self):

0 commit comments

Comments
 (0)