From 357ba70b96b3762a2d8336cb88b9eab1c9b263f3 Mon Sep 17 00:00:00 2001 From: caberos Date: Mon, 11 Apr 2022 11:00:56 -0400 Subject: [PATCH 1/3] Update global ip assign/unassign to use new API --- SoftLayer/CLI/globalip/assign.py | 14 +++++++------- SoftLayer/fixtures/SoftLayer_Network_Subnet.py | 1 + SoftLayer/managers/network.py | 10 ++++++++++ tests/CLI/modules/globalip_tests.py | 2 +- tests/managers/network_tests.py | 4 ++++ 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/SoftLayer/CLI/globalip/assign.py b/SoftLayer/CLI/globalip/assign.py index ea9a3d12f..1595ccdba 100644 --- a/SoftLayer/CLI/globalip/assign.py +++ b/SoftLayer/CLI/globalip/assign.py @@ -5,17 +5,17 @@ import SoftLayer from SoftLayer.CLI import environment -from SoftLayer.CLI import helpers -@click.command() +@click.command(epilog="More information about types and ") @click.argument('identifier') -@click.argument('target') +@click.option('--target', + help='See SLDN docs. ' + 'E.g SoftLayer_Network_Subnet_IpAddress, SoftLayer_Hardware_Server,SoftLayer_Virtual_Guest') +@click.option('--router', help='An appropriate identifier for the specified $type. Some types have multiple identifier') @environment.pass_env -def cli(env, identifier, target): +def cli(env, identifier, target, router): """Assigns the global IP 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, router) diff --git a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py index ac3b9d74a..d0b22b8e5 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 \ No newline at end of file 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') From 86173b04641d0fe59a2f1f13a810a068e2e92b20 Mon Sep 17 00:00:00 2001 From: caberos Date: Mon, 11 Apr 2022 15:42:38 -0400 Subject: [PATCH 2/3] fix the tox tool --- SoftLayer/fixtures/SoftLayer_Network_Subnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py index d0b22b8e5..9ecf8164e 100644 --- a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py +++ b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py @@ -44,4 +44,4 @@ editNote = True setTags = True cancel = True -route = True \ No newline at end of file +route = True From b32b8a979ad5b2115ac00682ea6aa1c3ee0e46b9 Mon Sep 17 00:00:00 2001 From: caberos Date: Thu, 14 Apr 2022 08:33:10 -0400 Subject: [PATCH 3/3] fix the team code review comments --- SoftLayer/CLI/globalip/assign.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/SoftLayer/CLI/globalip/assign.py b/SoftLayer/CLI/globalip/assign.py index 1595ccdba..3f58d7125 100644 --- a/SoftLayer/CLI/globalip/assign.py +++ b/SoftLayer/CLI/globalip/assign.py @@ -6,16 +6,21 @@ import SoftLayer from SoftLayer.CLI import environment +target_types = {'vlan': 'SoftLayer_Network_Vlan', + 'ip': 'SoftLayer_Network_Subnet_IpAddress', + 'hardware': 'SoftLayer_Hardware_Server', + 'vsi': 'SoftLayer_Virtual_Guest'} -@click.command(epilog="More information about types and ") + +@click.command(epilog="More information about types and identifiers " + "on https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/route/") @click.argument('identifier') -@click.option('--target', - help='See SLDN docs. ' - 'E.g SoftLayer_Network_Subnet_IpAddress, SoftLayer_Hardware_Server,SoftLayer_Virtual_Guest') -@click.option('--router', help='An appropriate identifier for the specified $type. Some types have multiple identifier') +@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, router): - """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) - mgr.route(identifier, target, router) + mgr.route(identifier, target_types.get(target), target_id)