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