3
# Copyright (C) 2011 Canonical Ltd.
5
# Author: Ben Howard <ben.howard@canonical.com>
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License version 3, as
9
# published by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
from cloudinit.settings import PER_INSTANCE
20
from cloudinit import util
22
frequency = PER_INSTANCE
24
distros = ['ubuntu', 'debian']
26
DEFAULT_FILE = "/etc/apt/apt.conf.d/90cloud-init-pipelining"
28
APT_PIPE_TPL = ("//Written by cloud-init per 'apt_pipelining'\n"
29
'Acquire::http::Pipeline-Depth "%s";\n')
31
# Acquire::http::Pipeline-Depth can be a value
32
# from 0 to 5 indicating how many outstanding requests APT should send.
33
# A value of zero MUST be specified if the remote host does not properly linger
34
# on TCP connections - otherwise data corruption will occur.
37
def handle(_name, cfg, _cloud, log, _args):
39
apt_pipe_value = util.get_cfg_option_str(cfg, "apt_pipelining", False)
40
apt_pipe_value_s = str(apt_pipe_value).lower().strip()
42
if apt_pipe_value_s == "false":
43
write_apt_snippet("0", log, DEFAULT_FILE)
44
elif apt_pipe_value_s in ("none", "unchanged", "os"):
46
elif apt_pipe_value_s in [str(b) for b in range(0, 6)]:
47
write_apt_snippet(apt_pipe_value_s, log, DEFAULT_FILE)
49
log.warn("Invalid option for apt_pipeling: %s", apt_pipe_value)
52
def write_apt_snippet(setting, log, f_name):
53
"""Writes f_name with apt pipeline depth 'setting'."""
55
file_contents = APT_PIPE_TPL % (setting)
56
util.write_file(f_name, file_contents)
57
log.debug("Wrote %s with apt pipeline depth setting %s", f_name, setting)