summaryrefslogtreecommitdiff
path: root/cloudinit/distros
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2013-12-14 14:17:31 -0500
committerScott Moser <smoser@ubuntu.com>2013-12-14 14:17:31 -0500
commit923a7d0efc3cf3224b891dc783321018d59ce33e (patch)
tree97230fcdef1b75e49da2d91d25c80def2f86a60a /cloudinit/distros
parent6af4aefbabdb38f5a3077554b458dd1f5a67f22a (diff)
downloadvyos-cloud-init-923a7d0efc3cf3224b891dc783321018d59ce33e.tar.gz
vyos-cloud-init-923a7d0efc3cf3224b891dc783321018d59ce33e.zip
support calling apt with eatmydata, enable by default if available.
This allows a general config option to prefix apt-get commands via 'apt_get_wrapper'. By default, the command is set to 'eatmydata', and the mode set to 'auto'. That means if eatmydata is available (via which), it will use it. The 'command' can be either a array or a string. LP: #1236531
Diffstat (limited to 'cloudinit/distros')
-rw-r--r--cloudinit/distros/debian.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index 8fe49cbe..1ae232fd 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -36,6 +36,10 @@ LOG = logging.getLogger(__name__)
APT_GET_COMMAND = ('apt-get', '--option=Dpkg::Options::=--force-confold',
'--option=Dpkg::options::=--force-unsafe-io',
'--assume-yes', '--quiet')
+APT_GET_WRAPPER = {
+ 'command': 'eatmydata',
+ 'enabled': 'auto',
+}
class Distro(distros.Distro):
@@ -148,7 +152,13 @@ class Distro(distros.Distro):
# See: http://tiny.cc/kg91fw
# Or: http://tiny.cc/mh91fw
e['DEBIAN_FRONTEND'] = 'noninteractive'
- cmd = list(self.get_option("apt_get_command", APT_GET_COMMAND))
+
+ wcfg = self.get_option("apt_get_wrapper", APT_GET_WRAPPER)
+ cmd = _get_wrapper_prefix(
+ wcfg.get('command', APT_GET_WRAPPER['command']),
+ wcfg.get('enabled', APT_GET_WRAPPER['enabled']))
+
+ cmd.extend(list(self.get_option("apt_get_command", APT_GET_COMMAND)))
if args and isinstance(args, str):
cmd.append(args)
@@ -166,7 +176,9 @@ class Distro(distros.Distro):
cmd.extend(pkglist)
# Allow the output of this to flow outwards (ie not be captured)
- util.subp(cmd, env=e, capture=False)
+ util.log_time(logfunc=LOG.debug,
+ msg="apt-%s [%s]" % (command, ' '.join(cmd)), func=util.subp,
+ args=(cmd,), kwargs={'env': e, 'capture': False})
def update_package_sources(self):
self._runner.run("update-sources", self.package_command,
@@ -175,3 +187,15 @@ class Distro(distros.Distro):
def get_primary_arch(self):
(arch, _err) = util.subp(['dpkg', '--print-architecture'])
return str(arch).strip()
+
+
+def _get_wrapper_prefix(cmd, mode):
+ if isinstance(cmd, str):
+ cmd = [str(cmd)]
+
+ if (util.is_true(mode) or
+ (str(mode).lower() == "auto" and cmd[0] and
+ util.which(cmd[0]))):
+ return cmd
+ else:
+ return []