Skip to content

Commit 8bdadbb

Browse files
Merge pull request #1422 from FernandoOjeda/ft/hw_create_with_routers
Add the option network component by router to slcli hw create.
2 parents 4156741 + 5a046cb commit 8bdadbb

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,40 @@ def test_generate_create_dict(self):
354354
self.assertEqual(preset_keyname, data['preset_keyname'])
355355
self.assertEqual(hourly, data['hourly'])
356356

357+
def test_generate_create_dict_by_router_network_component(self):
358+
args = {
359+
'size': 'S1270_8GB_2X1TBSATA_NORAID',
360+
'hostname': 'unicorn',
361+
'domain': 'giggles.woo',
362+
'location': 'wdc07',
363+
'os': 'OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT',
364+
'port_speed': 10,
365+
'hourly': True,
366+
'extras': ['1_IPV6_ADDRESS'],
367+
'public_router': 1111,
368+
'private_router': 1234
369+
}
370+
371+
extras = {
372+
'hardware': [{
373+
'domain': 'giggles.woo',
374+
'hostname': 'unicorn',
375+
'primaryNetworkComponent': {
376+
"router": {
377+
"id": 1111
378+
}
379+
},
380+
'primaryBackendNetworkComponent': {
381+
"router": {
382+
"id": 1234
383+
}
384+
}
385+
}]
386+
}
387+
388+
data = self.hardware._generate_create_dict(**args)
389+
self.assertEqual(extras, data['extras'])
390+
357391
def test_generate_create_dict_network_key(self):
358392
args = {
359393
'size': 'S1270_8GB_2X1TBSATA_NORAID',

0 commit comments

Comments
 (0)