Skip to content

Commit 22f892c

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

File tree

2 files changed

+55
-28
lines changed

2 files changed

+55
-28
lines changed

SoftLayer/CLI/virt/create.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def _update_with_like_args(ctx, _, value):
6565
ctx.default_map = {}
6666
ctx.default_map.update(like_args)
6767

68-
6968
def _parse_create_args(client, args):
7069
"""Converts CLI arguments to args for VSManager.create_instance.
7170
@@ -121,10 +120,7 @@ def _parse_create_args(client, args):
121120
# Get the SSH keys
122121
if args.get('key'):
123122
keys = []
124-
for key in args.get('key'):
125-
resolver = SoftLayer.SshKeyManager(client).resolve_ids
126-
key_id = helpers.resolve_id(resolver, key, 'SshKey')
127-
keys.append(key_id)
123+
_add_keys(args, client, keys)
128124
data['ssh_keys'] = keys
129125

130126
if args.get('vlan_public'):
@@ -156,6 +152,13 @@ def _parse_create_args(client, args):
156152
return data
157153

158154

155+
def _add_keys(args, client, keys):
156+
for key in args.get('key'):
157+
resolver = SoftLayer.SshKeyManager(client).resolve_ids
158+
key_id = helpers.resolve_id(resolver, key, 'SshKey')
159+
keys.append(key_id)
160+
161+
159162
@click.command(epilog="See 'slcli vs create-options' for valid options")
160163
@click.option('--hostname', '-H',
161164
help="Host portion of the FQDN",
@@ -231,7 +234,7 @@ def _parse_create_args(client, args):
231234
type=click.Path(exists=True, readable=True, resolve_path=True))
232235
@click.option('--vlan-public',
233236
help="The ID of the public VLAN on which you want the virtual "
234-
"server placed",
237+
"server placed",
235238
type=click.INT)
236239
@click.option('--vlan-private',
237240
help="The ID of the private VLAN on which you want the virtual "

SoftLayer/managers/vs.py

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
from SoftLayer.managers import ordering
1717
from SoftLayer import utils
1818

19-
2019
LOGGER = logging.getLogger(__name__)
20+
21+
2122
# pylint: disable=no-self-use
2223

2324

@@ -366,27 +367,10 @@ def _generate_create_dict(
366367
if datacenter:
367368
data["datacenter"] = {"name": datacenter}
368369

369-
if 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-
380-
if 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)}}})
370+
if private_vlan and public_vlan:
371+
network_components = self._create_network_components(public_vlan, private_vlan,
372+
private_subnet, public_subnet)
373+
data.update(network_components)
390374

391375
if public_security_groups:
392376
secgroups = [{'securityGroup': {'id': int(sg)}}
@@ -429,6 +413,46 @@ def _generate_create_dict(
429413

430414
return data
431415

416+
def _create_network_components(
417+
self, public_vlan=None, private_vlan=None,
418+
private_subnet=None, public_subnet=None, **kwargs):
419+
420+
if private_vlan and public_vlan:
421+
if private_subnet and public_subnet:
422+
parameters = {
423+
'primaryNetworkComponent': {
424+
"networkVlan": {"primarySubnet": {"id": int(public_subnet)}}},
425+
'primaryBackendNetworkComponent': {
426+
"networkVlan": {"primarySubnet": {"id": int(private_subnet)}}}}
427+
else:
428+
if private_subnet:
429+
parameters = {
430+
'primaryNetworkComponent': {
431+
"networkVlan": {"id": int(public_vlan)}},
432+
'primaryBackendNetworkComponent': {
433+
"networkVlan": {"primarySubnet": {"id": int(private_subnet)}}}
434+
}
435+
else:
436+
parameters = {
437+
'primaryNetworkComponent': {
438+
"networkVlan": {"primarySubnet": {"id": int(public_subnet)}}},
439+
'primaryBackendNetworkComponent': {
440+
"networkVlan": {"id": int(private_vlan)}}
441+
}
442+
else:
443+
if private_vlan:
444+
parameters = {
445+
'primaryBackendNetworkComponent': {
446+
"networkVlan": {"id": int(private_vlan)}}
447+
}
448+
else:
449+
parameters = {
450+
'primaryNetworkComponent': {
451+
"networkVlan": {"id": int(public_vlan)}}
452+
}
453+
454+
return parameters
455+
432456
@retry(logger=LOGGER)
433457
def wait_for_transaction(self, instance_id, limit, delay=10):
434458
"""Waits on a VS transaction for the specified amount of time.

0 commit comments

Comments
 (0)