You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tashi-commits@incubator.apache.org by rg...@apache.org on 2011/01/19 20:24:44 UTC
svn commit: r1060964 - in /incubator/tashi/branches/zoni-dev/trunk/src/zoni:
client/zoni-cli.py hardware/delldrac.py hardware/ipmi.py
hardware/raritanpdu.py hardware/systemmanagement.py
hardware/systemmanagementinterface.py
Author: rgass
Date: Wed Jan 19 20:24:44 2011
New Revision: 1060964
URL: http://svn.apache.org/viewvc?rev=1060964&view=rev
Log:
adding support to do a soft power off via acpi instead of just yanking the power.
The host must have acpid enabled or this will not do anything.
systemmanagement.py starts a thread to confirm that the power is indeed off
when a soft shutdown is executed
Modified:
incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py
incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/delldrac.py
incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/ipmi.py
incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/raritanpdu.py
incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/systemmanagement.py
incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/systemmanagementinterface.py
Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py?rev=1060964&r1=1060963&r2=1060964&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py Wed Jan 19 20:24:44 2011
@@ -94,6 +94,7 @@ def main():
group.add_option("--reboot", "--reboot", dest="REBOOTNODE", help="Reboot node (Soft)", action="store_true", default=False)
group.add_option("--powerCycle", "--powercycle", dest="POWERCYCLE", help="Power Cycle (Hard)", action="store_true", default=False)
group.add_option("--powerOff", "--poweroff", dest="POWEROFF", help="Power off node", action="store_true", default=False)
+ group.add_option("--powerOffSoft", "--poweroffsoft", dest="POWEROFFSOFT", help="Power off node (soft)", action="store_true", default=False)
group.add_option("--powerOn", "--poweron", dest="POWERON", help="Power on node", action="store_true", default=False)
group.add_option("--powerReset", "--powerreset", dest="POWERRESET", help="Power reset node", action="store_true", default=False)
group.add_option("--console", dest="CONSOLE", help="Console mode", action="store_true", default=False)
@@ -213,7 +214,7 @@ def main():
hw = Ipmi(configs, options.nodeName, host)
#
if options.hardwareType == "pdu":
- hw = raritanDominionPx(configs, host)
+ hw = raritanDominionPx(configs, options.nodeName, host)
#
if options.hardwareType == "drac":
## Check if node has drac card
@@ -223,7 +224,7 @@ def main():
mesg = "Host (" + options.nodeName + ") does not have a DRAC card!!\n"
sys.stdout.write(mesg)
exit(1)
- if (options.REBOOTNODE or options.POWERCYCLE or options.POWEROFF or \
+ if (options.REBOOTNODE or options.POWERCYCLE or options.POWEROFF or options.POWEROFFSOFT or \
options.POWERON or options.POWERSTATUS or options.CONSOLE or \
options.POWERRESET) and options.nodeName:
@@ -239,6 +240,9 @@ def main():
if options.POWEROFF:
hw.powerOff()
exit()
+ if options.POWEROFFSOFT:
+ hw.powerOffSoft()
+ exit()
if options.POWERON:
hw.powerOn()
exit()
@@ -256,7 +260,7 @@ def main():
else:
hw = zoni.hardware.systemmanagement.SystemManagement(configs,data)
- if (options.REBOOTNODE or options.POWERCYCLE or options.POWEROFF or \
+ if (options.REBOOTNODE or options.POWERCYCLE or options.POWEROFF or options.POWEROFFSOFT or \
options.POWERON or options.POWERSTATUS or options.CONSOLE or \
options.POWERRESET) and options.nodeName:
@@ -269,6 +273,9 @@ def main():
if options.POWERCYCLE:
hw.powerCycle(options.nodeName)
exit()
+ if options.POWEROFFSOFT:
+ hw.powerOffSoft(options.nodeName)
+ exit()
if options.POWEROFF:
hw.powerOff(options.nodeName)
exit()
Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/delldrac.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/delldrac.py?rev=1060964&r1=1060963&r2=1060964&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/delldrac.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/delldrac.py Wed Jan 19 20:24:44 2011
@@ -157,6 +157,30 @@ class dellDrac(SystemManagementInterface
return code
@timeF
+ def powerOffSoft(self):
+ code = 0
+ fout = tempfile.TemporaryFile()
+ child = self.__login()
+ child.logfile = fout
+ cmd = "racadm serveraction -m " + self.server + " graceshutdown"
+ child.sendline(cmd)
+ i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
+ fout.seek(0)
+ self.log.info("Hardware power off (soft): %s", self.hostname)
+
+ for val in fout.readlines():
+ if "OK" in val:
+ code = 1
+ if "CURRENTLY POWER-OFF" in val:
+ self.log.info("Hardware already power off : %s", self.hostname)
+ code = 1
+ if code < 1:
+ self.log.info("Hardware power off failed : %s", self.hostname)
+ child.terminate()
+ fout.close()
+ return code
+
+ @timeF
def powerCycle(self):
code = 0
fout = tempfile.TemporaryFile()
Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/ipmi.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/ipmi.py?rev=1060964&r1=1060963&r2=1060964&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/ipmi.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/ipmi.py Wed Jan 19 20:24:44 2011
@@ -87,7 +87,7 @@ class Ipmi(SystemManagementInterface):
return self.powerStatus
def getPowerStatus(self):
- self.log.info("Getpowerstatus :%s" % self.nodeName)
+ #self.log.info("getPowerStatus :%s" % self.nodeName)
return self.isPowered()
@@ -101,6 +101,11 @@ class Ipmi(SystemManagementInterface):
cmd = self.ipmicmd + "chassis power off"
return self.__executeCmd(cmd)
+ def powerOffSoft(self):
+ self.log.info("Hardware power off (soft): %s", self.nodeName)
+ cmd = self.ipmicmd + "chassis power soft"
+ return self.__executeCmd(cmd)
+
def powerCycle(self):
self.log.info("Hardware power cycle : %s", self.nodeName)
cmd = self.ipmicmd + "chassis power cycle"
Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/raritanpdu.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/raritanpdu.py?rev=1060964&r1=1060963&r2=1060964&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/raritanpdu.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/raritanpdu.py Wed Jan 19 20:24:44 2011
@@ -106,6 +106,7 @@ class raritanDominionPx(SystemManagement
cmdgen.CommunityData('my-agent', self.user, 0), \
cmdgen.UdpTransportTarget((self.pdu_name, 161)), thisoid)
output = varBinds[0][1]
+ print output, varBinds
if output == 1:
self.powerStatus = 1
@@ -113,8 +114,8 @@ class raritanDominionPx(SystemManagement
if output == 0:
self.powerStatus = 0
powerstat = "off"
-
- self.log.info("%s setPowerStatus %s" % (self.nodeName, self.powerStatus))
+ print "pwerstat", powerstat
+ self.log.info("hardware setPowerStatus %s : %s" % (powerstat, self.nodeName))
if output:
return 1
Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/systemmanagement.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/systemmanagement.py?rev=1060964&r1=1060963&r2=1060964&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/systemmanagement.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/systemmanagement.py Wed Jan 19 20:24:44 2011
@@ -22,6 +22,7 @@
import sys
import os
import logging
+import threading
from systemmanagementinterface import SystemManagementInterface
from zoni.data.resourcequerysql import *
@@ -54,7 +55,7 @@ class SystemManagement(SystemManagementI
def __iterateHardware(self, nodeName, cmd, *args):
retries = 2
- print "cmd ", cmd, "args", args
+
mycmd = "%s()" % (cmd)
self.host = self.__getHostInfo(nodeName)
hw = self.data.getHardwareCapabilities(nodeName)
@@ -71,6 +72,12 @@ class SystemManagement(SystemManagementI
if doit > 0:
self.log.info("%s method success (%s) on %s (attempt %s)", i[0], mycmd, nodeName, count + 1)
success = 1
+ # IF we use soft poweroff, start a thread to poweroff after 60 seconds to
+ # guarantee. If the node doesn't have acpi installed, powerOffSoft doesn't do
+ # anything
+ if "powerOffSoft" in mycmd:
+ threading.Thread(args=(i[0], nodeName), target=self.softPowerConfirm).start()
+
break
else:
self.log.error("%s method failed (%s) on %s (attempt %s)", i[0], mycmd, nodeName, count + 1)
@@ -79,6 +86,21 @@ class SystemManagement(SystemManagementI
return doit
+ def softPowerConfirm(self, method, nodeName):
+ # using a sleep for now...
+ time.sleep(30)
+ inst = instantiateImplementation(self.config['hardwareControl'][method]['class'], self.config, nodeName, self.host)
+ mycmd = "%s()" % ("powerOff")
+ a = "inst.%s" % mycmd
+ doit = eval(a)
+ if doit > 0:
+ self.log.info("%s method success after soft power off(%s))", method[0], mycmd, nodeName)
+ else:
+ self.log.error("%s method failed after soft power off(%s))", method[0], mycmd, nodeName)
+ exit()
+
+
+
def runCmd(self, nodeName, cmd, *args):
self.__iterateHardware(nodeName, cmd, args)
@@ -88,6 +110,9 @@ class SystemManagement(SystemManagementI
def powerOff(self, nodeName):
self.__iterateHardware(nodeName, "powerOff")
+ def powerOffSoft(self, nodeName):
+ self.__iterateHardware(nodeName, "powerOffSoft")
+
def powerCycle(self, nodeName):
self.__iterateHardware(nodeName, "powerCycle")
Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/systemmanagementinterface.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/systemmanagementinterface.py?rev=1060964&r1=1060963&r2=1060964&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/systemmanagementinterface.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/systemmanagementinterface.py Wed Jan 19 20:24:44 2011
@@ -46,6 +46,10 @@ class SystemManagementInterface(object):
''' Powers off a system '''
raise NotImplementedError
+ def powerOffSoft(self):
+ ''' Powers off a system via acpi'''
+ raise NotImplementedError
+
def powerCycle(self):
''' Powers cycles a system '''
raise NotImplementedError