Blob Blame History Raw
diff -ru cobbler-2.0.7/cobbler/action_power.py cobbler-2.0.7-new/cobbler/action_power.py
--- cobbler-2.0.7/cobbler/action_power.py	2010-07-28 17:48:48.000000000 +0200
+++ cobbler-2.0.7-new/cobbler/action_power.py	2012-06-11 11:16:06.409111259 +0200
@@ -36,6 +36,7 @@
 from cexceptions import *
 import templar
 import clogger
+import shlex

 class PowerTool:
     """
@@ -68,8 +69,9 @@
         interested in maximum security should take that route.
         """
 
-        template = self.get_command_template()
-        template_file = open(template, "r")
+        power_command = utils.get_power(self.system.power_type)
+        if not power_command:
+            utils.die(self.logger,"no power type set for system")
 
         meta = utils.blender(self.api, False, self.system)
         meta["power_mode"] = desired_state
@@ -80,35 +82,27 @@
         if self.force_pass is not None:
            meta["power_pass"] = self.force_pass
 
-        tmp = templar.Templar(self.api._config)
-        cmd = tmp.render(template_file, meta, None, self.system)
-        template_file.close()
-
-        cmd = cmd.strip()
-
         self.logger.info("cobbler power configuration is:")
-
         self.logger.info("      type   : %s" % self.system.power_type)
         self.logger.info("      address: %s" % self.system.power_address)
         self.logger.info("      user   : %s" % self.system.power_user)
         self.logger.info("      id     : %s" % self.system.power_id)
 
         # if no username/password data, check the environment
-
         if meta.get("power_user","") == "":
             meta["power_user"] = os.environ.get("COBBLER_POWER_USER","")
         if meta.get("power_pass","") == "":
             meta["power_pass"] = os.environ.get("COBBLER_POWER_PASS","")
 
-        self.logger.info("- %s" % cmd)
-
-        # use shell so we can have mutliple power commands chained together
-        cmd = ['/bin/sh','-c', cmd]
+        template = utils.get_power_template(self.system.power_type)
+        tmp = templar.Templar(self.api._config)
+        template_data = tmp.render(template, meta, None, self.system)
+        template_command = shlex.split(str(template_data))
 
         # Try the power command 5 times before giving up.
         # Some power switches are flakey
         for x in range(0,5):
-            rc = utils.subprocess_call(self.logger, cmd, shell=False)
+            rc = utils.subprocess_call(self.logger, template_command, shell=False)
             if rc == 0:
                 break
             else:
@@ -119,19 +113,3 @@
 
         return rc
 
-    def get_command_template(self):
-
-        """
-        In case the user wants to customize the power management commands, 
-        we source the code for each command from /etc/cobbler and run
-        them through Cheetah.
-        """
-
-        if self.system.power_type in [ "", "none" ]:
-            utils.die(self.logger,"Power management is not enabled for this system")
-
-        result = utils.get_power(self.system.power_type)
-        if not result:
-            utils.die(self.logger, "Invalid power management type for this system (%s, %s)" % (self.system.power_type, self.system.name))
-        return result
-
diff -ru cobbler-2.0.7/cobbler/item_system.py cobbler-2.0.7-new/cobbler/item_system.py
--- cobbler-2.0.7/cobbler/item_system.py	2010-07-28 17:48:48.000000000 +0200
+++ cobbler-2.0.7-new/cobbler/item_system.py	2012-06-11 11:16:06.410111268 +0200
@@ -50,11 +50,11 @@
   ["virt_auto_boot","<<inherit>>",0,"Virt Auto Boot",True,"Auto boot this VM?",0,"bool"],
   ["ctime",0,0,"",False,"",0,"float"],
   ["mtime",0,0,"",False,"",0,"float"],
-  ["power_type","SETTINGS:power_management_default_type",0,"Power Management Type",True,"",utils.get_power_types(),"str"],
+  ["power_type","SETTINGS:power_management_default_type",0,"Power Management Type",True,"Power management script to use",utils.get_power_types(),"str"],
   ["power_address","",0,"Power Management Address",True,"Ex: power-device.example.org",0,"str"],
-  ["power_user","",0,"Power Username ",True,"",0,"str"],
-  ["power_pass","",0,"Power Password",True,"",0,"str"],
-  ["power_id","",0,"Power ID",True,"Usually a plug number or blade name, if power type requires it",0,"str"],
+  ["power_user","",0,"Power Management Username ",True,"",0,"str"],
+  ["power_pass","",0,"Power Management Password",True,"",0,"str"],
+  ["power_id","",0,"Power Management ID",True,"Usually a plug number or blade name, if power type requires it",0,"str"],
   ["hostname","",0,"Hostname",True,"",0,"str"],
   ["gateway","",0,"Gateway",True,"",0,"str"],
   ["name_servers",[],0,"Name Servers",True,"space delimited",0,"list"],
diff -ru cobbler-2.0.7/cobbler/utils.py cobbler-2.0.7-new/cobbler/utils.py
--- cobbler-2.0.7/cobbler/utils.py	2012-06-11 11:19:10.469232289 +0200
+++ cobbler-2.0.7-new/cobbler/utils.py	2012-06-11 11:18:39.660541633 +0200
@@ -1846,6 +1846,20 @@
             return powerpath
     return None
 
+def get_power_template(powertype=None):
+    """
+    Return power template for type
+    """
+    if powertype:
+        powertemplate = "/etc/cobbler/power/power_%s.template" % powertype
+        if os.path.isfile(powertemplate):
+            f = open(powertemplate)
+            template = f.read()
+            f.close()
+            return template
+    # return a generic template if a specific one wasn't found
+    return "action=$power_mode\nlogin=$power_user\npasswd=$power_pass\nipaddr=$power_address\nport=$power_id"
+
 def get_shared_secret():
     """
     The 'web.ss' file is regenerated each time cobblerd restarts and is