Merge lp:~lynxman/cloud-init/puppet-mcollective into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Marc Cluet
Status: Merged
Merged at revision: 368
Proposed branch: lp:~lynxman/cloud-init/puppet-mcollective
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 125 lines (+85/-4)
2 files modified
cloudinit/CloudConfig/cc_mcollective.py (+63/-0)
cloudinit/CloudConfig/cc_puppet.py (+22/-4)
To merge this branch: bzr merge lp:~lynxman/cloud-init/puppet-mcollective
Reviewer Review Type Date Requested Status
Scott Moser Needs Fixing
Review via email: mp+49819@code.launchpad.net

Description of the change

Modified puppet module to try to replace values on the existing file instead of adding new values to the end

Also added initial mcollective module

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

It looks good except, I'd like a doc/examples/cloud-config-mcollective.txt
or a section in doc/examples/cloud-config.txt that would explain the mcollective configurations.

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'cloudinit/CloudConfig/cc_mcollective.py'
--- cloudinit/CloudConfig/cc_mcollective.py 1970-01-01 00:00:00 +0000
+++ cloudinit/CloudConfig/cc_mcollective.py 2011-02-15 14:53:56 +0000
@@ -0,0 +1,63 @@
1# vi: ts=4 expandtab
2#
3# Copyright (C) 2009-2011 Canonical Ltd.
4#
5# Author: Marc Cluet <marc.cluet@canonical.com>
6# Based on code by Scott Moser <scott.moser@canonical.com>
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License version 3, as
10# published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19import os
20import pwd
21import socket
22import subprocess
23import StringIO
24import ConfigParser
25import cloudinit.CloudConfig as cc
26
27# Our fake header section
28class FakeSecHead(object):
29 def __init__(self, fp):
30 self.fp = fp
31 self.sechead = '[nullsection]\n'
32 def readline(self):
33 if self.sechead:
34 try: return self.sechead
35 finally: self.sechead = None
36 else: return self.fp.readline()
37
38def handle(name,cfg,cloud,log,args):
39 # If there isn't a mcollective key in the configuration don't do anything
40 if not cfg.has_key('mcollective'): return
41 mcollective_cfg = cfg['mcollective']
42 # Start by installing the mcollective package ...
43 cc.install_packages(("mcollective",))
44
45 # ... and then update the mcollective configuration
46 if mcollective_cfg.has_key('conf'):
47 # Create object for reading server.cfg values
48 mcollective_config = ConfigParser.ConfigParser()
49 # Read server.cfg values from original file in order to be able to mix the rest up
50 mcollective_config.readfp(FakeSecHead(open('/etc/mcollective/server.cfg')))
51 for cfg_name, cfg in mcollective_cfg['conf'].iteritems():
52 # Iterate throug the config items, we'll use ConfigParser.set
53 # to overwrite or create new items as needed
54 for o, v in cfg.iteritems():
55 mcollective_config.set(cfg_name,o,v)
56 # We got all our config as wanted we'll rename
57 # the previous server.cfg and create our new one
58 os.rename('/etc/mcollective/server.cfg','/etc/mcollective/server.cfg.old')
59 with open('/etc/mcollective/server.cfg', 'wb') as configfile:
60 mcollective_config.write(configfile)
61 # Start mcollective
62 subprocess.check_call(['service', 'mcollective', 'start'])
63
064
=== modified file 'cloudinit/CloudConfig/cc_puppet.py'
--- cloudinit/CloudConfig/cc_puppet.py 2011-02-07 19:43:40 +0000
+++ cloudinit/CloudConfig/cc_puppet.py 2011-02-15 14:53:56 +0000
@@ -19,6 +19,8 @@
19import pwd19import pwd
20import socket20import socket
21import subprocess21import subprocess
22import StringIO
23import ConfigParser
22import cloudinit.CloudConfig as cc24import cloudinit.CloudConfig as cc
2325
24def handle(name,cfg,cloud,log,args):26def handle(name,cfg,cloud,log,args):
@@ -31,7 +33,13 @@
31 # ... and then update the puppet configuration33 # ... and then update the puppet configuration
32 if puppet_cfg.has_key('conf'):34 if puppet_cfg.has_key('conf'):
33 # Add all sections from the conf object to puppet.conf35 # Add all sections from the conf object to puppet.conf
34 puppet_conf_fh = open('/etc/puppet/puppet.conf', 'a')36 puppet_conf_fh = open('/etc/puppet/puppet.conf', 'r')
37 # Create object for reading puppet.conf values
38 puppet_config = ConfigParser.ConfigParser()
39 # Read puppet.conf values from original file in order to be able to mix the rest up
40 puppet_config.readfp(StringIO.StringIO(''.join(i.lstrip() for i in puppet_conf_fh.readlines())))
41 # Close original file, no longer needed
42 puppet_conf_fh.close()
35 for cfg_name, cfg in puppet_cfg['conf'].iteritems():43 for cfg_name, cfg in puppet_cfg['conf'].iteritems():
36 # ca_cert configuration is a special case44 # ca_cert configuration is a special case
37 # Dump the puppetmaster ca certificate in the correct place45 # Dump the puppetmaster ca certificate in the correct place
@@ -51,7 +59,12 @@
51 os.chown('/var/lib/puppet/ssl/certs/ca.pem',59 os.chown('/var/lib/puppet/ssl/certs/ca.pem',
52 pwd.getpwnam('puppet').pw_uid, 0)60 pwd.getpwnam('puppet').pw_uid, 0)
53 else:61 else:
54 puppet_conf_fh.write("\n[%s]\n" % (cfg_name))62 #puppet_conf_fh.write("\n[%s]\n" % (cfg_name))
63 # If puppet.conf already has this section we don't want to write it again
64 if puppet_config.has_section(cfg_name) == False
65 puppet_config.add_section(cfg_name)
66 # Iterate throug the config items, we'll use ConfigParser.set
67 # to overwrite or create new items as needed
55 for o, v in cfg.iteritems():68 for o, v in cfg.iteritems():
56 if o == 'certname':69 if o == 'certname':
57 # Expand %f as the fqdn70 # Expand %f as the fqdn
@@ -61,8 +74,13 @@
61 cloud.datasource.get_instance_id())74 cloud.datasource.get_instance_id())
62 # certname needs to be downcase75 # certname needs to be downcase
63 v = v.lower()76 v = v.lower()
64 puppet_conf_fh.write("%s=%s\n" % (o, v))77 puppet_config.set(cfg_name,o,v)
65 puppet_conf_fh.close()78 #puppet_conf_fh.write("%s=%s\n" % (o, v))
79 # We got all our config as wanted we'll rename
80 # the previous puppet.conf and create our new one
81 os.rename('/etc/puppet/puppet.conf','/etc/puppet/puppet.conf.old')
82 with open('/etc/puppet/puppet.conf', 'wb') as configfile:
83 puppet_config.write(configfile)
66 # Set puppet default file to automatically start84 # Set puppet default file to automatically start
67 subprocess.check_call(['sed', '-i',85 subprocess.check_call(['sed', '-i',
68 '-e', 's/^START=.*/START=yes/',86 '-e', 's/^START=.*/START=yes/',