diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-12-21 08:56:35 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-12-21 08:56:35 -0500 |
commit | 354854c3a84b586f80da3da7691c3831fa3d7204 (patch) | |
tree | 002bcb60fbe9490951c5d7fe15ed99df1694e29b | |
parent | 7b6da6936cdf690598b6ed16f5c5c254dca19e39 (diff) | |
parent | 64b80e08bc61554e22606edd4153070bcdd18089 (diff) | |
download | vyos-cloud-init-354854c3a84b586f80da3da7691c3831fa3d7204.tar.gz vyos-cloud-init-354854c3a84b586f80da3da7691c3831fa3d7204.zip |
support configuration of landscape-client via cloud-config (LP: #857366)
This adds the ability to configure landscape client code from
cloud-config. The fields available are those that were populated to
/etc/landscape/client.conf when I ran landscape-config on precise
('11.07.1.1-0ubuntu2')
LP: #857366
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_landscape.py | 65 | ||||
-rw-r--r-- | config/cloud.cfg | 1 | ||||
-rw-r--r-- | doc/examples/cloud-config-landscape.txt | 13 |
4 files changed, 80 insertions, 0 deletions
@@ -14,6 +14,7 @@ - put INSTANCE_ID environment variable in bootcmd scripts - add 'cloud-init-per' script for easily running things with a given frequency - replace cloud-init-run-module with cloud-init-per + - support configuration of landscape-client via cloud-config (LP: #857366) 0.6.2: - fix bug where update was not done unless update was explicitly set. It would not be run if 'upgrade' or packages were set to be installed diff --git a/cloudinit/CloudConfig/cc_landscape.py b/cloudinit/CloudConfig/cc_landscape.py new file mode 100644 index 00000000..e3e4f7ba --- /dev/null +++ b/cloudinit/CloudConfig/cc_landscape.py @@ -0,0 +1,65 @@ +# vi: ts=4 expandtab +# +# Copyright (C) 2011 Canonical Ltd. +# +# Author: Scott Moser <scott.moser@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/>. +from cloudinit.CloudConfig import per_instance +from configobj import ConfigObj + +frequency = per_instance + +lsc_client_cfg_file = "/etc/landscape/client.conf" + +# defaults taken from stock client.conf in landscape-client 11.07.1.1-0ubuntu2 +lsc_builtincfg = { + 'client': { + 'log_level': "info", + 'url': "https://landscape.canonical.com/message-system", + 'ping_url': "http://landscape.canonical.com/ping", + 'data_path': "/var/lib/landscape/client", + } +} + +def handle(name,cfg,cloud,log,args): + """ + Basically turn a top level 'landscape' entry with a 'client' dict + and render it to ConfigObj format under '[client]' section in + /etc/landscape/client.conf + """ + + ls_cloudcfg = cfg.get("landscape", { }) + + if not isinstance(ls_cloudcfg, dict): + raise(Exception("'landscape' existed in config, but not a dict")) + + merged = mergeTogether([lsc_builtincfg, lsc_client_cfg_file, ls_cloudcfg]) + + with open(lsc_client_cfg_file, "w") as fp: + merged.write(fp) + + log.debug("updated %s" % lsc_client_cfg_file) + +def mergeTogether(objs): + """ + merge together ConfigObj objects or things that ConfigObj() will take in + later entries override earlier + """ + cfg = ConfigObj({}) + for obj in objs: + if isinstance(obj, ConfigObj): + cfg.merge(obj) + else: + cfg.merge(ConfigObj(obj)) + return cfg diff --git a/config/cloud.cfg b/config/cloud.cfg index 6329fd7d..45538955 100644 --- a/config/cloud.cfg +++ b/config/cloud.cfg @@ -19,6 +19,7 @@ cloud_config_modules: - set-passwords - grub-dpkg - apt-update-upgrade + - landscape - timezone - puppet - chef diff --git a/doc/examples/cloud-config-landscape.txt b/doc/examples/cloud-config-landscape.txt new file mode 100644 index 00000000..12c8101f --- /dev/null +++ b/doc/examples/cloud-config-landscape.txt @@ -0,0 +1,13 @@ +# Landscape-client configuration +# +# Anything under the top 'landscape: client' entry +# will be basically rendered into a ConfigObj formated file +# under the '[client]' section of /etc/landscape/client.conf +# +landscape: + client: + url: "https://landscape.canonical.com/message-system" + ping_url: "http://landscape.canonical.com/ping" + data_path: "/var/lib/landscape/client" + http_proxy: "http://my.proxy.com/foobar" + tags: [ server, cloud ] |