Repository: softlayer/softlayer-python
Pull request #1615 (2022-04-13 16:13:27)

Ability to route/unroute subnets
https://github.com/softlayer/softlayer-python/issues/1613

the Subnet::unroute not implemented by the missing documentation about it


[subnet::unroute](https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/unroute/)


Patch:
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index 2d5bb9d6..ac2d5084 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -323,6 +323,7 @@
     ('subnet:list', 'SoftLayer.CLI.subnet.list:cli'),
     ('subnet:lookup', 'SoftLayer.CLI.subnet.lookup:cli'),
     ('subnet:edit-ip', 'SoftLayer.CLI.subnet.edit_ip:cli'),
+    ('subnet:route', 'SoftLayer.CLI.subnet.route:cli'),
 
     ('tags', 'SoftLayer.CLI.tags'),
     ('tags:cleanup', 'SoftLayer.CLI.tags.cleanup:cli'),
diff --git a/SoftLayer/CLI/subnet/route.py b/SoftLayer/CLI/subnet/route.py
new file mode 100644
index 00000000..e4d4acd4
--- /dev/null
+++ b/SoftLayer/CLI/subnet/route.py
@@ -0,0 +1,26 @@
+"""allows you to change the route of your Account Owned subnets."""
+# :license: MIT, see LICENSE for more details.
+
+import click
+
+import SoftLayer
+from SoftLayer.CLI import environment
+
+target_types = {'vlan': 'SoftLayer_Network_Vlan',
+                'ip': 'SoftLayer_Network_Subnet_IpAddress',
+                'hardware': 'SoftLayer_Hardware_Server',
+                'vsi': 'SoftLayer_Virtual_Guest'}
+
+
+@click.command(epilog="More information about types and identifiers "
+                      "on https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/route/")
+@click.argument('identifier')
+@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, target_id):
+    """Assigns the subnet to a target."""
+
+    mgr = SoftLayer.NetworkManager(env.client)
+    mgr.route(identifier, target_types.get(target), target_id)
diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py
index b139c27e..d1d4e8f8 100644
--- a/SoftLayer/managers/network.py
+++ b/SoftLayer/managers/network.py
@@ -831,7 +831,7 @@ def get_closed_pods(self):
         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.
+        """Assigns a subnet 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
diff --git a/docs/cli/subnet.rst b/docs/cli/subnet.rst
index 38bda428..7d22b824 100644
--- a/docs/cli/subnet.rst
+++ b/docs/cli/subnet.rst
@@ -30,3 +30,6 @@ Subnets
 .. click:: SoftLayer.CLI.subnet.edit_ip:cli
     :prog: subnet edit-ip
     :show-nested:
+.. click:: SoftLayer.CLI.subnet.route:cli
+    :prog: subnet route
+    :show-nested:


Test patch:
diff --git a/tests/CLI/modules/subnet_tests.py b/tests/CLI/modules/subnet_tests.py
index 65a4cc5c..03166c9f 100644
--- a/tests/CLI/modules/subnet_tests.py
+++ b/tests/CLI/modules/subnet_tests.py
@@ -184,3 +184,9 @@ def test_cancel(self, confirm_mock):
     def test_cancel_fail(self):
         result = self.run_command(['subnet', 'cancel', '1234'])
         self.assertEqual(result.exit_code, 2)
+
+    def test_route(self):
+        result = self.run_command(['subnet', 'route', '1'])
+
+        self.assert_no_fail(result)
+        self.assertEqual(result.exit_code, 0)