summaryrefslogtreecommitdiff
path: root/cloudinit/sources
diff options
context:
space:
mode:
authorBrett Holman <brett.holman@canonical.com>2023-03-31 15:24:09 -0600
committerGitHub <noreply@github.com>2023-03-31 15:24:09 -0600
commit612b4de892d19333c33276d541fed99fd16d3998 (patch)
treec90b72f14ea98f7a4d99563e3b3f9745a0bbe343 /cloudinit/sources
parent2a61a589fc0145314a61a31df4fd71c4639c0154 (diff)
downloadcloud-init-git-612b4de892d19333c33276d541fed99fd16d3998.tar.gz
Standardize kernel commandline user interface (#2093)
- deprecate ci.ds= and ci.datasource= in favor of ds= - enable semi-colon-delimited datasource everywhere - add support for case-insensitive datasource match - add integration tests
Diffstat (limited to 'cloudinit/sources')
-rw-r--r--cloudinit/sources/DataSourceNoCloud.py11
-rw-r--r--cloudinit/sources/__init__.py41
2 files changed, 36 insertions, 16 deletions
diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py
index a32bd4d0..596a96a7 100644
--- a/cloudinit/sources/DataSourceNoCloud.py
+++ b/cloudinit/sources/DataSourceNoCloud.py
@@ -357,6 +357,14 @@ class DataSourceNoCloudNet(DataSourceNoCloud):
DataSourceNoCloud.__init__(self, sys_cfg, distro, paths)
self.supported_seed_starts = ("http://", "https://")
+ def ds_detect(self):
+ """NoCloud requires "nocloud-net" as the way to specify
+ seeding from an http(s) address. This diverges from all other
+ datasources in that it does a kernel commandline match on something
+ other than the datasource dsname for only DEP_NETWORK.
+ """
+ return "nocloud-net" == sources.parse_cmdline()
+
# Used to match classes to dependencies
datasources = [
@@ -368,6 +376,3 @@ datasources = [
# Return a list of data sources that match this set of dependencies
def get_datasource_list(depends):
return sources.list_from_depends(depends, datasources)
-
-
-# vi: ts=4 expandtab
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index 2779cac4..90521ba2 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -321,7 +321,7 @@ class DataSource(CloudInitPickleMixin, metaclass=abc.ABCMeta):
does not run, _something_ needs to detect the kernel command line
definition.
"""
- if self.dsname == parse_cmdline():
+ if self.dsname.lower() == parse_cmdline().lower():
LOG.debug(
"Machine is configured by the kernel commandline to run on "
"single datasource %s.",
@@ -998,11 +998,12 @@ def find_source(
raise DataSourceNotFoundException(msg)
-# Return a list of classes that have the same depends as 'depends'
-# iterate through cfg_list, loading "DataSource*" modules
-# and calling their "get_datasource_list".
-# Return an ordered list of classes that match (if any)
def list_sources(cfg_list, depends, pkg_list):
+ """Return a list of classes that have the same depends as 'depends'
+ iterate through cfg_list, loading "DataSource*" modules
+ and calling their "get_datasource_list".
+ Return an ordered list of classes that match (if any)
+ """
src_list = []
LOG.debug(
"Looking for data source in: %s,"
@@ -1011,9 +1012,9 @@ def list_sources(cfg_list, depends, pkg_list):
pkg_list,
depends,
)
- for ds_name in cfg_list:
- if not ds_name.startswith(DS_PREFIX):
- ds_name = "%s%s" % (DS_PREFIX, ds_name)
+
+ for ds in cfg_list:
+ ds_name = importer.match_case_insensitive_module_name(ds)
m_locs, _looked_locs = importer.find_module(
ds_name, pkg_list, ["get_datasource_list"]
)
@@ -1149,13 +1150,27 @@ def pkl_load(fname: str) -> Optional[DataSource]:
return None
-def parse_cmdline():
+def parse_cmdline() -> str:
"""Check if command line argument for this datasource was passed
Passing by command line overrides runtime datasource detection
"""
cmdline = util.get_cmdline()
- ds_parse_1 = re.search(r"ci\.ds=([a-zA-Z]+)(\s|$)", cmdline)
- ds_parse_2 = re.search(r"ci\.datasource=([a-zA-Z]+)(\s|$)", cmdline)
- ds = ds_parse_1 or ds_parse_2
- if ds:
+ ds_parse_0 = re.search(r"ds=([a-zA-Z]+)(\s|$|;)", cmdline)
+ ds_parse_1 = re.search(r"ci\.ds=([a-zA-Z]+)(\s|$|;)", cmdline)
+ ds_parse_2 = re.search(r"ci\.datasource=([a-zA-Z]+)(\s|$|;)", cmdline)
+ ds = ds_parse_0 or ds_parse_1 or ds_parse_2
+ deprecated = ds_parse_1 or ds_parse_2
+ if deprecated:
+ dsname = deprecated.group(1).strip()
+ util.deprecate(
+ deprecated=(
+ f"Defining the datasource on the commandline using "
+ f"ci.ds={dsname} or "
+ f"ci.datasource={dsname}"
+ ),
+ deprecated_version="23.2",
+ extra_message=f"Use ds={dsname} instead",
+ )
+ if ds and ds.group(1):
return ds.group(1)
+ return ""