diff options
Diffstat (limited to 'cloudinit/sources/__init__.py')
-rw-r--r-- | cloudinit/sources/__init__.py | 41 |
1 files changed, 28 insertions, 13 deletions
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 "" |