Skip to content

Commit 80bb3f1

Browse files
Merge pull request #1615 from caberos/issue1613
Ability to route/unroute subnets
2 parents 4b5d9c0 + 9fa63ac commit 80bb3f1

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@
323323
('subnet:list', 'SoftLayer.CLI.subnet.list:cli'),
324324
('subnet:lookup', 'SoftLayer.CLI.subnet.lookup:cli'),
325325
('subnet:edit-ip', 'SoftLayer.CLI.subnet.edit_ip:cli'),
326+
('subnet:route', 'SoftLayer.CLI.subnet.route:cli'),
326327

327328
('tags', 'SoftLayer.CLI.tags'),
328329
('tags:cleanup', 'SoftLayer.CLI.tags.cleanup:cli'),

SoftLayer/CLI/subnet/route.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""allows you to change 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+
9+
target_types = {'vlan': 'SoftLayer_Network_Vlan',
10+
'ip': 'SoftLayer_Network_Subnet_IpAddress',
11+
'hardware': 'SoftLayer_Hardware_Server',
12+
'vsi': 'SoftLayer_Virtual_Guest'}
13+
14+
15+
@click.command(epilog="More information about types and identifiers "
16+
"on https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/route/")
17+
@click.argument('identifier')
18+
@click.option('--target', type=click.Choice(['vlan', 'ip', 'hardware', 'vsi']),
19+
help='choose the type. vlan, ip, hardware, vsi')
20+
@click.option('--target-id', help='The identifier for the destination resource to route this subnet to. ')
21+
@environment.pass_env
22+
def cli(env, identifier, target, target_id):
23+
"""Assigns the subnet to a target."""
24+
25+
mgr = SoftLayer.NetworkManager(env.client)
26+
mgr.route(identifier, target_types.get(target), target_id)

SoftLayer/managers/network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ def get_closed_pods(self):
831831
return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', mask=mask, filter=closing_filter)
832832

833833
def route(self, subnet_id, type_serv, target):
834-
"""Assigns a global IP address to a specified target.
834+
"""Assigns a subnet to a specified target.
835835
836836
:param int subnet_id: The ID of the global IP being assigned
837837
:param string type_serv: The type service to assign

docs/cli/subnet.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ Subnets
3030
.. click:: SoftLayer.CLI.subnet.edit_ip:cli
3131
:prog: subnet edit-ip
3232
:show-nested:
33+
.. click:: SoftLayer.CLI.subnet.route:cli
34+
:prog: subnet route
35+
:show-nested:

tests/CLI/modules/subnet_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,9 @@ def test_cancel(self, confirm_mock):
184184
def test_cancel_fail(self):
185185
result = self.run_command(['subnet', 'cancel', '1234'])
186186
self.assertEqual(result.exit_code, 2)
187+
188+
def test_route(self):
189+
result = self.run_command(['subnet', 'route', '1'])
190+
191+
self.assert_no_fail(result)
192+
self.assertEqual(result.exit_code, 0)

0 commit comments

Comments
 (0)