diff --git a/SoftLayer/CLI/globalip/assign.py b/SoftLayer/CLI/globalip/assign.py index ea9a3d12f..3f58d7125 100644 --- a/SoftLayer/CLI/globalip/assign.py +++ b/SoftLayer/CLI/globalip/assign.py @@ -5,17 +5,22 @@ import SoftLayer from SoftLayer.CLI import environment -from SoftLayer.CLI import helpers +target_types = {'vlan': 'SoftLayer_Network_Vlan', + 'ip': 'SoftLayer_Network_Subnet_IpAddress', + 'hardware': 'SoftLayer_Hardware_Server', + 'vsi': 'SoftLayer_Virtual_Guest'} -@click.command() + +@click.command(epilog="More information about types and identifiers " + "on https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/route/") @click.argument('identifier') -@click.argument('target') +@click.option('--target', type=click.Choice(['vlan', 'ip', 'hardware', 'vsi']), + help='choose the type. vlan, ip, hardware, vsi') +@click.option('--target-id', help='The identifier for the destination resource to route this subnet to. ') @environment.pass_env -def cli(env, identifier, target): - """Assigns the global IP to a target.""" +def cli(env, identifier, target, target_id): + """Assigns the subnet to a target.""" mgr = SoftLayer.NetworkManager(env.client) - global_ip_id = helpers.resolve_id(mgr.resolve_global_ip_ids, identifier, - name='global ip') - mgr.assign_global_ip(global_ip_id, target) + mgr.route(identifier, target_types.get(target), target_id) diff --git a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py index ac3b9d74a..9ecf8164e 100644 --- a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py +++ b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py @@ -44,3 +44,4 @@ editNote = True setTags = True cancel = True +route = True diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index 0f550ec3d..73cd4430c 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -824,3 +824,13 @@ def get_closed_pods(self): mask = """mask[name, datacenterLongName, frontendRouterId, capabilities, datacenterId, backendRouterId, backendRouterName, frontendRouterName]""" return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', mask=mask, filter=closing_filter) + + def route(self, subnet_id, type_serv, target): + """Assigns a global IP address to a specified target. + + :param int subnet_id: The ID of the global IP being assigned + :param string type_serv: The type service to assign + :param string target: The instance to assign + """ + return self.client.call('SoftLayer_Network_Subnet', 'route', + type_serv, target, id=subnet_id, ) diff --git a/tests/CLI/modules/globalip_tests.py b/tests/CLI/modules/globalip_tests.py index e12b7c3f6..f46bd5ef7 100644 --- a/tests/CLI/modules/globalip_tests.py +++ b/tests/CLI/modules/globalip_tests.py @@ -15,7 +15,7 @@ class DnsTests(testing.TestCase): def test_ip_assign(self): - result = self.run_command(['globalip', 'assign', '1', '127.0.0.1']) + result = self.run_command(['globalip', 'assign', '1']) self.assert_no_fail(result) self.assertEqual(result.output, "") diff --git a/tests/managers/network_tests.py b/tests/managers/network_tests.py index a578fd604..24a2bbb0b 100644 --- a/tests/managers/network_tests.py +++ b/tests/managers/network_tests.py @@ -628,3 +628,7 @@ def test_vlan_edit(self): def test_get_all_pods(self): self.network.get_pods() self.assert_called_with('SoftLayer_Network_Pod', 'getAllObjects') + + def test_route(self): + self.network.route('SoftLayer_Hardware_Server', 123456, 100) + self.assert_called_with('SoftLayer_Network_Subnet', 'route')