Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions SoftLayer/CLI/globalip/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions SoftLayer/fixtures/SoftLayer_Network_Subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
editNote = True
setTags = True
cancel = True
route = True
10 changes: 10 additions & 0 deletions SoftLayer/managers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, )
2 changes: 1 addition & 1 deletion tests/CLI/modules/globalip_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down
4 changes: 4 additions & 0 deletions tests/managers/network_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')