Skip to content

Commit 5672b1f

Browse files
author
Fernando Ojeda
committed
Fixed vlan subnet issue.
1 parent 32a6e43 commit 5672b1f

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

SoftLayer/CLI/virt/create.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ def _parse_create_args(client, args):
133133
if args.get('vlan_private'):
134134
data['private_vlan'] = args['vlan_private']
135135

136+
if args.get('subnet_public'):
137+
data['public_subnet'] = args['subnet_public']
138+
139+
if args.get('subnet_private'):
140+
data['private_subnet'] = args['subnet_private']
141+
136142
if args.get('public_security_group'):
137143
pub_groups = args.get('public_security_group')
138144
data['public_security_groups'] = [group for group in pub_groups]
@@ -231,6 +237,12 @@ def _parse_create_args(client, args):
231237
help="The ID of the private VLAN on which you want the virtual "
232238
"server placed",
233239
type=click.INT)
240+
@click.option('--subnet-public',
241+
help="The ID of the public SUBNET on which you want the virtual server placed",
242+
type=click.INT)
243+
@click.option('--subnet-private',
244+
help="The ID of the private SUBNET on which you want the virtual server placed",
245+
type=click.INT)
234246
@helpers.multi_option('--public-security-group',
235247
'-S',
236248
help=('Security group ID to associate with '

SoftLayer/managers/vs.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ def _generate_create_dict(
305305
hostname=None, domain=None, local_disk=True,
306306
datacenter=None, os_code=None, image_id=None,
307307
dedicated=False, public_vlan=None, private_vlan=None,
308+
private_subnet=None, public_subnet=None,
308309
userdata=None, nic_speed=None, disks=None, post_uri=None,
309310
private=False, ssh_keys=None, public_security_groups=None,
310311
private_security_groups=None, boot_mode=None, **kwargs):
@@ -366,13 +367,26 @@ def _generate_create_dict(
366367
data["datacenter"] = {"name": datacenter}
367368

368369
if public_vlan:
369-
data.update({
370-
'primaryNetworkComponent': {
371-
"networkVlan": {"id": int(public_vlan)}}})
370+
if public_subnet:
371+
data.update({
372+
'primaryNetworkComponent': {
373+
"networkVlan": {"id": int(public_vlan),
374+
"primarySubnet": {"id": int(public_subnet)}}}})
375+
else:
376+
data.update({
377+
'primaryNetworkComponent': {
378+
"networkVlan": {"id": int(public_vlan)}}})
379+
372380
if private_vlan:
373-
data.update({
374-
"primaryBackendNetworkComponent": {
375-
"networkVlan": {"id": int(private_vlan)}}})
381+
if private_subnet:
382+
data.update({
383+
'primaryBackendNetworkComponent': {
384+
"networkVlan": {"id": int(private_vlan),
385+
"primarySubnet": {"id": int(private_subnet)}}}})
386+
else:
387+
data.update({
388+
"primaryBackendNetworkComponent": {
389+
"networkVlan": {"id": int(private_vlan)}}})
376390

377391
if public_security_groups:
378392
secgroups = [{'securityGroup': {'id': int(sg)}}

tests/CLI/modules/vs_tests.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,31 @@ def test_create(self, confirm_mock):
337337
self.assert_called_with('SoftLayer_Virtual_Guest', 'createObject',
338338
args=args)
339339

340+
@mock.patch('SoftLayer.CLI.formatting.confirm')
341+
def test_create_vlan_subnet(self, confirm_mock):
342+
confirm_mock.return_value = True
343+
344+
result = self.run_command(['vs', 'create',
345+
'--cpu=2',
346+
'--domain=example.com',
347+
'--hostname=host',
348+
'--os=UBUNTU_LATEST',
349+
'--memory=1',
350+
'--billing=hourly',
351+
'--datacenter=dal05',
352+
'--vlan-private=577940',
353+
'--subnet-private=478700',
354+
'--vlan-public=1639255',
355+
'--subnet-public=297614',
356+
'--tag=dev',
357+
'--tag=green'])
358+
359+
self.assert_no_fail(result)
360+
self.assertEqual(json.loads(result.output),
361+
{'guid': '1a2b3c-1701',
362+
'id': 100,
363+
'created': '2013-08-01 15:23:45'})
364+
340365
@mock.patch('SoftLayer.CLI.formatting.confirm')
341366
def test_create_with_wait_ready(self, confirm_mock):
342367
mock = self.set_mock('SoftLayer_Virtual_Guest', 'getObject')

0 commit comments

Comments
 (0)