3
# Copyright (C) 2011 Canonical Ltd.
4
# Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
6
# Author: Scott Moser <scott.moser@canonical.com>
7
# Author: Juerg Haefliger <juerg.haefliger@hp.com>
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License version 3, as
11
# published by the Free Software Foundation.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
from StringIO import StringIO
25
from configobj import ConfigObj
27
from cloudinit import util
29
from cloudinit.settings import PER_INSTANCE
31
frequency = PER_INSTANCE
33
LSC_CLIENT_CFG_FILE = "/etc/landscape/client.conf"
37
# defaults taken from stock client.conf in landscape-client 11.07.1.1-0ubuntu2
41
'url': "https://landscape.canonical.com/message-system",
42
'ping_url': "http://landscape.canonical.com/ping",
43
'data_path': "/var/lib/landscape/client",
48
def handle(_name, cfg, cloud, log, _args):
50
Basically turn a top level 'landscape' entry with a 'client' dict
51
and render it to ConfigObj format under '[client]' section in
52
/etc/landscape/client.conf
55
ls_cloudcfg = cfg.get("landscape", {})
57
if not isinstance(ls_cloudcfg, (dict)):
58
raise RuntimeError(("'landscape' key existed in config,"
59
" but not a dictionary type,"
60
" is a %s instead"), util.obj_name(ls_cloudcfg))
64
cloud.paths.join(True, LSC_CLIENT_CFG_FILE),
67
merged = merge_together(merge_data)
69
lsc_client_fn = cloud.paths.join(False, LSC_CLIENT_CFG_FILE)
70
lsc_dir = cloud.paths.join(False, os.path.dirname(lsc_client_fn))
71
if not os.path.isdir(lsc_dir):
72
util.ensure_dir(lsc_dir)
75
merged.write(contents)
78
util.write_file(lsc_client_fn, contents.getvalue())
79
log.debug("Wrote landscape config file to %s", lsc_client_fn)
82
def merge_together(objs):
84
merge together ConfigObj objects or things that ConfigObj() will take in
85
later entries override earlier
91
if isinstance(obj, ConfigObj):
94
cfg.merge(ConfigObj(obj))