diff options
author | eb3095 <45504889+eb3095@users.noreply.github.com> | 2021-10-04 10:23:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-04 09:23:12 -0500 |
commit | 591e97dad5cf5a6ea8211f34c7d8135aaaf947f6 (patch) | |
tree | 9405e9efd27401eb935a30d3256ca23dc2df75cd | |
parent | 392c3262dcb4108b42f09e1369d9072502302361 (diff) | |
download | vyos-cloud-init-591e97dad5cf5a6ea8211f34c7d8135aaaf947f6.tar.gz vyos-cloud-init-591e97dad5cf5a6ea8211f34c7d8135aaaf947f6.zip |
Allow Vultr to set MTU and use as-is configs (#1037)
Add MTU, accept-ra, routes, options and a direct way to provide intact
cloud configs for networking opposed to relying on configurations that
may need changed often.
-rw-r--r-- | cloudinit/sources/DataSourceVultr.py | 7 | ||||
-rw-r--r-- | cloudinit/sources/helpers/vultr.py | 41 |
2 files changed, 47 insertions, 1 deletions
diff --git a/cloudinit/sources/DataSourceVultr.py b/cloudinit/sources/DataSourceVultr.py index 92765c72..68e1ff0b 100644 --- a/cloudinit/sources/DataSourceVultr.py +++ b/cloudinit/sources/DataSourceVultr.py @@ -67,7 +67,12 @@ class DataSourceVultr(sources.DataSource): # Process metadata def get_datasource_data(self, md): # Generate network config - self.netcfg = vultr.generate_network_config(md['interfaces']) + if "cloud_interfaces" in md: + # In the future we will just drop pre-configured + # network configs into the array. They need names though. + self.netcfg = vultr.add_interface_names(md['cloud_interfaces']) + else: + self.netcfg = vultr.generate_network_config(md['interfaces']) # Grab vendordata self.vendordata_raw = md['vendor-data'] diff --git a/cloudinit/sources/helpers/vultr.py b/cloudinit/sources/helpers/vultr.py index 9effb0d9..55487ac3 100644 --- a/cloudinit/sources/helpers/vultr.py +++ b/cloudinit/sources/helpers/vultr.py @@ -152,6 +152,16 @@ def generate_public_network_interface(interface): ] } + # Options that may or may not be used + if "mtu" in interface: + netcfg['mtu'] = interface['mtu'] + + if "accept-ra" in interface: + netcfg['accept-ra'] = interface['accept-ra'] + + if "routes" in interface: + netcfg['subnets'][0]['routes'] = interface['routes'] + # Check for additional IP's additional_count = len(interface['ipv4']['additional']) if "ipv4" in interface and additional_count > 0: @@ -162,6 +172,10 @@ def generate_public_network_interface(interface): "address": additional['address'], "netmask": additional['netmask'] } + + if "routes" in additional: + add['routes'] = additional['routes'] + netcfg['subnets'].append(add) # Check for additional IPv6's @@ -174,6 +188,10 @@ def generate_public_network_interface(interface): "address": additional['address'], "netmask": additional['netmask'] } + + if "routes" in additional: + add['routes'] = additional['routes'] + netcfg['subnets'].append(add) # Add config to template @@ -202,7 +220,30 @@ def generate_private_network_interface(interface): ] } + # Options that may or may not be used + if "mtu" in interface: + netcfg['mtu'] = interface['mtu'] + + if "accept-ra" in interface: + netcfg['accept-ra'] = interface['accept-ra'] + + if "routes" in interface: + netcfg['subnets'][0]['routes'] = interface['routes'] + return netcfg +# Make required adjustments to the network configs provided +def add_interface_names(interfaces): + for interface in interfaces: + interface_name = get_interface_name(interface['mac']) + if not interface_name: + raise RuntimeError( + "Interface: %s could not be found on the system" % + interface['mac']) + interface['name'] = interface_name + + return interfaces + + # vi: ts=4 expandtab |