Skip to content

Commit d8f219d

Browse files
caberoscaberos
authored andcommitted
Ability to route/unroute subnets
1 parent 51b594e commit d8f219d

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
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/fixtures/SoftLayer_Network_Subnet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@
4444
editNote = True
4545
setTags = True
4646
cancel = True
47+
route = True

SoftLayer/managers/network.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,3 +824,13 @@ def get_closed_pods(self):
824824
mask = """mask[name, datacenterLongName, frontendRouterId, capabilities, datacenterId, backendRouterId,
825825
backendRouterName, frontendRouterName]"""
826826
return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', mask=mask, filter=closing_filter)
827+
828+
def route(self, subnet_id, type_serv, target):
829+
"""Assigns a subnet to a specified target.
830+
831+
:param int subnet_id: The ID of the global IP being assigned
832+
:param string type_serv: The type service to assign
833+
:param string target: The instance to assign
834+
"""
835+
return self.client.call('SoftLayer_Network_Subnet', 'route',
836+
type_serv, target, id=subnet_id, )

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)

tests/managers/network_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,3 +628,7 @@ def test_vlan_edit(self):
628628
def test_get_all_pods(self):
629629
self.network.get_pods()
630630
self.assert_called_with('SoftLayer_Network_Pod', 'getAllObjects')
631+
632+
def test_route(self):
633+
self.network.route('SoftLayer_Hardware_Server', 123456, 100)
634+
self.assert_called_with('SoftLayer_Network_Subnet', 'route')

0 commit comments

Comments
 (0)