Skip to content

Commit 1e588f0

Browse files
committed
add option apt_pipelining to cloud-config to address s3 mirrors (LP: #948461)
Thanks to Ben Howard.
2 parents e40c7c0 + 91c1ef6 commit 1e588f0

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
- DataSourceNoCloud: support seed from external disk of ISO or vfat (LP: #857378)
2929
- DataSourceNoCloud: support inserting /etc/network/interfaces
3030
- DataSourceMaaS: add data source for Ubuntu Machines as a Service (MaaS) (LP: #942061)
31+
- add option 'apt_pipelining' to address issue with S3 mirrors
32+
(LP: #948461) [Ben Howard]
3133
0.6.2:
3234
- fix bug where update was not done unless update was explicitly set.
3335
It would not be run if 'upgrade' or packages were set to be installed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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)

config/cloud.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cloud_config_modules:
1919
- locale
2020
- set-passwords
2121
- grub-dpkg
22+
- apt-pipelining
2223
- apt-update-upgrade
2324
- landscape
2425
- timezone

doc/examples/cloud-config.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ apt_mirror_search:
4545
# apt_proxy (configure Acquire::HTTP::Proxy)
4646
apt_proxy: http://my.apt.proxy:3128
4747

48+
# apt_pipelining (configure Acquire::http::Pipeline-Depth)
49+
# Default: disables HTTP pipelining. Certain web servers, such
50+
# as S3 do not pipeline properly (LP: #948461).
51+
# Valid options:
52+
# False/default: Disables pipelining for APT
53+
# None/Unchanged: Use OS default
54+
# Number: Set pipelining to some number (not recommended)
55+
apt_pipelining: False
56+
4857
# Preserve existing /etc/apt/sources.list
4958
# Default: overwrite sources_list with mirror. If this is true
5059
# then apt_mirror above will have no effect

0 commit comments

Comments
 (0)