diff options
author | Chad Smith <chad.smith@canonical.com> | 2017-12-05 16:25:11 -0700 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2017-12-05 16:25:11 -0700 |
commit | 30b4d15764a1a9644379cf95770e8b2480856882 (patch) | |
tree | 102b18e80e5ff8bf383a7fe35e56f88328cd924a /cloudinit/util.py | |
parent | 47016791ca5e97d80e45d3f100bc4e5d0b88627d (diff) | |
download | vyos-cloud-init-30b4d15764a1a9644379cf95770e8b2480856882.tar.gz vyos-cloud-init-30b4d15764a1a9644379cf95770e8b2480856882.zip |
cli: Add clean and status subcommands
The 'cloud-init clean' command allows a user or script to clear cloud-init
artifacts from the system so that cloud-init sees the system as
unconfigured upon reboot. Optional parameters can be provided to remove
cloud-init logs and reboot after clean.
The 'cloud-init status' command allows the user or script to check whether
cloud-init has finished all configuration stages and whether errors
occurred. An optional --wait argument will poll on a 0.25 second interval
until cloud-init configuration is complete. The benefit here is scripts
can block on cloud-init completion before performing post-config tasks.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 6c014ba5..320d64e0 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -1398,6 +1398,32 @@ def get_output_cfg(cfg, mode): return ret +def get_config_logfiles(cfg): + """Return a list of log file paths from the configuration dictionary. + + @param cfg: The cloud-init merged configuration dictionary. + """ + logs = [] + if not cfg or not isinstance(cfg, dict): + return logs + default_log = cfg.get('def_log_file') + if default_log: + logs.append(default_log) + for fmt in get_output_cfg(cfg, None): + if not fmt: + continue + match = re.match('(?P<type>\||>+)\s*(?P<target>.*)', fmt) + if not match: + continue + target = match.group('target') + parts = target.split() + if len(parts) == 1: + logs.append(target) + elif ['tee', '-a'] == parts[:2]: + logs.append(parts[2]) + return list(set(logs)) + + def logexc(log, msg, *args): # Setting this here allows this to change # levels easily (not always error level) |