|
| 1 | +# vi: ts=4 expandtab |
| 2 | +# |
| 3 | +# Copyright (C) 2011 Canonical Ltd. |
| 4 | +# |
| 5 | +# Author: Ben Howard <ben.howard@canonical.com> |
| 6 | +# |
| 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. |
| 10 | +# |
| 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. |
| 15 | +# |
| 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/>. |
| 18 | + |
| 19 | +import cloudinit.util as util |
| 20 | +from cloudinit.CloudConfig import per_instance |
| 21 | + |
| 22 | +frequency = per_instance |
| 23 | +default_file = "/etc/apt/apt.conf.d/90cloud-init-pipeling" |
| 24 | + |
| 25 | + |
| 26 | +def handle(_name, cfg, _cloud, log, _args): |
| 27 | + |
| 28 | + apt_pipe_value = util.get_cfg_option_str(cfg, "apt_pipelining", False) |
| 29 | + apt_pipe_value = str(apt_pipe_value).lower() |
| 30 | + |
| 31 | + if apt_pipe_value == "false": |
| 32 | + write_apt_snippet("0", log) |
| 33 | + |
| 34 | + elif apt_pipe_value in ("none", "unchanged", "os"): |
| 35 | + return |
| 36 | + |
| 37 | + elif apt_pipe_value in str(range(0, 6)): |
| 38 | + write_apt_snippet(apt_pipe_value, log) |
| 39 | + |
| 40 | + else: |
| 41 | + log.warn("Invalid option for apt_pipeling: %s" % apt_pipe_value) |
| 42 | + |
| 43 | + |
| 44 | +def write_apt_snippet(setting, log, f_name=default_file): |
| 45 | + """ Writes f_name with apt pipeline depth 'setting' """ |
| 46 | + |
| 47 | + acquire_pipeline_depth = 'Acquire::http::Pipeline-Depth "%s";\n' |
| 48 | + file_contents = ("//Written by cloud-init per 'apt_pipelining'\n" |
| 49 | + + (acquire_pipeline_depth % setting)) |
| 50 | + |
| 51 | + util.write_file(f_name, file_contents) |
| 52 | + |
| 53 | + log.debug("Wrote %s with APT pipeline setting" % f_name) |
0 commit comments