Repository: softlayer/softlayer-python
Pull request #1614 (2022-04-11 19:35:00)

Update global ip assign/unassign to use new API
https://github.com/softlayer/softlayer-python/issues/1612


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1749efae..6b6f55a7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,15 +1,6 @@
 # Change Log
 
 
-## [6.0.2] - 2022-03-30
-
-## What's Changed
-* New Command slcli hardware|virtual monitoring by @caberos in https://github.com/softlayer/softlayer-python/pull/1593
-* When listing datacenters/pods, mark those that are closing soon. by @caberos in https://github.com/softlayer/softlayer-python/pull/1597
-
-
-**Full Changelog**: https://github.com/softlayer/softlayer-python/compare/v6.0.1...v6.0.2
-
 ## [6.0.1] - 2022-03-11
 
 
diff --git a/SoftLayer/CLI/account/event_detail.py b/SoftLayer/CLI/account/event_detail.py
index 386a4171..2c1ee80c 100644
--- a/SoftLayer/CLI/account/event_detail.py
+++ b/SoftLayer/CLI/account/event_detail.py
@@ -65,9 +65,9 @@ def update_table(event):
     """Formats a basic event update table"""
     update_number = 0
     for update in event.get('updates', []):
-        update_number = update_number + 1
         header = "======= Update #%s on %s =======" % (update_number, utils.clean_time(update.get('startDate')))
         click.secho(header, fg='green')
+        update_number = update_number + 1
         text = update.get('contents')
         # deals with all the \r\n from the API
         click.secho(utils.clean_splitlines(text))
diff --git a/SoftLayer/CLI/globalip/assign.py b/SoftLayer/CLI/globalip/assign.py
index ea9a3d12..3f58d712 100644
--- a/SoftLayer/CLI/globalip/assign.py
+++ b/SoftLayer/CLI/globalip/assign.py
@@ -5,17 +5,22 @@
 
 import SoftLayer
 from SoftLayer.CLI import environment
-from SoftLayer.CLI import helpers
 
+target_types = {'vlan': 'SoftLayer_Network_Vlan',
+                'ip': 'SoftLayer_Network_Subnet_IpAddress',
+                'hardware': 'SoftLayer_Hardware_Server',
+                'vsi': 'SoftLayer_Virtual_Guest'}
 
-@click.command()
+
+@click.command(epilog="More information about types and identifiers "
+                      "on https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/route/")
 @click.argument('identifier')
-@click.argument('target')
+@click.option('--target', type=click.Choice(['vlan', 'ip', 'hardware', 'vsi']),
+              help='choose the type. vlan, ip, hardware, vsi')
+@click.option('--target-id', help='The identifier for the destination resource to route this subnet to. ')
 @environment.pass_env
-def cli(env, identifier, target):
-    """Assigns the global IP to a target."""
+def cli(env, identifier, target, target_id):
+    """Assigns the subnet to a target."""
 
     mgr = SoftLayer.NetworkManager(env.client)
-    global_ip_id = helpers.resolve_id(mgr.resolve_global_ip_ids, identifier,
-                                      name='global ip')
-    mgr.assign_global_ip(global_ip_id, target)
+    mgr.route(identifier, target_types.get(target), target_id)
diff --git a/SoftLayer/CLI/hardware/create.py b/SoftLayer/CLI/hardware/create.py
index 19d100fc..a1d373e1 100644
--- a/SoftLayer/CLI/hardware/create.py
+++ b/SoftLayer/CLI/hardware/create.py
@@ -41,10 +41,6 @@
 def cli(env, **args):
     """Order/create a dedicated server."""
     mgr = SoftLayer.HardwareManager(env.client)
-    network = SoftLayer.NetworkManager(env.client)
-
-    pods = network.get_closed_pods()
-    closure = []
 
     # Get the SSH keys
     ssh_keys = []
@@ -103,10 +99,6 @@ def cli(env, **args):
         return
 
     if do_create:
-        for pod in pods:
-            if args.get('datacenter') in str(pod['name']):
-                closure.append(pod['name'])
-        click.secho(click.style('Warning: Closed soon: %s' % (', '.join(closure)), fg='yellow'))
         if not (env.skip_confirmations or formatting.confirm(
                 "This action will incur charges on your account. Continue?")):
             raise exceptions.CLIAbort('Aborting dedicated server order.')
diff --git a/SoftLayer/CLI/licenses/__init__.py b/SoftLayer/CLI/licenses/__init__.py
index 74c74f88..e69de29b 100644
--- a/SoftLayer/CLI/licenses/__init__.py
+++ b/SoftLayer/CLI/licenses/__init__.py
@@ -1,2 +0,0 @@
-"""VMware licenses."""
-# :license: MIT, see LICENSE for more details.
diff --git a/SoftLayer/CLI/order/place.py b/SoftLayer/CLI/order/place.py
index 2b20be22..531bacee 100644
--- a/SoftLayer/CLI/order/place.py
+++ b/SoftLayer/CLI/order/place.py
@@ -8,7 +8,6 @@
 from SoftLayer.CLI import environment
 from SoftLayer.CLI import exceptions
 from SoftLayer.CLI import formatting
-from SoftLayer.managers import NetworkManager
 from SoftLayer.managers import ordering
 
 COLUMNS = ['keyName',
@@ -65,10 +64,6 @@ def cli(env, package_keyname, location, preset, verify, billing, complex_type,
 
     """
     manager = ordering.OrderingManager(env.client)
-    network = NetworkManager(env.client)
-
-    pods = network.get_closed_pods()
-    closure = []
 
     if extras:
         try:
@@ -95,9 +90,6 @@ def cli(env, package_keyname, location, preset, verify, billing, complex_type,
             ])
 
     else:
-        for pod in pods:
-            closure.append(pod['name'])
-        click.secho(click.style('Warning: Closed soon: %s' % (', '.join(closure)), fg='yellow'))
         if not (env.skip_confirmations or formatting.confirm(
                 "This action will incur charges on your account. Continue?")):
             raise exceptions.CLIAbort("Aborting order.")
diff --git a/SoftLayer/CLI/virt/create.py b/SoftLayer/CLI/virt/create.py
index 5953364d..ad8b3b35 100644
--- a/SoftLayer/CLI/virt/create.py
+++ b/SoftLayer/CLI/virt/create.py
@@ -218,16 +218,8 @@ def cli(env, **args):
     create_args = _parse_create_args(env.client, args)
     test = args.get('test', False)
     do_create = not (args.get('export') or test)
-    network = SoftLayer.NetworkManager(env.client)
-
-    pods = network.get_closed_pods()
-    closure = []
 
     if do_create:
-        for pod in pods:
-            if args.get('datacenter') in str(pod['name']):
-                closure.append(pod['name'])
-        click.secho(click.style('Warning: Closed soon: %s' % (', '.join(closure)), fg='yellow'))
         if not (env.skip_confirmations or formatting.confirm(
                 "This action will incur charges on your account. Continue?")):
             raise exceptions.CLIAbort('Aborting virtual server order.')
diff --git a/SoftLayer/consts.py b/SoftLayer/consts.py
index 32ebd4ec..54e4dfd2 100644
--- a/SoftLayer/consts.py
+++ b/SoftLayer/consts.py
@@ -5,7 +5,7 @@
 
     :license: MIT, see LICENSE for more details.
 """
-VERSION = 'v6.0.2'
+VERSION = 'v6.0.1'
 API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/xmlrpc/v3.1/'
 API_PRIVATE_ENDPOINT = 'https://api.service.softlayer.com/xmlrpc/v3.1/'
 API_PUBLIC_ENDPOINT_REST = 'https://api.softlayer.com/rest/v3.1/'
diff --git a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py
index ac3b9d74..9ecf8164 100644
--- a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py
+++ b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py
@@ -44,3 +44,4 @@
 editNote = True
 setTags = True
 cancel = True
+route = True
diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py
index 184c3713..73cd4430 100644
--- a/SoftLayer/managers/network.py
+++ b/SoftLayer/managers/network.py
@@ -506,7 +506,7 @@ def list_subnets(self, identifier=None, datacenter=None, version=0,
         kwargs['iter'] = True
         return self.client.call('Account', 'getSubnets', **kwargs)
 
-    def list_vlans(self, datacenter=None, vlan_number=None, name=None, limit=100, **kwargs):
+    def list_vlans(self, datacenter=None, vlan_number=None, name=None, **kwargs):
         """Display a list of all VLANs on the account.
 
         This provides a quick overview of all VLANs including information about
@@ -523,8 +523,6 @@ def list_vlans(self, datacenter=None, vlan_number=None, name=None, limit=100, **
         """
         _filter = utils.NestedDict(kwargs.get('filter') or {})
 
-        _filter['networkVlans']['id'] = utils.query_filter_orderby()
-
         if vlan_number:
             _filter['networkVlans']['vlanNumber'] = (
                 utils.query_filter(vlan_number))
@@ -542,10 +540,7 @@ def list_vlans(self, datacenter=None, vlan_number=None, name=None, limit=100, **
             kwargs['mask'] = DEFAULT_VLAN_MASK
 
         kwargs['iter'] = True
-        if limit > 0:
-            return self.account.getNetworkVlans(mask=kwargs['mask'], filter=_filter.to_dict(), limit=limit)
-        else:
-            return self.account.getNetworkVlans(mask=kwargs['mask'], filter=_filter.to_dict(), iter=True)
+        return self.account.getNetworkVlans(**kwargs)
 
     def list_securitygroups(self, **kwargs):
         """List security groups."""
@@ -829,3 +824,13 @@ def get_closed_pods(self):
         mask = """mask[name, datacenterLongName, frontendRouterId, capabilities, datacenterId, backendRouterId,
                 backendRouterName, frontendRouterName]"""
         return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', mask=mask, filter=closing_filter)
+
+    def route(self, subnet_id, type_serv, target):
+        """Assigns a global IP address to a specified target.
+
+        :param int subnet_id: The ID of the global IP being assigned
+        :param string type_serv: The type service to assign
+        :param string target: The instance to assign
+        """
+        return self.client.call('SoftLayer_Network_Subnet', 'route',
+                                type_serv, target, id=subnet_id, )
diff --git a/setup.py b/setup.py
index 09921fea..0138ba9d 100644
--- a/setup.py
+++ b/setup.py
@@ -16,7 +16,7 @@
 
 setup(
     name='SoftLayer',
-    version='6.0.2',
+    version='6.0.1',
     description=DESCRIPTION,
     long_description=LONG_DESCRIPTION,
     long_description_content_type='text/x-rst',
@@ -35,7 +35,7 @@
     python_requires='>=3.5',
     install_requires=[
         'prettytable >= 2.0.0',
-        'click == 8.0.4',
+        'click >= 7',
         'requests >= 2.20.0',
         'prompt_toolkit >= 2',
         'pygments >= 2.0.0',
diff --git a/tools/requirements.txt b/tools/requirements.txt
index dd85ec17..09f985d8 100644
--- a/tools/requirements.txt
+++ b/tools/requirements.txt
@@ -1,5 +1,5 @@
 prettytable >= 2.0.0
-click == 8.0.4
+click >= 7
 requests >= 2.20.0
 prompt_toolkit >= 2
 pygments >= 2.0.0


Test patch:
diff --git a/tests/CLI/modules/globalip_tests.py b/tests/CLI/modules/globalip_tests.py
index e12b7c3f..f46bd5ef 100644
--- a/tests/CLI/modules/globalip_tests.py
+++ b/tests/CLI/modules/globalip_tests.py
@@ -15,7 +15,7 @@
 class DnsTests(testing.TestCase):
 
     def test_ip_assign(self):
-        result = self.run_command(['globalip', 'assign', '1', '127.0.0.1'])
+        result = self.run_command(['globalip', 'assign', '1'])
 
         self.assert_no_fail(result)
         self.assertEqual(result.output, "")
diff --git a/tests/CLI/modules/order_tests.py b/tests/CLI/modules/order_tests.py
index 5eec6c18..be03bbd1 100644
--- a/tests/CLI/modules/order_tests.py
+++ b/tests/CLI/modules/order_tests.py
@@ -141,9 +141,10 @@ def test_place(self):
 
         self.assert_no_fail(result)
         self.assert_called_with('SoftLayer_Product_Order', 'placeOrder')
-        self.assertEqual('Warning: Closed soon: ams01.pod01, wdc07.pod01, TEST00.pod2\n'
-                         '{\n    "id": 1234,\n    "created": "2017-04-04 07:39:20",\n    "status": "APPROVED"\n}\n',
-                         str(result.output))
+        self.assertEqual({'id': 1234,
+                          'created': order_date,
+                          'status': 'APPROVED'},
+                         json.loads(result.output))
 
     def test_place_with_quantity(self):
         order_date = '2017-04-04 07:39:20'
@@ -161,9 +162,10 @@ def test_place_with_quantity(self):
 
         self.assert_no_fail(result)
         self.assert_called_with('SoftLayer_Product_Order', 'placeOrder')
-        self.assertEqual('Warning: Closed soon: ams01.pod01, wdc07.pod01, TEST00.pod2\n'
-                         '{\n    "id": 1234,\n    "created": "2017-04-04 07:39:20",\n    "status": "APPROVED"\n}\n',
-                         str(result.output))
+        self.assertEqual({'id': 1234,
+                          'created': order_date,
+                          'status': 'APPROVED'},
+                         json.loads(result.output))
 
     def test_place_extras_parameter_fail(self):
         result = self.run_command(['-y', 'order', 'place', 'package', 'DALLAS13', 'ITEM1',
diff --git a/tests/CLI/modules/server_tests.py b/tests/CLI/modules/server_tests.py
index b026fa8c..a150217e 100644
--- a/tests/CLI/modules/server_tests.py
+++ b/tests/CLI/modules/server_tests.py
@@ -397,9 +397,8 @@ def test_create_server(self, order_mock):
                                    ])
 
         self.assert_no_fail(result)
-        self.assertEqual(
-            str(result.output),
-            'Warning: Closed soon: TEST00.pod2\n{\n    "id": 98765,\n    "created": "2013-08-02 15:23:47"\n}\n')
+        self.assertEqual(json.loads(result.output),
+                         {'id': 98765, 'created': '2013-08-02 15:23:47'})
 
     @mock.patch('SoftLayer.CLI.template.export_to_template')
     def test_create_server_with_export(self, export_mock):
diff --git a/tests/managers/network_tests.py b/tests/managers/network_tests.py
index acb58bd2..24a2bbb0 100644
--- a/tests/managers/network_tests.py
+++ b/tests/managers/network_tests.py
@@ -360,14 +360,13 @@ def test_list_vlans_with_filters(self):
         self.assertEqual(result, fixtures.SoftLayer_Account.getNetworkVlans)
         _filter = {
             'networkVlans': {
-                'id': {
-                    'operation': 'orderBy',
-                    'options': [
-                           {'name': 'sort', 'value': ['ASC']}]},
+                'primaryRouter': {
+                    'datacenter': {
+                        'name': {'operation': '_= dal00'}},
+                },
                 'vlanNumber': {'operation': 5},
                 'name': {'operation': '_= primary-vlan'},
-                'primaryRouter': {
-                      'datacenter': {'name': {'operation': '_= dal00'}}}}
+            },
         }
         self.assert_called_with('SoftLayer_Account', 'getNetworkVlans',
                                 filter=_filter)
@@ -629,3 +628,7 @@ def test_vlan_edit(self):
     def test_get_all_pods(self):
         self.network.get_pods()
         self.assert_called_with('SoftLayer_Network_Pod', 'getAllObjects')
+
+    def test_route(self):
+        self.network.route('SoftLayer_Hardware_Server', 123456, 100)
+        self.assert_called_with('SoftLayer_Network_Subnet', 'route')
diff --git a/tools/test-requirements.txt b/tools/test-requirements.txt
index ac58d124..3cc0f32e 100644
--- a/tools/test-requirements.txt
+++ b/tools/test-requirements.txt
@@ -5,7 +5,7 @@ pytest-cov
 mock
 sphinx
 prettytable >= 2.0.0
-click == 8.0.4
+click >= 7
 requests >= 2.20.0
 prompt_toolkit >= 2
 pygments >= 2.0.0