generate ruby config via plc-config. Required by puppet
authorS.Çağlar Onur <caglar@verivue.com>
Tue, 3 May 2011 19:04:29 +0000 (15:04 -0400)
committerS.Çağlar Onur <caglar@verivue.com>
Tue, 3 May 2011 19:04:29 +0000 (15:04 -0400)
plc-config
plc.init
plc_config.py

index 78fc6db..ad638dd 100755 (executable)
@@ -27,6 +27,7 @@ Usage: %s [OPTION]... [FILES]
         --shell         Output shell configuration file
         --python        Output Python configuration file
         --php           Output PHP configuration file
+        --ruby          Output Ruby configuration file
 
         Information:
 
@@ -72,6 +73,7 @@ def main():
     # Standard options
     shortopts = "hs:"
     longopts = ["shell", "bash", "python",
+                "ruby",
                 "php",
                 "xml",
                 "variables",
@@ -94,6 +96,8 @@ def main():
              opt == "--bash" or \
              opt == "--python":
             output = plc.output_shell
+        elif opt == "--ruby":
+            output = plc.output_ruby
         elif opt == "--php":
             output = plc.output_php
         elif opt == "--xml":
index 0617516..2e9e825 100755 (executable)
--- a/plc.init
+++ b/plc.init
@@ -81,6 +81,9 @@ reload ()
     if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config.py ] ; then
        plc-config --python >/etc/planetlab/plc_config.py
     fi
+    if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config.rb ] ; then
+       plc-config --ruby >/etc/planetlab/plc_config.rb
+    fi
     if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/php/plc_config.php ] ; then
        mkdir -p /etc/planetlab/php
        plc-config --php >/etc/planetlab/php/plc_config.php
index fcab1f6..07097f3 100644 (file)
@@ -719,6 +719,31 @@ DO NOT EDIT. This file was automatically generated at
 
         return buf.getvalue()
 
+    def output_ruby(self, show_comments = True, encoding = "utf-8"):
+        """
+        Return variables as a shell script.
+        """
+
+        buf = codecs.lookup(encoding)[3](StringIO())
+        buf.writelines(["# " + line + os.linesep for line in self._header()])
+
+        for (category_id, (category, variables)) in self._variables.iteritems():
+            for variable in variables.values():
+                (id, name, value, comments) = self._sanitize_variable(category_id, variable)
+                if show_comments:
+                    buf.write(os.linesep)
+                    if name is not None:
+                        buf.write("# " + name + os.linesep)
+                    if comments is not None:
+                        buf.writelines(["# " + line + os.linesep for line in comments])
+                # bash does not have the concept of NULL
+                if value is not None:
+                    buf.write("$" + id + "=" + value + os.linesep)
+
+        return buf.getvalue()
+
+
+
 
     def output_php(self, encoding = "utf-8"):
         """