summaryrefslogtreecommitdiff
path: root/cloudinit/sources/DataSourceNoCloud.py
diff options
context:
space:
mode:
authorBrett Holman <brett.holman@canonical.com>2023-04-12 10:44:47 -0600
committerGitHub <noreply@github.com>2023-04-12 10:44:47 -0600
commitf146fe71733e72b94fad525b8cc9988b1405e760 (patch)
treececd909672cfdcb3b1ee171f8aad5d38ea175926 /cloudinit/sources/DataSourceNoCloud.py
parent24945cad70bb98c12b44b1626cdcd99bc795e2dc (diff)
downloadcloud-init-git-f146fe71733e72b94fad525b8cc9988b1405e760.tar.gz
NoCloud: Use seedfrom protocol to determine mode (#2107)
Historically ds=nocloud-net was a required argument for the user to pass in to tell cloud-init which mode to use. This argument, however, is redundant when a seedfrom argument is passed. Allow the mode to be automatically determined, so that the user need not pass a mode configuration to achieve desired behavior.
Diffstat (limited to 'cloudinit/sources/DataSourceNoCloud.py')
-rw-r--r--cloudinit/sources/DataSourceNoCloud.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py
index 596a96a7..8d9caa02 100644
--- a/cloudinit/sources/DataSourceNoCloud.py
+++ b/cloudinit/sources/DataSourceNoCloud.py
@@ -280,12 +280,23 @@ def load_cmdline_data(fill, cmdline=None):
("ds=nocloud-net", sources.DSMODE_NETWORK),
]
for idstr, dsmode in pairs:
- if parse_cmdline_data(idstr, fill, cmdline):
+ if not parse_cmdline_data(idstr, fill, cmdline):
+ continue
+ if "dsmode" in fill:
# if dsmode was explicitly in the command line, then
- # prefer it to the dsmode based on the command line id
- if "dsmode" not in fill:
- fill["dsmode"] = dsmode
+ # prefer it to the dsmode based on seedfrom type
return True
+
+ seedfrom = fill.get("seedfrom")
+ if seedfrom:
+ if seedfrom.startswith(("http://", "https://")):
+ fill["dsmode"] = sources.DSMODE_NETWORK
+ elif seedfrom.startswith(("file://", "/")):
+ fill["dsmode"] = sources.DSMODE_LOCAL
+ else:
+ fill["dsmode"] = dsmode
+
+ return True
return False