Skip to content

Commit 4b5d9c0

Browse files
Merge pull request #1614 from caberos/issue1612
Update global ip assign/unassign to use new API
2 parents 078c025 + b32b8a9 commit 4b5d9c0

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

SoftLayer/CLI/globalip/assign.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@
55

66
import SoftLayer
77
from SoftLayer.CLI import environment
8-
from SoftLayer.CLI import helpers
98

9+
target_types = {'vlan': 'SoftLayer_Network_Vlan',
10+
'ip': 'SoftLayer_Network_Subnet_IpAddress',
11+
'hardware': 'SoftLayer_Hardware_Server',
12+
'vsi': 'SoftLayer_Virtual_Guest'}
1013

11-
@click.command()
14+
15+
@click.command(epilog="More information about types and identifiers "
16+
"on https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/route/")
1217
@click.argument('identifier')
13-
@click.argument('target')
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. ')
1421
@environment.pass_env
15-
def cli(env, identifier, target):
16-
"""Assigns the global IP to a target."""
22+
def cli(env, identifier, target, target_id):
23+
"""Assigns the subnet to a target."""
1724

1825
mgr = SoftLayer.NetworkManager(env.client)
19-
global_ip_id = helpers.resolve_id(mgr.resolve_global_ip_ids, identifier,
20-
name='global ip')
21-
mgr.assign_global_ip(global_ip_id, target)
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
@@ -829,3 +829,13 @@ def get_closed_pods(self):
829829
mask = """mask[name, datacenterLongName, frontendRouterId, capabilities, datacenterId, backendRouterId,
830830
backendRouterName, frontendRouterName]"""
831831
return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', mask=mask, filter=closing_filter)
832+
833+
def route(self, subnet_id, type_serv, target):
834+
"""Assigns a global IP address to a specified target.
835+
836+
:param int subnet_id: The ID of the global IP being assigned
837+
:param string type_serv: The type service to assign
838+
:param string target: The instance to assign
839+
"""
840+
return self.client.call('SoftLayer_Network_Subnet', 'route',
841+
type_serv, target, id=subnet_id, )

tests/CLI/modules/globalip_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class DnsTests(testing.TestCase):
1616

1717
def test_ip_assign(self):
18-
result = self.run_command(['globalip', 'assign', '1', '127.0.0.1'])
18+
result = self.run_command(['globalip', 'assign', '1'])
1919

2020
self.assert_no_fail(result)
2121
self.assertEqual(result.output, "")

tests/managers/network_tests.py

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

0 commit comments

Comments
 (0)