summaryrefslogtreecommitdiff
path: root/cloudinit/CloudConfig
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/CloudConfig')
-rw-r--r--cloudinit/CloudConfig/cc_apt_pipelining.py53
-rw-r--r--cloudinit/CloudConfig/cc_resizefs.py4
-rw-r--r--cloudinit/CloudConfig/cc_salt_minion.py56
-rw-r--r--cloudinit/CloudConfig/cc_update_etc_hosts.py2
4 files changed, 112 insertions, 3 deletions
diff --git a/cloudinit/CloudConfig/cc_apt_pipelining.py b/cloudinit/CloudConfig/cc_apt_pipelining.py
new file mode 100644
index 00000000..0286a9ae
--- /dev/null
+++ b/cloudinit/CloudConfig/cc_apt_pipelining.py
@@ -0,0 +1,53 @@
+# vi: ts=4 expandtab
+#
+# Copyright (C) 2011 Canonical Ltd.
+#
+# Author: Ben Howard <ben.howard@canonical.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import cloudinit.util as util
+from cloudinit.CloudConfig import per_instance
+
+frequency = per_instance
+default_file = "/etc/apt/apt.conf.d/90cloud-init-pipelining"
+
+
+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 == "false":
+ write_apt_snippet("0", log)
+
+ elif apt_pipe_value in ("none", "unchanged", "os"):
+ return
+
+ elif apt_pipe_value in str(range(0, 6)):
+ write_apt_snippet(apt_pipe_value, log)
+
+ else:
+ log.warn("Invalid option for apt_pipeling: %s" % apt_pipe_value)
+
+
+def write_apt_snippet(setting, log, f_name=default_file):
+ """ Writes f_name with apt pipeline depth 'setting' """
+
+ acquire_pipeline_depth = 'Acquire::http::Pipeline-Depth "%s";\n'
+ file_contents = ("//Written by cloud-init per 'apt_pipelining'\n"
+ + (acquire_pipeline_depth % setting))
+
+ util.write_file(f_name, file_contents)
+
+ log.debug("Wrote %s with APT pipeline setting" % f_name)
diff --git a/cloudinit/CloudConfig/cc_resizefs.py b/cloudinit/CloudConfig/cc_resizefs.py
index 0186d4d2..c76cc664 100644
--- a/cloudinit/CloudConfig/cc_resizefs.py
+++ b/cloudinit/CloudConfig/cc_resizefs.py
@@ -49,8 +49,8 @@ def handle(_name, cfg, _cloud, log, args):
dev = os.makedev(os.major(st_dev), os.minor(st_dev))
os.mknod(devpth, 0400 | stat.S_IFBLK, dev)
except:
- if util.islxc():
- log.debug("inside lxc, ignoring mknod failure in resizefs")
+ if util.is_container():
+ log.debug("inside container, ignoring mknod failure in resizefs")
return
log.warn("Failed to make device node to resize /")
raise
diff --git a/cloudinit/CloudConfig/cc_salt_minion.py b/cloudinit/CloudConfig/cc_salt_minion.py
new file mode 100644
index 00000000..1a3b5039
--- /dev/null
+++ b/cloudinit/CloudConfig/cc_salt_minion.py
@@ -0,0 +1,56 @@
+# vi: ts=4 expandtab
+#
+# Author: Jeff Bauer <jbauer@rubic.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import os.path
+import subprocess
+import cloudinit.CloudConfig as cc
+import yaml
+
+
+def handle(_name, cfg, _cloud, _log, _args):
+ # If there isn't a salt key in the configuration don't do anything
+ if 'salt_minion' not in cfg:
+ return
+ salt_cfg = cfg['salt_minion']
+ # Start by installing the salt package ...
+ cc.install_packages(("salt",))
+ config_dir = '/etc/salt'
+ if not os.path.isdir(config_dir):
+ os.makedirs(config_dir)
+ # ... and then update the salt configuration
+ if 'conf' in salt_cfg:
+ # Add all sections from the conf object to /etc/salt/minion
+ minion_config = os.path.join(config_dir, 'minion')
+ yaml.dump(salt_cfg['conf'],
+ file(minion_config, 'w'),
+ default_flow_style=False)
+ # ... copy the key pair if specified
+ if 'public_key' in salt_cfg and 'private_key' in salt_cfg:
+ pki_dir = '/etc/salt/pki'
+ cumask = os.umask(077)
+ if not os.path.isdir(pki_dir):
+ os.makedirs(pki_dir)
+ pub_name = os.path.join(pki_dir, 'minion.pub')
+ pem_name = os.path.join(pki_dir, 'minion.pem')
+ with open(pub_name, 'w') as f:
+ f.write(salt_cfg['public_key'])
+ with open(pem_name, 'w') as f:
+ f.write(salt_cfg['private_key'])
+ os.umask(cumask)
+
+ # Start salt-minion
+ subprocess.check_call(['service', 'salt-minion', 'start'])
diff --git a/cloudinit/CloudConfig/cc_update_etc_hosts.py b/cloudinit/CloudConfig/cc_update_etc_hosts.py
index 572e6750..6ad2fca8 100644
--- a/cloudinit/CloudConfig/cc_update_etc_hosts.py
+++ b/cloudinit/CloudConfig/cc_update_etc_hosts.py
@@ -28,7 +28,7 @@ frequency = per_always
def handle(_name, cfg, cloud, log, _args):
(hostname, fqdn) = util.get_hostname_fqdn(cfg, cloud)
- manage_hosts = util.get_cfg_option_bool(cfg, "manage_etc_hosts", False)
+ manage_hosts = util.get_cfg_option_str(cfg, "manage_etc_hosts", False)
if manage_hosts in ("True", "true", True, "template"):
# render from template file
try: