From a3e1b519dfce76c3df612bc5513101246ac281f6 Mon Sep 17 00:00:00 2001 From: zsdc Date: Sun, 14 Feb 2021 19:21:10 +0200 Subject: network-config: T2403: Fixed missed network-config The commit ceaa51c3df393d8bcfb8aa58e47d9d2eb7a9efb2 fixed receiving network-config for non-typical, "internal" datasources not addressed to be used normally, but broke this for normal ones. So, this is the third time when this part of the module must be changed to combine both methods: `cloud.datasource.network_config` for normal and `init_stage._find_networking_config()` for internal. --- cloudinit/config/cc_vyos.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'cloudinit/config/cc_vyos.py') diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index e472a1cd..338f5507 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -454,8 +454,12 @@ def handle(name, cfg, cloud, log, _args): vendordata = cloud.datasource.vendordata logger.debug("Vendor-Data: {}".format(vendordata)) # Network-config - init_stage = Init() - (netcfg, netcfg_src) = init_stage._find_networking_config() + netcfg = cloud.datasource.network_config + if netcfg: + netcfg_src = dsname + else: + init_stage = Init() + (netcfg, netcfg_src) = init_stage._find_networking_config() logger.debug("Network-config: {}".format(netcfg)) logger.debug("Network-config source: {}".format(netcfg_src)) # Hostname with FQDN (if exist) -- cgit v1.2.3 From 054bb80a589e3f8d116ff6f4752c94c2d4d3606a Mon Sep 17 00:00:00 2001 From: zsdc Date: Mon, 15 Feb 2021 17:24:23 +0200 Subject: MAC address: T2403: Added MAC processing to network-config In rare cases, udev scripts may try to rename ethernet interfaces at the first boot, including an interface used to configure the system. This leads to inconsistency between the config and actual interface names and sometimes to wrong interfaces (`renameX`). If we will configure the `hw-id` option via Cloud-init, this must guarantee that interface will have a proper (expected) config and name. --- cloudinit/config/cc_vyos.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'cloudinit/config/cc_vyos.py') diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index 338f5507..45b1ca07 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -232,6 +232,13 @@ def set_config_interfaces_v1(config, iface_config): # configure physical interfaces if iface_config['type'] == 'physical': iface_name = iface_config['name'] + + # configre MAC + if 'mac_address' in iface_config: + logger.debug("Setting MAC for {}: {}".format(iface_name, iface_config['mac_address'])) + config.set(['interfaces', 'ethernet', iface_name, 'hw-id'], value=iface_config['mac_address'], replace=True) + config.set_tag(['interfaces', 'ethernet']) + # configre MTU if 'mtu' in iface_config: logger.debug("Setting MTU for {}: {}".format(iface_name, iface_config['mtu'])) @@ -345,6 +352,13 @@ def set_config_interfaces_v1(config, iface_config): # configure interface from networking config version 2 def set_config_interfaces_v2(config, iface_name, iface_config): logger.debug("Configuring network using Cloud-init networking config version 2") + + # configure MAC + if 'match' in iface_config and 'macaddress' in iface_config['match']: + logger.debug("Setting MAC for {}: {}".format(iface_name, iface_config['match']['macaddress'])) + config.set(['interfaces', 'ethernet', iface_name, 'hw-id'], value=iface_config['match']['macaddress'], replace=True) + config.set_tag(['interfaces', 'ethernet']) + # configure DHCP client if 'dhcp4' in iface_config: if iface_config['dhcp4'] is True: @@ -370,7 +384,7 @@ def set_config_interfaces_v2(config, iface_name, iface_config): config.set_tag(['protocols', 'static', 'route6']) config.set_tag(['protocols', 'static', 'route6', '::/0', 'next-hop']) - # configre MTU + # configure MTU if 'mtu' in iface_config: logger.debug("Setting MTU for {}: {}".format(iface_name, iface_config['mtu'])) config.set(['interfaces', 'ethernet', iface_name, 'mtu'], value=iface_config['mtu'], replace=True) -- cgit v1.2.3 From 57e53d13ad772a74f55c38d95f6d61623fe08633 Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Thu, 25 Mar 2021 09:54:15 -0500 Subject: Metadata: T3432: Azure ssh keys not working for version 1.2.7/1.3.x --- cloudinit/config/cc_vyos.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cloudinit/config/cc_vyos.py') diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index 45b1ca07..7fe01595 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -513,6 +513,9 @@ def handle(name, cfg, cloud, log, _args): # configure system logins # Prepare SSH public keys for default user, to be sure that global keys applied to the default account (if it exist) ssh_keys = metadata_v1['public_ssh_keys'] + # append SSH keys from metadata_ds + if metadata_ds['public-keys']: + ssh_keys.extend([ key for key in metadata_ds['public-keys'] ]) # append SSH keys from cloud-config ssh_keys.extend(cfg.get('ssh_authorized_keys', [])) # Configure authentication for default user account -- cgit v1.2.3 From 5b47d9dc1cd80e3dbd0fb21125febab2e99d5f9c Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Mon, 29 Mar 2021 06:44:35 -0500 Subject: Metadata: T3432: Azure ssh keys not working for version 1.2.7/1.3.x update --- cloudinit/config/cc_vyos.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cloudinit/config/cc_vyos.py') diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index 7fe01595..42b442fc 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -514,7 +514,8 @@ def handle(name, cfg, cloud, log, _args): # Prepare SSH public keys for default user, to be sure that global keys applied to the default account (if it exist) ssh_keys = metadata_v1['public_ssh_keys'] # append SSH keys from metadata_ds - if metadata_ds['public-keys']: + ds_keys = metadata_ds.get('public-keys') + if ds_keys: ssh_keys.extend([ key for key in metadata_ds['public-keys'] ]) # append SSH keys from cloud-config ssh_keys.extend(cfg.get('ssh_authorized_keys', [])) -- cgit v1.2.3 From 2f72bee35078604e9059ae5f8ae5c127ee05db4c Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Mon, 29 Mar 2021 14:01:57 -0500 Subject: domain-name: T3446: Cloudinit error message when empty domain is passed to filter. --- cloudinit/config/cc_vyos.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'cloudinit/config/cc_vyos.py') diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index 42b442fc..e632b1fa 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -441,8 +441,9 @@ def set_config_hostname(config, hostname, fqdn): if fqdn: try: domain_name = fqdn.partition("{}.".format(hostname))[2] - logger.debug("Configuring domain-name to: {}".format(hostname_filter(domain_name))) - config.set(['system', 'domain-name'], value=hostname_filter(domain_name), replace=True) + if domain_name: + logger.debug("Configuring domain-name to: {}".format(hostname_filter(domain_name))) + config.set(['system', 'domain-name'], value=hostname_filter(domain_name), replace=True) except Exception as err: logger.error("Failed to configure domain-name: {}".format(err)) -- cgit v1.2.3 From 48ee31b8b99c8dced5fa667946949045dceb577c Mon Sep 17 00:00:00 2001 From: zsdc Date: Sat, 3 Apr 2021 01:12:04 +0300 Subject: Azure: T3432: Reverted changes for appending public-keys This commit reverts the 5b47d9dc1cd80e3dbd0fb21125febab2e99d5f9c and 57e53d13ad772a74f55c38d95f6d61623fe08633 since Cloud-init 20.4 is not affected by the problem. --- cloudinit/config/cc_vyos.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'cloudinit/config/cc_vyos.py') diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index e632b1fa..cbe29811 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -514,10 +514,6 @@ def handle(name, cfg, cloud, log, _args): # configure system logins # Prepare SSH public keys for default user, to be sure that global keys applied to the default account (if it exist) ssh_keys = metadata_v1['public_ssh_keys'] - # append SSH keys from metadata_ds - ds_keys = metadata_ds.get('public-keys') - if ds_keys: - ssh_keys.extend([ key for key in metadata_ds['public-keys'] ]) # append SSH keys from cloud-config ssh_keys.extend(cfg.get('ssh_authorized_keys', [])) # Configure authentication for default user account -- cgit v1.2.3 From c1d00c2b17eea0c7fc05cb1852a3af83cd8b0a70 Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Tue, 1 Jun 2021 03:36:37 -0500 Subject: T3583: Overwrite default config ntp settings when custom ntp servers are provided. --- cloudinit/config/cc_vyos.py | 1 + 1 file changed, 1 insertion(+) (limited to 'cloudinit/config/cc_vyos.py') diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index cbe29811..3c5a5923 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -157,6 +157,7 @@ def set_config_ovf(config, ovf_environment): # Configure NTP servers if ntp_string: ntp_list = list(ntp_string.replace(' ', '').split(',')) + config.delete(['system', 'ntp']) for server in ntp_list: logger.debug("Configuring NTP server: {}".format(server)) config.set(['system', 'ntp', 'server'], value=server, replace=False) -- cgit v1.2.3 From 025ff72784d2f45bbe361fe451a69c5cde8bfdc1 Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Sun, 6 Jun 2021 08:11:25 -0500 Subject: T3601: Error in ssh keys for vmware cloud-init if ssh keys is left empty. --- cloudinit/config/cc_vyos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cloudinit/config/cc_vyos.py') diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index 3c5a5923..59571e15 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -514,7 +514,7 @@ def handle(name, cfg, cloud, log, _args): # configure system logins # Prepare SSH public keys for default user, to be sure that global keys applied to the default account (if it exist) - ssh_keys = metadata_v1['public_ssh_keys'] + ssh_keys = [key for key in metadata_v1['public_ssh_keys'] if key ] # append SSH keys from cloud-config ssh_keys.extend(cfg.get('ssh_authorized_keys', [])) # Configure authentication for default user account -- cgit v1.2.3 From 9f5a20ff749918694cae74d95eb8ea1142f540bb Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Mon, 7 Jun 2021 15:53:15 -0500 Subject: T3339: Cloud-Init domain search setting not applied. --- cloudinit/config/cc_vyos.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cloudinit/config/cc_vyos.py') diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index 59571e15..e1516f1b 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -315,7 +315,7 @@ def set_config_interfaces_v1(config, iface_config): if 'dns_search' in subnet: for item in subnet['dns_search']: logger.debug("Configuring DNS search domain for {}: {}".format(iface_name, item)) - config.set(['system', 'domain-search'], value=item, replace=False) + config.set(['system', 'domain-search', 'domain'], value=item, replace=False) # configure nameservers if iface_config['type'] == 'nameserver': @@ -326,7 +326,7 @@ def set_config_interfaces_v1(config, iface_config): if 'search' in iface_config: for item in iface_config['search']: logger.debug("Configuring DNS search domain: {}".format(item)) - config.set(['system', 'domain-search'], value=item, replace=False) + config.set(['system', 'domain-search', 'domain'], value=item, replace=False) # configure routes if iface_config['type'] == 'route': @@ -413,7 +413,7 @@ def set_config_interfaces_v2(config, iface_name, iface_config): if 'search' in iface_config['nameservers']: for item in iface_config['nameservers']['search']: logger.debug("Configuring DNS search domain for {}: {}".format(iface_name, item)) - config.set(['system', 'domain-search'], value=item, replace=False) + config.set(['system', 'domain-search', 'domain'], value=item, replace=False) if 'addresses' in iface_config['nameservers']: for item in iface_config['nameservers']['addresses']: logger.debug("Configuring DNS nameserver for {}: {}".format(iface_name, item)) -- cgit v1.2.3 From b1433de9e22fbc3ca5bb83276f4d69f26696a292 Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Wed, 9 Jun 2021 14:43:58 -0500 Subject: Add descrition for why the the ssh_keys variable is parsed. --- cloudinit/config/cc_vyos.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cloudinit/config/cc_vyos.py') diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index e1516f1b..65037e3b 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -514,6 +514,8 @@ def handle(name, cfg, cloud, log, _args): # configure system logins # Prepare SSH public keys for default user, to be sure that global keys applied to the default account (if it exist) + # If the ssh key is left emty on an OVA deploy the OVF datastore passes an empty string which generates an invalid key error. + # Set the ssh_keys variable from the metadata_v1['public_ssh_keys'] checked for empty strings. ssh_keys = [key for key in metadata_v1['public_ssh_keys'] if key ] # append SSH keys from cloud-config ssh_keys.extend(cfg.get('ssh_authorized_keys', [])) -- cgit v1.2.3 From f19bdae2a31d7271698bf9e3afdbfa150d40b571 Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Sun, 27 Jun 2021 10:25:30 -0500 Subject: T3653: Cloudinit subnet error if a cidr (/24) is used instead of a subnet mask (255.255.255.0) --- cloudinit/config/cc_vyos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cloudinit/config/cc_vyos.py') diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index 65037e3b..c1a27b3c 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -135,7 +135,7 @@ def set_config_ovf(config, ovf_environment): # Configure an interface and default route if ip_address and ip_mask and gateway: - ip_address_cidr = ipaddress.ip_interface("{}/{}".format(ip_address, ip_mask)).with_prefixlen + ip_address_cidr = ipaddress.ip_interface("{}/{}".format(ip_address, ip_mask.replace('/', ''))).with_prefixlen logger.debug("Configuring the IP address on the eth0 interface: {}".format(ip_address_cidr)) set_ipaddress(config, 'eth0', ip_address_cidr) -- cgit v1.2.3 From 8c3b48a080dad42aac05635a924c12087fe28763 Mon Sep 17 00:00:00 2001 From: zsdc Date: Fri, 11 Mar 2022 18:24:38 +0200 Subject: interfaces: T4296: Deconfigure network config applied by Cloud-Init This commit adds the ability to deconfigure all the interfaces that Cloud-init configured during deployment and remove the configuration file `/etc/network/interfaces.d/50-cloud-init`. This should protect from conflicts between CLI config and actual interfaces states. --- cloudinit/config/cc_vyos.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'cloudinit/config/cc_vyos.py') diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index c1a27b3c..c19ecfe8 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -22,7 +22,8 @@ import re import ipaddress -from os import path +from pathlib import Path +from subprocess import run, DEVNULL from uuid import uuid4 from cloudinit import log as logging from cloudinit.ssh_util import AuthKeyLineParser @@ -449,6 +450,28 @@ def set_config_hostname(config, hostname, fqdn): logger.error("Failed to configure domain-name: {}".format(err)) +# cleanup network interface config file added by cloud-init +def network_cleanup(): + logger.debug("Cleaning up network configuration applied by Cloud-Init") + net_config_file = Path('/etc/network/interfaces.d/50-cloud-init') + if net_config_file.exists(): + logger.debug(f"Configuration file {net_config_file} was found") + try: + # get a list of interfaces that need to be deconfigured + configured_ifaces = run( + ['ifquery', '-l', '-X', 'lo', '-i', net_config_file], + capture_output=True).stdout.decode().splitlines() + if configured_ifaces: + for iface in configured_ifaces: + logger.debug(f"Deconfiguring interface: {iface}") + run(['ifdown', iface], stdout=DEVNULL) + # delete the file + net_config_file.unlink() + logger.debug(f"Configuration file {net_config_file} was removed") + except Exception as err: + logger.error(f"Failed to cleanup network configuration: {err}") + + # main config handler def handle(name, cfg, cloud, log, _args): logger.debug("Cloud-init config: {}".format(cfg)) @@ -496,7 +519,7 @@ def handle(name, cfg, cloud, log, _args): bak_file_name = '/opt/vyatta/etc/config.boot.default' # open configuration file - if not path.exists(cfg_file_name): + if not Path(cfg_file_name).exists: file_name = bak_file_name else: file_name = cfg_file_name @@ -514,9 +537,9 @@ def handle(name, cfg, cloud, log, _args): # configure system logins # Prepare SSH public keys for default user, to be sure that global keys applied to the default account (if it exist) - # If the ssh key is left emty on an OVA deploy the OVF datastore passes an empty string which generates an invalid key error. + # If the ssh key is left emty on an OVA deploy the OVF datastore passes an empty string which generates an invalid key error. # Set the ssh_keys variable from the metadata_v1['public_ssh_keys'] checked for empty strings. - ssh_keys = [key for key in metadata_v1['public_ssh_keys'] if key ] + ssh_keys = [key for key in metadata_v1['public_ssh_keys'] if key] # append SSH keys from cloud-config ssh_keys.extend(cfg.get('ssh_authorized_keys', [])) # Configure authentication for default user account @@ -593,3 +616,6 @@ def handle(name, cfg, cloud, log, _args): logger.debug("Configuration file saved: {}".format(cfg_file_name)) except Exception as e: logger.error("Failed to write configs into file {}: {}".format(cfg_file_name, e)) + + # since we already have a config file, it is a time to clean up what Cloud-init may left + network_cleanup() -- cgit v1.2.3