Skip to content

Commit ac7465f

Browse files
author
Fernando Ojeda
committed
Add the option network component by router to slcli hw create.
1 parent 056cb87 commit ac7465f

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

SoftLayer/CLI/hardware/create.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
help="Exports options to a template file")
3232
@click.option('--wait', type=click.INT,
3333
help="Wait until the server is finished provisioning for up to X seconds before returning")
34+
@click.option('--router-public', type=click.INT,
35+
help="The ID of the public ROUTER on which you want the virtual server placed")
36+
@click.option('--router-private', type=click.INT,
37+
help="The ID of the private ROUTER on which you want the virtual server placed")
3438
@helpers.multi_option('--key', '-k', help="SSH keys to add to the root user")
3539
@helpers.multi_option('--extra', '-e', help="Extra option Key Names")
3640
@environment.pass_env
@@ -57,7 +61,9 @@ def cli(env, **args):
5761
'port_speed': args.get('port_speed'),
5862
'no_public': args.get('no_public') or False,
5963
'extras': args.get('extra'),
60-
'network': args.get('network')
64+
'network': args.get('network'),
65+
'public_router': args.get('router_public', None),
66+
'private_router': args.get('router_private', None)
6167
}
6268

6369
# Do not create hardware server with --test or --export

SoftLayer/managers/hardware.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ def _generate_create_dict(self,
492492
hourly=True,
493493
no_public=False,
494494
extras=None,
495-
network=None):
495+
network=None,
496+
public_router=None,
497+
private_router=None):
496498
"""Translates arguments into a dictionary for creating a server."""
497499

498500
extras = extras or []
@@ -535,6 +537,10 @@ def _generate_create_dict(self,
535537
'domain': domain,
536538
}]
537539
}
540+
if private_router:
541+
extras['hardware'][0]['primaryBackendNetworkComponent'] = {"router": {"id": int(private_router)}}
542+
if public_router:
543+
extras['hardware'][0]['primaryNetworkComponent'] = {"router": {"id": int(public_router)}}
538544
if post_uri:
539545
extras['provisionScripts'] = [post_uri]
540546

tests/CLI/modules/server_tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,26 @@ def test_create_server_with_export(self, export_mock):
418418
self.assertIn("Successfully exported options to a template file.", result.output)
419419
export_mock.assert_called_once()
420420

421+
@mock.patch('SoftLayer.HardwareManager.place_order')
422+
def test_create_server_with_router(self, order_mock):
423+
order_mock.return_value = {
424+
'orderId': 98765,
425+
'orderDate': '2013-08-02 15:23:47'
426+
}
427+
428+
result = self.run_command(['--really', 'server', 'create',
429+
'--size=S1270_8GB_2X1TBSATA_NORAID',
430+
'--hostname=test',
431+
'--domain=example.com',
432+
'--datacenter=TEST00',
433+
'--port-speed=100',
434+
'--os=OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT',
435+
'--router-private=123',
436+
'--router-public=1234'
437+
])
438+
439+
self.assert_no_fail(result)
440+
421441
def test_edit_server_userdata_and_file(self):
422442
# Test both userdata and userfile at once
423443
with tempfile.NamedTemporaryFile() as userfile:

tests/managers/hardware_tests.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -318,41 +318,29 @@ def test_generate_create_dict(self):
318318
'port_speed': 10,
319319
'hourly': True,
320320
'extras': ['1_IPV6_ADDRESS'],
321-
'post_uri': 'http://example.com/script.php',
322-
'ssh_keys': [10],
321+
'public_router': 1111,
322+
'private_router': 1234
323323
}
324324

325-
package = 'BARE_METAL_SERVER'
326-
location = 'wdc07'
327-
item_keynames = [
328-
'1_IP_ADDRESS',
329-
'UNLIMITED_SSL_VPN_USERS_1_PPTP_VPN_USER_PER_ACCOUNT',
330-
'REBOOT_KVM_OVER_IP',
331-
'OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT',
332-
'BANDWIDTH_0_GB_2',
333-
'10_MBPS_PUBLIC_PRIVATE_NETWORK_UPLINKS',
334-
'1_IPV6_ADDRESS'
335-
]
336-
hourly = True
337-
preset_keyname = 'S1270_8GB_2X1TBSATA_NORAID'
338325
extras = {
339326
'hardware': [{
340327
'domain': 'giggles.woo',
341328
'hostname': 'unicorn',
342-
}],
343-
'provisionScripts': ['http://example.com/script.php'],
344-
'sshKeys': [{'sshKeyIds': [10]}]
329+
'primaryNetworkComponent': {
330+
"router": {
331+
"id": 1111
332+
}
333+
},
334+
'primaryBackendNetworkComponent': {
335+
"router": {
336+
"id": 1234
337+
}
338+
}
339+
}]
345340
}
346341

347342
data = self.hardware._generate_create_dict(**args)
348-
349-
self.assertEqual(package, data['package_keyname'])
350-
self.assertEqual(location, data['location'])
351-
for keyname in item_keynames:
352-
self.assertIn(keyname, data['item_keynames'])
353343
self.assertEqual(extras, data['extras'])
354-
self.assertEqual(preset_keyname, data['preset_keyname'])
355-
self.assertEqual(hourly, data['hourly'])
356344

357345
def test_generate_create_dict_network_key(self):
358346
args = {

0 commit comments

Comments
 (0)