summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-03-05 13:35:53 -0500
committerScott Moser <smoser@ubuntu.com>2015-03-05 13:35:53 -0500
commitc3f5fb9cd04681428dcc64aa8fc55b2d9cb86a52 (patch)
tree0a31c164b9ec3119dd9928b3fa72fa9af8e1a475 /cloudinit
parent5938747c4e3dbaca8afb3ce63e8ea5a67210b399 (diff)
parentc501a37e94b9601740fd7b3dcbcc4cce9136d7f4 (diff)
downloadvyos-cloud-init-c3f5fb9cd04681428dcc64aa8fc55b2d9cb86a52.tar.gz
vyos-cloud-init-c3f5fb9cd04681428dcc64aa8fc55b2d9cb86a52.zip
snappy: disable by default
this does 2 things actually a.) disables snappy by default, and adds checks to filesystem to enable it this way it runs on snappy systems, but not on others. b.) removes the 'render2env' that was mostly spike code. LP: #1428495
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/config/cc_snappy.py82
1 files changed, 31 insertions, 51 deletions
diff --git a/cloudinit/config/cc_snappy.py b/cloudinit/config/cc_snappy.py
index 1588443f..133336d4 100644
--- a/cloudinit/config/cc_snappy.py
+++ b/cloudinit/config/cc_snappy.py
@@ -14,15 +14,16 @@ LOG = logging.getLogger(__name__)
frequency = PER_INSTANCE
SNAPPY_ENV_PATH = "/writable/system-data/etc/snappy.env"
-CI_SNAPPY_CFG = {
- 'env_file_path': SNAPPY_ENV_PATH,
+BUILTIN_CFG = {
'packages': [],
'packages_dir': '/writable/user-data/cloud-init/click_packages',
- 'ssh_enabled': False
+ 'ssh_enabled': False,
+ 'system_snappy': "auto"
}
"""
snappy:
+ system_snappy: auto
ssh_enabled: True
packages:
- etcd
@@ -30,25 +31,6 @@ snappy:
"""
-def flatten(data, fill=None, tok="_", prefix='', recurse=True):
- if fill is None:
- fill = {}
- for key, val in data.items():
- key = key.replace("-", "_")
- if isinstance(val, dict) and recurse:
- flatten(val, fill, tok=tok, prefix=prefix + key + tok,
- recurse=recurse)
- elif isinstance(key, str):
- fill[prefix + key] = val
- return fill
-
-
-def render2env(data, tok="_", prefix=''):
- flat = flatten(data, tok=tok, prefix=prefix)
- ret = ["%s='%s'" % (key, val) for key, val in flat.items()]
- return '\n'.join(ret) + '\n'
-
-
def install_package(pkg_name, config=None):
cmd = ["snappy", "install"]
if config:
@@ -98,36 +80,34 @@ def disable_enable_ssh(enabled):
util.write_file(not_to_be_run, "cloud-init\n")
+def system_is_snappy():
+ # channel.ini is configparser loadable.
+ # snappy will move to using /etc/system-image/config.d/*.ini
+ # this is certainly not a perfect test, but good enough for now.
+ content = util.load_file("/etc/system-image/channel.ini", quiet=True)
+ if 'ubuntu-core' in content.lower():
+ return True
+ if os.path.isdir("/etc/system-image/config.d/"):
+ return True
+ return False
+
+
def handle(name, cfg, cloud, log, args):
- mycfg = cfg.get('snappy', {'ssh_enabled': False})
+ cfgin = cfg.get('snappy')
+ if not cfgin:
+ cfgin = {}
+ mycfg = util.mergemanydict([cfgin, BUILTIN_CFG])
+
+ sys_snappy = str(mycfg.get("system_snappy", "auto"))
+ if util.is_false(sys_snappy):
+ LOG.debug("%s: System is not snappy. disabling", name)
+ return
- if not mycfg:
- LOG.debug("%s: no top level found", name)
+ if sys_snappy.lower() == "auto" and not(system_is_snappy()):
+ LOG.debug("%s: 'auto' mode, and system not snappy", name)
return
- # take out of 'cfg' the cfg keys that cloud-init uses, so
- # mycfg has only content external to cloud-init.
- ci_cfg = CI_SNAPPY_CFG.copy()
- for i in ci_cfg:
- if i in mycfg:
- ci_cfg[i] = mycfg[i]
- del mycfg[i]
-
- # render the flattened environment variable style file to a path
- # this was useful for systemd config environment files. given:
- # snappy:
- # foo:
- # bar: wark
- # cfg1:
- # key1: value
- # you get the following in env_file_path.
- # foo_bar=wark
- # foo_cfg1_key1=value
- contents = render2env(mycfg)
- header = '# for internal use only, not a guaranteed interface\n'
- util.write_file(ci_cfg['env_file_path'], header + render2env(mycfg))
-
- install_packages(ci_cfg['packages_dir'],
- ci_cfg['packages'])
-
- disable_enable_ssh(ci_cfg.get('ssh_enabled', False))
+ install_packages(mycfg['packages_dir'],
+ mycfg['packages'])
+
+ disable_enable_ssh(mycfg.get('ssh_enabled', False))