Skip to content

Commit 31df7ad

Browse files
caberoscaberos
authored andcommitted
New command: subnet clear-route
1 parent fc276dd commit 31df7ad

File tree

7 files changed

+50
-2
lines changed

7 files changed

+50
-2
lines changed

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@
333333
('subnet:lookup', 'SoftLayer.CLI.subnet.lookup:cli'),
334334
('subnet:edit-ip', 'SoftLayer.CLI.subnet.edit_ip:cli'),
335335
('subnet:route', 'SoftLayer.CLI.subnet.route:cli'),
336+
('subnet:clear-route', 'SoftLayer.CLI.subnet.clear_route:cli'),
336337

337338
('tags', 'SoftLayer.CLI.tags'),
338339
('tags:cleanup', 'SoftLayer.CLI.tags.cleanup:cli'),
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Remove the route of your Account Owned subnets."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import exceptions
9+
10+
11+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
12+
@click.argument('identifier')
13+
@environment.pass_env
14+
def cli(env, identifier):
15+
"""Remove the route of your Account Owned subnets."""
16+
17+
mgr = SoftLayer.NetworkManager(env.client)
18+
19+
subnet = mgr.clear_route(identifier)
20+
21+
if subnet:
22+
click.secho("The transaction to clear the route is created, routes will be updated in one or two minutes.")
23+
else:
24+
raise exceptions.CLIAbort('Failed to clear the route for the subnet.')

SoftLayer/fixtures/SoftLayer_Network_Subnet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@
4545
setTags = True
4646
cancel = True
4747
route = True
48+
clearRoute = True

SoftLayer/managers/network.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,3 +880,10 @@ def get_datacenter_by_keyname(self, keyname=None):
880880
if len(result) >= 1:
881881
return result[0]
882882
return {}
883+
884+
def clear_route(self, identifier):
885+
"""Calls SoftLayer_Network_Subnet::clearRoute()
886+
887+
returns true or false.
888+
"""
889+
return self.client.call('SoftLayer_Network_Subnet', 'clearRoute', id=identifier)

docs/cli/subnet.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ Subnets
3030
.. click:: SoftLayer.CLI.subnet.edit_ip:cli
3131
:prog: subnet edit-ip
3232
:show-nested:
33+
3334
.. click:: SoftLayer.CLI.subnet.route:cli
3435
:prog: subnet route
3536
:show-nested:
37+
38+
.. click:: SoftLayer.CLI.subnet.clear_route:cli
39+
:prog: subnet clear-route
40+
:show-nested:

tests/CLI/modules/subnet_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,7 @@ def test_route(self):
190190

191191
self.assert_no_fail(result)
192192
self.assertEqual(result.exit_code, 0)
193+
194+
def test_clear_route(self):
195+
result = self.run_command(['subnet', 'clear-route', '123456'])
196+
self.assert_no_fail(result)

tests/managers/network_tests.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,11 @@ def test_list_vlans_with_filters(self):
363363
'id': {
364364
'operation': 'orderBy',
365365
'options': [
366-
{'name': 'sort', 'value': ['ASC']}]},
366+
{'name': 'sort', 'value': ['ASC']}]},
367367
'vlanNumber': {'operation': 5},
368368
'name': {'operation': '_= primary-vlan'},
369369
'primaryRouter': {
370-
'datacenter': {'name': {'operation': '_= dal00'}}}}
370+
'datacenter': {'name': {'operation': '_= dal00'}}}}
371371
}
372372
self.assert_called_with('SoftLayer_Account', 'getNetworkVlans',
373373
filter=_filter)
@@ -653,3 +653,9 @@ def test_get_datacenter_by_keyname(self):
653653
SoftLayer_Location.return_value = []
654654
result = self.network.get_datacenter_by_keyname("TEST01")
655655
self.assertEqual(result, {})
656+
657+
def test_clear_route(self):
658+
result = self.network.clear_route(1234)
659+
660+
self.assertEqual(result, True)
661+
self.assert_called_with('SoftLayer_Network_Subnet', 'clearRoute')

0 commit comments

Comments
 (0)