diff options
-rw-r--r-- | cloudinit/CloudConfig/cc_apt_pipelining.py | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/cloudinit/CloudConfig/cc_apt_pipelining.py b/cloudinit/CloudConfig/cc_apt_pipelining.py index c1e65847..7ca93e66 100644 --- a/cloudinit/CloudConfig/cc_apt_pipelining.py +++ b/cloudinit/CloudConfig/cc_apt_pipelining.py @@ -17,54 +17,37 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import cloudinit.util as util -import re -import os from cloudinit.CloudConfig import per_instance frequency = per_instance default_file = "/etc/apt/apt.conf.d/90cloud-init-pipeling" -def handle(_name, cfg, cloud, log, _args): + +def handle(_name, cfg, _cloud, log, _args): apt_pipe_value = util.get_cfg_option_str(cfg, "apt_pipelining", False) apt_pipe_value = str(apt_pipe_value).lower() - if apt_pipe_value in ("false", "default", False): - write_apt_snippet(0, log) + if apt_pipe_value == "false": + write_apt_snippet("0", log) elif apt_pipe_value in ("none", "unchanged", "os"): return - elif apt_pipe_value in str(range(1, 5)): + elif apt_pipe_value in str(range(0, 6)): write_apt_snippet(apt_pipe_value, log) else: - log.warn("Invalid option for apt_pipeling") + log.warn("Invalid option for apt_pipeling: %s" % apt_pipe_value) + def write_apt_snippet(setting, log, f_name=default_file): - """ - Reads f_name and determines if the setting matches or not. Sets to - desired value - """ + """ Writes f_name with apt pipeline depth 'setting' """ acquire_pipeline_depth = 'Acquire::http::Pipeline-Depth "%s";\n' - try: - if os.path.exists(f_name): - skip_re = re.compile('^//CLOUD-INIT-IGNORE.*') - - for line in tweak.readlines(): - if skip_re.match(line): - tweak.close() - return - - tweak.close() - - file_contents = ("//Cloud-init Tweaks\n//Disables APT HTTP pipelining"\ - "\n" + (acquire_pipeline_depth % setting)) - - util.write_file(f_name, file_contents) + file_contents = ("//Written by cloud-init per 'apt_pipelining'\n" + + (acquire_pipeline_depth % setting)) - log.debug("Wrote %s with APT pipeline setting" % f_name ) + util.write_file(f_name, file_contents) - except IOError as e: - log.debug("Unable to update pipeline settings in %s\n%s" % (f_name, e)) + log.debug("Wrote %s with APT pipeline setting" % f_name) |