summaryrefslogtreecommitdiff
path: root/cloudinit/stages.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-03-11 21:15:45 +0100
committerGitHub <noreply@github.com>2020-03-11 21:15:45 +0100
commitfd87c24ff8f6f09a7e2cc223a4e8cdb8c08f1ef8 (patch)
treeb754b3991e5e57a9ae9155819f73fa0cbd4be269 /cloudinit/stages.py
parentca9a4eb26b41c204d1bd3a15586b14a5dde950bb (diff)
parentc6627bc05a57645e6af8b9a5a67e452d9f37e487 (diff)
downloadvyos-cloud-init-fd87c24ff8f6f09a7e2cc223a4e8cdb8c08f1ef8.tar.gz
vyos-cloud-init-fd87c24ff8f6f09a7e2cc223a4e8cdb8c08f1ef8.zip
Merge pull request #4 from zdc/T2117
Cloud-init: T2117: Updated to 20.1 version
Diffstat (limited to 'cloudinit/stages.py')
-rw-r--r--cloudinit/stages.py79
1 files changed, 58 insertions, 21 deletions
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index 8a064124..db8ba64c 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -6,11 +6,9 @@
import copy
import os
+import pickle
import sys
-import six
-from six.moves import cPickle as pickle
-
from cloudinit.settings import (
FREQUENCIES, CLOUD_CONFIG, PER_INSTANCE, RUN_CLOUD_CONFIG)
@@ -24,6 +22,7 @@ from cloudinit.handlers.shell_script import ShellScriptPartHandler
from cloudinit.handlers.upstart_job import UpstartJobPartHandler
from cloudinit.event import EventType
+from cloudinit.sources import NetworkConfigSource
from cloudinit import cloud
from cloudinit import config
@@ -500,7 +499,7 @@ class Init(object):
# Init the handlers first
for (_ctype, mod) in c_handlers.items():
if mod in c_handlers.initialized:
- # Avoid initing the same module twice (if said module
+ # Avoid initiating the same module twice (if said module
# is registered to more than one content-type).
continue
handlers.call_begin(mod, data, frequency)
@@ -548,11 +547,15 @@ class Init(object):
with events.ReportEventStack("consume-user-data",
"reading and applying user-data",
parent=self.reporter):
+ if util.get_cfg_option_bool(self.cfg, 'allow_userdata', True):
self._consume_userdata(frequency)
+ else:
+ LOG.debug('allow_userdata = False: discarding user-data')
+
with events.ReportEventStack("consume-vendor-data",
"reading and applying vendor-data",
parent=self.reporter):
- self._consume_vendordata(frequency)
+ self._consume_vendordata(frequency)
# Perform post-consumption adjustments so that
# modules that run during the init stage reflect
@@ -630,32 +633,54 @@ class Init(object):
if os.path.exists(disable_file):
return (None, disable_file)
- cmdline_cfg = ('cmdline', cmdline.read_kernel_cmdline_config())
- dscfg = ('ds', None)
+ available_cfgs = {
+ NetworkConfigSource.cmdline: cmdline.read_kernel_cmdline_config(),
+ NetworkConfigSource.initramfs: cmdline.read_initramfs_config(),
+ NetworkConfigSource.ds: None,
+ NetworkConfigSource.system_cfg: self.cfg.get('network'),
+ }
+
if self.datasource and hasattr(self.datasource, 'network_config'):
- dscfg = ('ds', self.datasource.network_config)
- sys_cfg = ('system_cfg', self.cfg.get('network'))
+ available_cfgs[NetworkConfigSource.ds] = (
+ self.datasource.network_config)
- for loc, ncfg in (cmdline_cfg, sys_cfg, dscfg):
+ if self.datasource:
+ order = self.datasource.network_config_sources
+ else:
+ order = sources.DataSource.network_config_sources
+ for cfg_source in order:
+ if not hasattr(NetworkConfigSource, cfg_source):
+ LOG.warning('data source specifies an invalid network'
+ ' cfg_source: %s', cfg_source)
+ continue
+ if cfg_source not in available_cfgs:
+ LOG.warning('data source specifies an unavailable network'
+ ' cfg_source: %s', cfg_source)
+ continue
+ ncfg = available_cfgs[cfg_source]
if net.is_disabled_cfg(ncfg):
- LOG.debug("network config disabled by %s", loc)
- return (None, loc)
+ LOG.debug("network config disabled by %s", cfg_source)
+ return (None, cfg_source)
if ncfg:
- return (ncfg, loc)
- return (self.distro.generate_fallback_config(), "fallback")
-
- def apply_network_config(self, bring_up):
- netcfg, src = self._find_networking_config()
- if netcfg is None:
- LOG.info("network config is disabled by %s", src)
- return
+ return (ncfg, cfg_source)
+ return (self.distro.generate_fallback_config(),
+ NetworkConfigSource.fallback)
+ def _apply_netcfg_names(self, netcfg):
try:
LOG.debug("applying net config names for %s", netcfg)
self.distro.apply_network_config_names(netcfg)
except Exception as e:
LOG.warning("Failed to rename devices: %s", e)
+ def apply_network_config(self, bring_up):
+ # get a network config
+ netcfg, src = self._find_networking_config()
+ if netcfg is None:
+ LOG.info("network config is disabled by %s", src)
+ return
+
+ # request an update if needed/available
if self.datasource is not NULL_DATA_SOURCE:
if not self.is_new_instance():
if not self.datasource.update_metadata([EventType.BOOT]):
@@ -663,8 +688,20 @@ class Init(object):
"No network config applied. Neither a new instance"
" nor datasource network update on '%s' event",
EventType.BOOT)
+ # nothing new, but ensure proper names
+ self._apply_netcfg_names(netcfg)
return
+ else:
+ # refresh netcfg after update
+ netcfg, src = self._find_networking_config()
+
+ # ensure all physical devices in config are present
+ net.wait_for_physdevs(netcfg)
+
+ # apply renames from config
+ self._apply_netcfg_names(netcfg)
+ # rendering config
LOG.info("Applying network configuration from %s bringup=%s: %s",
src, bring_up, netcfg)
try:
@@ -719,7 +756,7 @@ class Modules(object):
for item in cfg_mods:
if not item:
continue
- if isinstance(item, six.string_types):
+ if isinstance(item, str):
module_list.append({
'mod': item.strip(),
})