Skip to content
Closed
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
7 changes: 7 additions & 0 deletions SoftLayer/CLI/virt/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def _parse_create_args(client, args):
if args.get('vlan_private'):
data['private_vlan'] = args['vlan_private']

if args.get('vlan_private_subnet'):
data['private_vlan_subnet'] = args['vlan_private_subnet']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend naming this private_subnet instead of private_vlan_subnet.


if args.get('public_security_group'):
pub_groups = args.get('public_security_group')
data['public_security_groups'] = [group for group in pub_groups]
Expand Down Expand Up @@ -227,6 +230,10 @@ def _parse_create_args(client, args):
help="The ID of the private VLAN on which you want the virtual "
"server placed",
type=click.INT)
@click.option('--vlan-private-subnet',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here just, --private-subnet.

help="The ID of the private VLAN subnet on which you want the virtual "
"server placed",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Max line length is 120, so put this all on one line please.

type=click.INT)
@helpers.multi_option('--public-security-group',
'-S',
help=('Security group ID to associate with '
Expand Down
24 changes: 20 additions & 4 deletions SoftLayer/managers/vs.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def _generate_create_dict(
dedicated=False, public_vlan=None, private_vlan=None,
userdata=None, nic_speed=None, disks=None, post_uri=None,
private=False, ssh_keys=None, public_security_groups=None,
private_security_groups=None, **kwargs):
private_security_groups=None, private_vlan_subnet=None, **kwargs):
"""Returns a dict appropriate to pass into Virtual_Guest::createObject

See :func:`create_instance` for a list of available options.
Expand Down Expand Up @@ -368,10 +368,25 @@ def _generate_create_dict(
data.update({
'primaryNetworkComponent': {
"networkVlan": {"id": int(public_vlan)}}})

if private_vlan:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thoughts here are to break out the private/public vlan stuff into a helper function.

if private_vlan or public_vlan:
    network_component = self._create_network_components(private_vlan, public_vlan, private_vlan_subnet, public_vlan_subnet)
    date.update(network_component)

Or something similar would work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions, I had just started doing that very thing - however, just to pre-warn you it seems there is a tox check for max number of lines in a module, and we have just crossed the 1000 limit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for that one, you can just add it to the ignored list at the top of this module. I don't want to split this file out at the moment, although I will likely do so in the future.

data.update({
"primaryBackendNetworkComponent": {
"networkVlan": {"id": int(private_vlan)}}})
# As per https://stackoverflow.com/questions/37592080/create-a-softlayer-virtual-guest-on-a-specific-subnet
# we can specify a subnet under the VLAN
if private_vlan_subnet:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be inside the private_vlan if statement since I don't think the API requires a vlan id when supplying a subnet id.

data.update({
"primaryBackendNetworkComponent": {
"networkVlanId": int(private_vlan),
"networkVlan": {
"primarySubnet": {
"id": int(private_vlan_subnet)
}
}
}
})
else:
data.update({
"primaryBackendNetworkComponent": {
"networkVlan": {"id": int(private_vlan)}}})

if public_security_groups:
secgroups = [{'securityGroup': {'id': int(sg)}}
Expand Down Expand Up @@ -565,6 +580,7 @@ def create_instance(self, **kwargs):
:param list public_security_groups: The list of security group IDs to apply to the public interface
:param list private_security_groups: The list of security group IDs to apply to the private interface
:param int private_vlan: The ID of the private VLAN on which you want this VS placed.
:param int private_vlan_subnet: The ID of the private VLAN subnet on which you want this VS placed.
:param list disks: A list of disk capacities for this server.
:param string post_uri: The URI of the post-install script to run after reload
:param bool private: If true, the VS will be provisioned only with access to the private network.
Expand Down