summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2018-12-03 22:06:47 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2018-12-03 22:06:47 +0000
commitadbd950af07a4b613a14bd83049915abdd6ca348 (patch)
treea99770cbb3f7a92fb5752e706ea4bb6928a833cf /cloudinit
parentcb44ad6f42ac015d7d8eaf2ab0bb5ab125ed04b6 (diff)
downloadvyos-cloud-init-adbd950af07a4b613a14bd83049915abdd6ca348.tar.gz
vyos-cloud-init-adbd950af07a4b613a14bd83049915abdd6ca348.zip
NoCloud: Allow top level 'network' key in network-config.
NoCloud's 'network-config' file was originally expected to contain network configuration without the top level 'network' key. This was because the file was named 'network-config' so specifying 'network' seemed redundant. However, JuJu is currently providing a top level 'network' config when it tries to disable networking ({"network": {"config": "disabled"}). Other users have also been surprised/confused by the fact that a network config in /etc/cloud/cloud.cfg.d/network.cfg differed from what was expected in 'network-config'. LP: #1798117
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/sources/DataSourceNoCloud.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py
index 9010f06c..6860f0cc 100644
--- a/cloudinit/sources/DataSourceNoCloud.py
+++ b/cloudinit/sources/DataSourceNoCloud.py
@@ -311,6 +311,35 @@ def parse_cmdline_data(ds_id, fill, cmdline=None):
return True
+def _maybe_remove_top_network(cfg):
+ """If network-config contains top level 'network' key, then remove it.
+
+ Some providers of network configuration may provide a top level
+ 'network' key (LP: #1798117) even though it is not necessary.
+
+ Be friendly and remove it if it really seems so.
+
+ Return the original value if no change or the updated value if changed."""
+ nullval = object()
+ network_val = cfg.get('network', nullval)
+ if network_val is nullval:
+ return cfg
+ bmsg = 'Top level network key in network-config %s: %s'
+ if not isinstance(network_val, dict):
+ LOG.debug(bmsg, "was not a dict", cfg)
+ return cfg
+ if len(list(cfg.keys())) != 1:
+ LOG.debug(bmsg, "had multiple top level keys", cfg)
+ return cfg
+ if network_val.get('config') == "disabled":
+ LOG.debug(bmsg, "was config/disabled", cfg)
+ elif not all(('config' in network_val, 'version' in network_val)):
+ LOG.debug(bmsg, "but missing 'config' or 'version'", cfg)
+ return cfg
+ LOG.debug(bmsg, "fixed by removing shifting network.", cfg)
+ return network_val
+
+
def _merge_new_seed(cur, seeded):
ret = cur.copy()
@@ -320,7 +349,8 @@ def _merge_new_seed(cur, seeded):
ret['meta-data'] = util.mergemanydict([cur['meta-data'], newmd])
if seeded.get('network-config'):
- ret['network-config'] = util.load_yaml(seeded['network-config'])
+ ret['network-config'] = _maybe_remove_top_network(
+ util.load_yaml(seeded.get('network-config')))
if 'user-data' in seeded:
ret['user-data'] = seeded['user-data']