Skip to content

Commit

Permalink
Add linode networking interfaces support in salt-cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
zliang-akamai committed Jan 24, 2024
1 parent b5c0969 commit 7bb75c4
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 24 deletions.
1 change: 1 addition & 0 deletions changelog/65908.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Linode instance networking interfaces support during salt-cloud Linode VM creation
51 changes: 42 additions & 9 deletions doc/topics/cloud/linode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,31 @@ Configuration Options
``swap``
**(optional)** The amount of disk space to allocate for the swap partition. Defaults to ``256``.

``interfaces``
**(Optional)** A list of networking interfaces to be attached to the Linode instance.
attribute of each interface includes ``purpose``, ``ipam_address``, ``label``, ``ipv4``, ``primary``,
and ``subnet_id``.

``purpose`` is required for all types of interface, allowed values: ``public``, ``vlan``, and ``vpc``.

``primary`` is a boolean that whether the interface is configured as the default route to the Linode.
Can't be ``true`` for VLAN interface

``ipam_address`` and ``label`` are only allowed for a VLAN interface, and ``label`` is required for a
VLAN interface.

``subnet_id`` and ``ipv4`` are only allowed for a VPC interface, and ``subnet_id`` is required for a
VPC interface.

``ipv4`` is an object with two attributes, ``nat_1_1`` and ``vpc``; ``vpc`` is the VPC Subnet IPv4
address for this Interface, and ``nat_1_1`` is the 1:1 NAT IPv4 address, used to associate a public
IPv4 address with the VPC Subnet IPv4 address assigned to this Interface.

You can check out the `interfaces schema on Linode API documentation`_ for details on the behaviors of
the attributes of an interface object.

.. _Linode's Network Helper: https://www.linode.com/docs/platform/network-helper/#what-is-network-helper
.. _interfaces schema on Linode API documentation: https://www.linode.com/docs/api/linode-instances/#linode-create__request-samples

Example Configuration
---------------------
Expand Down Expand Up @@ -141,15 +165,24 @@ A more advanced configuration utlizing all of the configuration options might lo
.. code-block:: yaml
my-linode-profile-advanced:
provider: my-linode-provider
size: g6-standard-1
image: linode/ubuntu22.04
location: us-central
password: iamaverylongp@ssword
assign_private_ip: true
ssh_interface: private_ips
ssh_pubkey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB...
swap_size: 512
provider: my-linode-provider
size: g6-standard-1
image: linode/ubuntu22.04
location: us-central
password: iamaverylongp@ssword
assign_private_ip: true
ssh_interface: private_ips
ssh_pubkey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB...
swap_size: 512
interfaces:
- purpose: public
- purpose: vlan
label: cool-vlan
ipam_address: 10.0.0.1/24
- purpose: vpc
subnet_id: 20222
ipv4:
vpc: 10.0.4.10
Migrating to APIv4
==================
Expand Down
53 changes: 38 additions & 15 deletions salt/cloud/clouds/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,38 @@
- **ssh_pubkey**: (optional) The public key to authorize for SSH with the VM.
- **swap**: (optional) The amount of disk space to allocate for the swap partition. Defaults to ``256``.
- **clonefrom**: (optional) The name of the Linode to clone from.
- **interfaces**: (optional) The list of networking interface to be attached to the Linode.
Set up a profile configuration in ``/etc/salt/cloud.profiles.d/``:
.. code-block:: yaml
my-linode-profile:
# a minimal configuration
provider: my-linode-provider
size: g6-standard-1
image: linode/ubuntu22.04
location: us-east
# a minimal configuration
provider: my-linode-provider
size: g6-standard-1
image: linode/ubuntu22.04
location: us-east
my-linode-profile-advanced:
# an advanced configuration
provider: my-linode-provider
size: g6-standard-3
image: linode/ubuntu22.04
location: eu-west
password: bogus123X
assign_private_ip: true
ssh_interface: private_ips
ssh_pubkey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB...
swap_size: 512
# an advanced configuration
provider: my-linode-provider
size: g6-standard-3
image: linode/ubuntu22.04
location: eu-west
password: bogus123X
assign_private_ip: true
ssh_interface: private_ips
ssh_pubkey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB...
swap_size: 512
interfaces:
- purpose: public
- purpose: vlan
label: cool-vlan
- purpose: vpc
subnet_id: 20222
ipv4:
vpc: 10.0.4.10
Migrating to APIv4
------------------
Expand Down Expand Up @@ -131,6 +140,18 @@ def _get_active_provider_name():
return __active_provider_name__


def _get_interfaces(vm_):
"""
Return the list of explicitly configured interface
"""
return config.get_cloud_config_value(
"interfaces",
vm_,
__opts__,
default=[{"purpose": "public"}],
)


def _get_backup_enabled(vm_):
"""
Return True if a backup is set to enabled
Expand Down Expand Up @@ -647,6 +668,7 @@ def create(self, vm_):
password = _get_password(vm_)
swap_size = _get_swap_size(vm_)
backups_enabled = _get_backup_enabled(vm_)
interfaces = _get_interfaces(vm_)

clonefrom_name = vm_.get("clonefrom", None)
instance_type = vm_.get("size", None)
Expand Down Expand Up @@ -685,6 +707,7 @@ def create(self, vm_):
"booted": True,
"root_pass": password,
"authorized_keys": pub_ssh_keys,
"interfaces": interfaces,
"image": image,
"swap_size": swap_size,
},
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/cloud/clouds/test_linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ def test_instance_with_backup(self):
self.run_cloud(" ".join(args), timeout=TIMEOUT)

self.assertDestroyInstance()

def test_instance_with_multiple_interfaces(self):
self._test_instance("linode-test-with-multiple-interfaces")
11 changes: 11 additions & 0 deletions tests/integration/files/conf/cloud.profiles.d/linode.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ linode-test-with-backup:
image: linode/ubuntu22.04
location: us-mia
backups_enabled: True

linode-test-with-multiple-interfaces:
provider: linode-config
size: g6-nanode-1
image: linode/ubuntu22.04
location: us-mia
backups_enabled: True
interfaces:
- purpose: public
- purpose: vlan
label: cool-vlan

0 comments on commit 7bb75c4

Please sign in to comment.