Blame SOURCES/cobbler-power-status.patch

1070a0
diff -rupN cobbler-2.0.7.old/cobbler/action_power.py cobbler-2.0.7/cobbler/action_power.py
1070a0
--- cobbler-2.0.7.old/cobbler/action_power.py	2014-11-10 15:07:00.578732736 -0500
1070a0
+++ cobbler-2.0.7/cobbler/action_power.py	2014-11-10 15:11:19.692536590 -0500
1070a0
@@ -30,6 +30,7 @@ import os
1070a0
 import os.path
1070a0
 import traceback
1070a0
 import time
1070a0
+import re
1070a0
 
1070a0
 import utils
1070a0
 import func_utils
1070a0
@@ -102,8 +103,22 @@ class PowerTool:
1070a0
         # Try the power command 5 times before giving up.
1070a0
         # Some power switches are flakey
1070a0
         for x in range(0,5):
1070a0
-            rc = utils.subprocess_call(self.logger, template_command, shell=False)
1070a0
+            output, rc = utils.subprocess_sp(self.logger, template_command, shell=False)
1070a0
             if rc == 0:
1070a0
+                # If the desired state is actually a query for the status
1070a0
+                # return different information than command return code
1070a0
+                if desired_state == 'status':
1070a0
+                    match = re.match('(^Status:\s)(ON|OFF)', output)
1070a0
+                    if not match:
1070a0
+                        match = re.match('(.*Chassis power\s*(=|is)\s*)(On|Off).*', output, re.IGNORECASE)
1070a0
+                    if match:
1070a0
+                        power_status = match.groups()[2]
1070a0
+                        if power_status.upper() == 'ON':
1070a0
+                            return True
1070a0
+                        else:
1070a0
+                            return False
1070a0
+                    utils.die(self.logger,"command succeeded (rc=%s), but output ('%s') was not understood" % (rc, output))
1070a0
+                    return None
1070a0
                 break
1070a0
             else:
1070a0
                 time.sleep(2)
1070a0
diff -rupN cobbler-2.0.7.old/cobbler/api.py cobbler-2.0.7/cobbler/api.py
1070a0
--- cobbler-2.0.7.old/cobbler/api.py	2014-11-10 15:07:00.577732729 -0500
1070a0
+++ cobbler-2.0.7/cobbler/api.py	2014-11-10 15:07:27.941923229 -0500
1070a0
@@ -818,6 +818,15 @@ class BootAPI:
1070a0
         time.sleep(5)
1070a0
         return self.power_on(system, user, password, logger=logger)
1070a0
 
1070a0
+    def power_status(self, system, user=None, password=None, logger=None):
1070a0
+        """
1070a0
+        Returns the power status for a system that has power management configured.
1070a0
+
1070a0
+        @return: 0  the system is powered on, False if it's not or None on error
1070a0
+        """
1070a0
+        return action_power.PowerTool(self._config, system, self, user, password, logger = logger).power("status")
1070a0
+
1070a0
+
1070a0
     # ==========================================================================
1070a0
 
1070a0
     def clear_logs(self, system, logger=None):
1070a0
diff -rupN cobbler-2.0.7.old/cobbler/cli.py cobbler-2.0.7/cobbler/cli.py
1070a0
--- cobbler-2.0.7.old/cobbler/cli.py	2014-11-10 15:07:00.575732715 -0500
1070a0
+++ cobbler-2.0.7/cobbler/cli.py	2014-11-10 15:07:27.941923229 -0500
1070a0
@@ -40,7 +40,7 @@ import item_image
1070a0
 OBJECT_ACTIONS   = {
1070a0
    "distro"  : "add copy edit find list remove rename report".split(" "),
1070a0
    "profile" : "add copy dumpvars edit find getks list remove rename report".split(" "),
1070a0
-   "system"  : "add copy dumpvars edit find getks list remove rename report poweron poweroff reboot".split(" "),
1070a0
+   "system"  : "add copy dumpvars edit find getks list remove rename report poweron poweroff powerstatus reboot".split(" "),
1070a0
    "image"   : "add copy edit find list remove rename report".split(" "),
1070a0
    "repo"    : "add copy edit find list remove rename report".split(" ")
1070a0
 } 
1070a0
@@ -278,7 +278,7 @@ class BootCLI:
1070a0
             keys.sort()
1070a0
             for x in keys:
1070a0
                print "%s : %s" % (x, data[x])
1070a0
-        elif object_action in [ "poweron", "poweroff", "reboot" ]:
1070a0
+        elif object_action in [ "poweron", "poweroff", "powerstatus", "reboot" ]:
1070a0
             power={}
1070a0
             power["power"] = object_action.replace("power","")
1070a0
             power["systems"] = [options.name]
1070a0
diff -rupN cobbler-2.0.7.old/cobbler/remote.py cobbler-2.0.7/cobbler/remote.py
1070a0
--- cobbler-2.0.7.old/cobbler/remote.py	2014-11-10 15:07:00.575732715 -0500
1070a0
+++ cobbler-2.0.7/cobbler/remote.py	2014-11-10 15:07:27.942923236 -0500
1070a0
@@ -1706,7 +1706,7 @@ class CobblerXMLRPCInterface:
1070a0
         """
1070a0
         Internal implementation used by background_power, do not call
1070a0
         directly if possible.  
1070a0
-        Allows poweron/poweroff/reboot of a system specified by object_id.
1070a0
+        Allows poweron/poweroff/powerstatus/reboot of a system specified by object_id.
1070a0
         """
1070a0
         obj = self.__get_object(object_id)
1070a0
         self.check_access(token, "power_system", obj)
1070a0
@@ -1714,10 +1714,12 @@ class CobblerXMLRPCInterface:
1070a0
             rc=self.api.power_on(obj, user=None, password=None, logger=logger)
1070a0
         elif power=="off":
1070a0
             rc=self.api.power_off(obj, user=None, password=None, logger=logger)
1070a0
+        elif power=="status":
1070a0
+            rc=self.api.power_status(obj, user=None, password=None, logger=logger)
1070a0
         elif power=="reboot":
1070a0
             rc=self.api.reboot(obj, user=None, password=None, logger=logger)
1070a0
         else:
1070a0
-            utils.die(self.logger, "invalid power mode '%s', expected on/off/reboot" % power)
1070a0
+            utils.die(self.logger, "invalid power mode '%s', expected on/off/status/reboot" % power)
1070a0
         return rc
1070a0
 
1070a0
     def clear_system_logs(self, object_id, token=None, logger=None):
1070a0
diff -rupN cobbler-2.0.7.old/templates/power_ipmilan.template cobbler-2.0.7/templates/power_ipmilan.template
1070a0
--- cobbler-2.0.7.old/templates/power_ipmilan.template	2014-11-10 15:07:00.581732757 -0500
1070a0
+++ cobbler-2.0.7/templates/power_ipmilan.template	2014-11-10 15:07:27.943923243 -0500
1070a0
@@ -1,2 +1 @@
1070a0
-#use power_id to pass in additional options like -P, Use Lanplus
1070a0
-fence_ipmilan -i "$power_address" $power_id -l "$power_user" -p "$power_pass" -o "$power_mode"
1070a0
+fence_ipmilan -a "$power_address" $power_id -l "$power_user" -p "$power_pass" -o "$power_mode"