summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_snap.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-03-22 21:13:06 -0400
committerScott Moser <smoser@brickies.net>2018-03-22 21:13:06 -0400
commit0d51e912146b3031c458ce415b7d4cd6eb17d06e (patch)
tree3c130dee4981de130952123b0aee61757ef9940d /cloudinit/config/cc_snap.py
parentd29eeccd2c422b8eb3b053fc13ca966ed6d74c78 (diff)
downloadvyos-cloud-init-0d51e912146b3031c458ce415b7d4cd6eb17d06e.tar.gz
vyos-cloud-init-0d51e912146b3031c458ce415b7d4cd6eb17d06e.zip
ubuntu-advantage: Add new config module to support ubuntu-advantage-tools
ubuntu-advantage-tools is a package for enabling and disabling extended support services such as Extended Security Maintenance (ESM), Canonical Livepatch and FIPS certified PPAs. Simplify Ubuntu Advantage setup on machines by allowing users to provide a list of ubuntu-advantage commands in cloud-config.
Diffstat (limited to 'cloudinit/config/cc_snap.py')
-rw-r--r--cloudinit/config/cc_snap.py47
1 files changed, 2 insertions, 45 deletions
diff --git a/cloudinit/config/cc_snap.py b/cloudinit/config/cc_snap.py
index db965291..34a53fd4 100644
--- a/cloudinit/config/cc_snap.py
+++ b/cloudinit/config/cc_snap.py
@@ -11,6 +11,7 @@ from cloudinit import log as logging
from cloudinit.config.schema import (
get_schema_doc, validate_cloudconfig_schema)
from cloudinit.settings import PER_INSTANCE
+from cloudinit.subp import prepend_base_command
from cloudinit import util
@@ -160,50 +161,6 @@ def add_assertions(assertions):
util.subp(snap_cmd + [ASSERTIONS_FILE], capture=True)
-def prepend_snap_commands(commands):
- """Ensure user-provided commands start with SNAP_CMD, warn otherwise.
-
- Each command is either a list or string. Perform the following:
- - When the command is a list, pop the first element if it is None
- - When the command is a list, insert SNAP_CMD as the first element if
- not present.
- - When the command is a string containing a non-snap command, warn.
-
- Support cut-n-paste snap command sets from public snappy documentation.
- Allow flexibility to provide non-snap environment/config setup if needed.
-
- @commands: List of commands. Each command element is a list or string.
-
- @return: List of 'fixed up' snap commands.
- @raise: TypeError on invalid config item type.
- """
- warnings = []
- errors = []
- fixed_commands = []
- for command in commands:
- if isinstance(command, list):
- if command[0] is None: # Avoid warnings by specifying None
- command = command[1:]
- elif command[0] != SNAP_CMD: # Automatically prepend SNAP_CMD
- command.insert(0, SNAP_CMD)
- elif isinstance(command, str):
- if not command.startswith('%s ' % SNAP_CMD):
- warnings.append(command)
- else:
- errors.append(str(command))
- continue
- fixed_commands.append(command)
-
- if warnings:
- LOG.warning(
- 'Non-snap commands in snap config:\n%s', '\n'.join(warnings))
- if errors:
- raise TypeError(
- 'Invalid snap config.'
- ' These commands are not a string or list:\n' + '\n'.join(errors))
- return fixed_commands
-
-
def run_commands(commands):
"""Run the provided commands provided in snap:commands configuration.
@@ -224,7 +181,7 @@ def run_commands(commands):
'commands parameter was not a list or dict: {commands}'.format(
commands=commands))
- fixed_snap_commands = prepend_snap_commands(commands)
+ fixed_snap_commands = prepend_base_command('snap', commands)
cmd_failures = []
for command in fixed_snap_commands: