[node-patches] Change in ovirt-node[master]: puppet: add disable_puppet function into puppet_page

hadong0720 at gmail.com hadong0720 at gmail.com
Fri Oct 25 03:47:05 UTC 2013


hadong has uploaded a new change for review.

Change subject: puppet: add disable_puppet function into puppet_page
......................................................................

puppet: add disable_puppet function into puppet_page

Change-Id: I942252e228e9475c4c41e893aae6507b9505e245
Signed-off-by: hadong <hadong0720 at gmail.com>
---
M src/ovirt/node/setup/puppet/puppet_page.py
1 file changed, 61 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/38/20538/1

diff --git a/src/ovirt/node/setup/puppet/puppet_page.py b/src/ovirt/node/setup/puppet/puppet_page.py
index 6a016bc..e59d1a2 100644
--- a/src/ovirt/node/setup/puppet/puppet_page.py
+++ b/src/ovirt/node/setup/puppet/puppet_page.py
@@ -130,36 +130,68 @@
         return {"OVIRT_PUPPET_ENABLED": "yes" if enabled else None}
 
 
-class ActivatePuppet(utils.Transaction.Element):
+def enable_puppet():
+    cfg = Puppet().retrieve()
 
-    title = "Activating Puppet"
+    conf = File("/etc/puppet/puppet.conf")
+    conf_builder = ""
+    for line in conf:
+        try:
+            item = re.match(r'^#?\s+(\w+) =', line).group(1)
+            if item in cfg and cfg[item] is not '':
+                if re.match(r'^#.*', line):
+                    line = re.sub(r'^#', '', line)
+                conf_builder += re.sub(r'(^.*?' + item + ' =).*',
+                                       r'\1 "' + cfg[item] + '"',
+                                       line)
+            else:
+                conf_builder += line
+        except:
+            conf_builder += line
+
+    conf.write(conf_builder, "w")
+    fs.Config().persist("/etc/puppet/puppet.conf")
+
+    system.service("puppet", "stop")
+    utils.process.check_call("puppet agent --waitforcert 60 --test",
+                                 shell=True)
+    system.service("puppet", "start")
+
+
+def disable_puppet():
+    item_args = ["server", "certname"]
+
+    conf = File("/etc/puppet/puppet.conf")
+    conf_builder = ""
+    for line in conf:
+        try:
+            item = re.match(r'^\s+(\w+) =', line).group(1)
+            if item in item_args:
+                conf_builder += re.sub(r'(^.*?' + item + ' =).*',
+                                       "#" + r'\1 "''"',
+                                       line)
+            else:
+                conf_builder += line
+        except:
+            conf_builder += line
+
+    conf.write(conf_builder, "w")
+    fs.Config().persist("/etc/puppet/puppet.conf")
+
+    system.service("puppet", "stop")
+
+
+class ActivatePuppet(utils.Transaction.Element):
+    cfg = Puppet().retrieve()
+    enabled = cfg["enabled"]
+    state = ("Enabling" if enabled else "Disabling")
+    title = "%s Puppet" % state
 
     def commit(self):
 
-        self.logger.info("Connecting to Puppet server")
-
-        cfg = Puppet().retrieve()
-
-        conf = File("/etc/puppet/puppet.conf")
-        conf_builder = ""
-        for line in conf:
-            try:
-                item = re.match(r'^#?\s+(\w+) =', line).group(1)
-                if item in cfg and cfg[item] is not '':
-                    if re.match(r'^#.*', line):
-                        line = re.sub(r'^#', '', line)
-                    conf_builder += re.sub(r'(^.*?' + item + ' =).*',
-                                           r'\1 "' + cfg[item] + '"',
-                                           line)
-                else:
-                    conf_builder += line
-            except:
-                conf_builder += line
-
-        conf.write(conf_builder, "w")
-        fs.Config().persist("/etc/puppet/puppet.conf")
-
-        system.service("puppet", "stop")
-        utils.process.check_call("puppet agent --waitforcert 60 --test",
-                                 shell=True)
-        system.service("puppet", "start")
+        if enabled:
+            self.logger.info("Connecting to Puppet server")
+            enable_puppet()
+        else:
+            self.logger.info("Disconnecting to Puppet server")
+            disable_puppet()


-- 
To view, visit http://gerrit.ovirt.org/20538
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I942252e228e9475c4c41e893aae6507b9505e245
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: hadong <hadong0720 at gmail.com>



More information about the node-patches mailing list