Repository: softlayer/softlayer-python
Pull request #1738 (2022-08-24 14:33:31)

New command: subnet clear-route
[#issue1737](https://github.com/softlayer/softlayer-python/issues/1737)


Patch:
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index f652b77f..0d4af96c 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -333,6 +333,7 @@
     ('subnet:lookup', 'SoftLayer.CLI.subnet.lookup:cli'),
     ('subnet:edit-ip', 'SoftLayer.CLI.subnet.edit_ip:cli'),
     ('subnet:route', 'SoftLayer.CLI.subnet.route:cli'),
+    ('subnet:clear-route', 'SoftLayer.CLI.subnet.clear_route:cli'),
 
     ('tags', 'SoftLayer.CLI.tags'),
     ('tags:cleanup', 'SoftLayer.CLI.tags.cleanup:cli'),
diff --git a/SoftLayer/CLI/subnet/clear_route.py b/SoftLayer/CLI/subnet/clear_route.py
new file mode 100644
index 00000000..d343abe0
--- /dev/null
+++ b/SoftLayer/CLI/subnet/clear_route.py
@@ -0,0 +1,24 @@
+"""Remove the route of your Account Owned subnets."""
+# :license: MIT, see LICENSE for more details.
+
+import click
+
+import SoftLayer
+from SoftLayer.CLI import environment
+from SoftLayer.CLI import exceptions
+
+
+@click.command(cls=SoftLayer.CLI.command.SLCommand, )
+@click.argument('identifier')
+@environment.pass_env
+def cli(env, identifier):
+    """Remove the route of your Account Owned subnets."""
+
+    mgr = SoftLayer.NetworkManager(env.client)
+
+    subnet = mgr.clear_route(identifier)
+
+    if subnet:
+        click.secho("The transaction to clear the route is created, routes will be updated in one or two minutes.")
+    else:
+        raise exceptions.CLIAbort('Failed to clear the route for the subnet.')
diff --git a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py
index 9ecf8164..1ce8f916 100644
--- a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py
+++ b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py
@@ -45,3 +45,4 @@
 setTags = True
 cancel = True
 route = True
+clearRoute = True
diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py
index 1b0b6eac..327c1c80 100644
--- a/SoftLayer/managers/network.py
+++ b/SoftLayer/managers/network.py
@@ -880,3 +880,10 @@ def get_datacenter_by_keyname(self, keyname=None):
         if len(result) >= 1:
             return result[0]
         return {}
+
+    def clear_route(self, identifier):
+        """Calls SoftLayer_Network_Subnet::clearRoute()
+
+        returns  true or false.
+        """
+        return self.client.call('SoftLayer_Network_Subnet', 'clearRoute', id=identifier)
diff --git a/docs/cli/subnet.rst b/docs/cli/subnet.rst
index 7d22b824..6d70d2eb 100644
--- a/docs/cli/subnet.rst
+++ b/docs/cli/subnet.rst
@@ -30,6 +30,11 @@ 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:
+
+.. click:: SoftLayer.CLI.subnet.clear_route:cli
+    :prog: subnet clear-route
+    :show-nested:


Test patch:
diff --git a/tests/CLI/modules/subnet_tests.py b/tests/CLI/modules/subnet_tests.py
index 03166c9f..a0ebf1ae 100644
--- a/tests/CLI/modules/subnet_tests.py
+++ b/tests/CLI/modules/subnet_tests.py
@@ -190,3 +190,7 @@ def test_route(self):
 
         self.assert_no_fail(result)
         self.assertEqual(result.exit_code, 0)
+
+    def test_clear_route(self):
+        result = self.run_command(['subnet', 'clear-route', '123456'])
+        self.assert_no_fail(result)
diff --git a/tests/managers/network_tests.py b/tests/managers/network_tests.py
index 04c2d8d6..12cee4bc 100644
--- a/tests/managers/network_tests.py
+++ b/tests/managers/network_tests.py
@@ -363,11 +363,11 @@ def test_list_vlans_with_filters(self):
                 'id': {
                     'operation': 'orderBy',
                     'options': [
-                           {'name': 'sort', 'value': ['ASC']}]},
+                        {'name': 'sort', 'value': ['ASC']}]},
                 'vlanNumber': {'operation': 5},
                 'name': {'operation': '_= primary-vlan'},
                 'primaryRouter': {
-                      'datacenter': {'name': {'operation': '_= dal00'}}}}
+                    'datacenter': {'name': {'operation': '_= dal00'}}}}
         }
         self.assert_called_with('SoftLayer_Account', 'getNetworkVlans',
                                 filter=_filter)
@@ -653,3 +653,9 @@ def test_get_datacenter_by_keyname(self):
         SoftLayer_Location.return_value = []
         result = self.network.get_datacenter_by_keyname("TEST01")
         self.assertEqual(result, {})
+
+    def test_clear_route(self):
+        result = self.network.clear_route(1234)
+
+        self.assertEqual(result, True)
+        self.assert_called_with('SoftLayer_Network_Subnet', 'clearRoute')