Repository: softlayer/softlayer-python
Pull request #736 (2016-06-27 21:31:59)

Use network space over address space

coveralls: 
[![Coverage Status](https://coveralls.io/builds/6772756/badge)](https://coveralls.io/builds/6772756)

Coverage decreased (-0.009%) to 79.789% when pulling **ae87d6f3973a32fc09c097de7ebce0ce876a77e5 on sudorandom:subnet-network** into **62515bd07eb51982ed4271b574ecb96a167fe82f on softlayer:master**.


Patch:
diff --git a/SoftLayer/CLI/subnet/detail.py b/SoftLayer/CLI/subnet/detail.py
index cfc0dadb..9c089fcc 100644
--- a/SoftLayer/CLI/subnet/detail.py
+++ b/SoftLayer/CLI/subnet/detail.py
@@ -7,6 +7,7 @@
 from SoftLayer.CLI import environment
 from SoftLayer.CLI import formatting
 from SoftLayer.CLI import helpers
+from SoftLayer import utils
 
 
 @click.command()
@@ -35,6 +36,8 @@ def cli(env, identifier, no_vs, no_hardware):
                    '%s/%s' % (subnet['networkIdentifier'],
                               str(subnet['cidr']))])
     table.add_row(['subnet type', subnet['subnetType']])
+    table.add_row(['network space',
+                   utils.lookup(subnet, 'networkVlan', 'networkSpace')])
     table.add_row(['gateway', subnet.get('gateway', formatting.blank())])
     table.add_row(['broadcast',
                    subnet.get('broadcastAddress', formatting.blank())])
diff --git a/SoftLayer/CLI/subnet/list.py b/SoftLayer/CLI/subnet/list.py
index 5db042a7..e5d0d83a 100644
--- a/SoftLayer/CLI/subnet/list.py
+++ b/SoftLayer/CLI/subnet/list.py
@@ -15,7 +15,7 @@
               type=click.Choice(['id',
                                  'identifier',
                                  'type',
-                                 'address_space',
+                                 'network_space',
                                  'datacenter',
                                  'vlan_id',
                                  'IPs',
@@ -25,18 +25,18 @@
               help="Filter by datacenter shortname (sng01, dal05, ...)")
 @click.option('--identifier', help="Filter by network identifier")
 @click.option('--subnet-type', '-t', help="Filter by subnet type")
-@click.option('--address-space', help="Filter by address space")
+@click.option('--network-space', help="Filter by network space")
 @click.option('--v4', '--ipv4', is_flag=True, help="Display only IPv4 subnets")
 @click.option('--v6', '--ipv6', is_flag=True, help="Display only IPv6 subnets")
 @environment.pass_env
-def cli(env, sortby, datacenter, identifier, subnet_type, address_space,
+def cli(env, sortby, datacenter, identifier, subnet_type, network_space,
         ipv4, ipv6):
     """List subnets."""
 
     mgr = SoftLayer.NetworkManager(env.client)
 
     table = formatting.Table([
-        'id', 'identifier', 'type', 'address_space', 'datacenter', 'vlan_id',
+        'id', 'identifier', 'type', 'network_space', 'datacenter', 'vlan_id',
         'IPs', 'hardware', 'vs',
     ])
     table.sortby = sortby
@@ -52,7 +52,7 @@ def cli(env, sortby, datacenter, identifier, subnet_type, address_space,
         version=version,
         identifier=identifier,
         subnet_type=subnet_type,
-        address_space=address_space,
+        network_space=network_space,
     )
 
     for subnet in subnets:
@@ -60,7 +60,9 @@ def cli(env, sortby, datacenter, identifier, subnet_type, address_space,
             subnet['id'],
             '%s/%s' % (subnet['networkIdentifier'], str(subnet['cidr'])),
             subnet.get('subnetType', formatting.blank()),
-            subnet.get('addressSpace', formatting.blank()),
+            utils.lookup(subnet,
+                         'networkVlan',
+                         'networkSpace') or formatting.blank(),
             utils.lookup(subnet, 'datacenter', 'name',) or formatting.blank(),
             subnet['networkVlanId'],
             subnet['ipAddressCount'],
diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py
index 1cf3b315..904b91f9 100644
--- a/SoftLayer/managers/network.py
+++ b/SoftLayer/managers/network.py
@@ -14,7 +14,7 @@
                                 'datacenter',
                                 'ipAddressCount',
                                 'virtualGuests',
-                                'addressSpace'])
+                                'networkVlan[id,networkSpace]'])
 DEFAULT_VLAN_MASK = ','.join([
     'firewallInterfaces',
     'hardwareCount',
@@ -245,7 +245,7 @@ def list_global_ips(self, version=None, identifier=None, **kwargs):
         return self.account.getGlobalIpRecords(**kwargs)
 
     def list_subnets(self, identifier=None, datacenter=None, version=0,
-                     subnet_type=None, address_space=None, **kwargs):
+                     subnet_type=None, network_space=None, **kwargs):
         """Display a list of all subnets on the account.
 
         This provides a quick overview of all subnets including information
@@ -258,7 +258,7 @@ def list_subnets(self, identifier=None, datacenter=None, version=0,
         :param int version: Only returns subnets of this version (4 or 6).
         :param string subnet_type: If specified, it will only returns subnets
                                      of this type.
-        :param string address_space: If specified, it will only returns subnets
+        :param string network_space: If specified, it will only returns subnets
                                        with the given address space label.
         :param dict \\*\\*kwargs: response-level options (mask, limit, etc.)
         """
@@ -280,9 +280,9 @@ def list_subnets(self, identifier=None, datacenter=None, version=0,
         else:
             # This filters out global IPs from the subnet listing.
             _filter['subnets']['subnetType'] = {'operation': '!= GLOBAL_IP'}
-        if address_space:
-            _filter['subnets']['addressSpace'] = utils.query_filter(
-                address_space)
+        if network_space:
+            _filter['subnets']['networkVlan']['networkSpace'] = (
+                utils.query_filter(network_space))
 
         kwargs['filter'] = _filter.to_dict()
 


Test patch:
diff --git a/tests/managers/network_tests.py b/tests/managers/network_tests.py
index 446bc7b3..b62a656a 100644
--- a/tests/managers/network_tests.py
+++ b/tests/managers/network_tests.py
@@ -193,7 +193,7 @@ def test_list_subnets_with_filters(self):
             datacenter='dal00',
             version=4,
             subnet_type='PRIMARY',
-            address_space='PUBLIC',
+            network_space='PUBLIC',
         )
 
         self.assertEqual(result, fixtures.SoftLayer_Account.getSubnets)
@@ -205,9 +205,10 @@ def test_list_subnets_with_filters(self):
                 },
                 'version': {'operation': 4},
                 'subnetType': {'operation': '_= PRIMARY'},
-                'addressSpace': {'operation': '_= PUBLIC'},
+                'networkVlan': {'networkSpace': {'operation': '_= PUBLIC'}},
             }
         }
+
         self.assert_called_with('SoftLayer_Account', 'getSubnets',
                                 mask='mask[%s]' % network.DEFAULT_SUBNET_MASK,
                                 filter=_filter)