summaryrefslogtreecommitdiff
path: root/cloudinit/CloudConfig/cc_apt_pipelining.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-03-09 09:50:04 -0500
committerScott Moser <smoser@ubuntu.com>2012-03-09 09:50:04 -0500
commit210dfb8840baded8a2282e8b0b49c3a034222bd8 (patch)
tree29ccbbc2b32a48eac6a58393a026377cba6c2079 /cloudinit/CloudConfig/cc_apt_pipelining.py
parent162762d916c18ad83a6775cc1bd9a86cb78a5dd7 (diff)
downloadcloud-init-git-210dfb8840baded8a2282e8b0b49c3a034222bd8.tar.gz
Some cleanups before merge.
* removed the 'CLOUD-INIT-IGNORE' section, as we're just blindly writing the file now. removed the now-unnecessary import of 're' and 'os' * removed try/except block around write_apt_snippet. This will bubble up and cloud-init will let it through even to the console. Catching it and turning it into a debug would just hide it. * removed 'default' as a synonym for 'whatever cloud-init thinks is best' If people are going to change this, I'd rather they be specific. * supported value of "0" * fixed some complaints from ./tools/run-pylint cloudinit/CloudConfig/cc_apt_pipelining.py
Diffstat (limited to 'cloudinit/CloudConfig/cc_apt_pipelining.py')
-rw-r--r--cloudinit/CloudConfig/cc_apt_pipelining.py41
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)