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 2010/11/30 18:27:55 UTC
svn commit: r1040673 - in
/incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware: delldrac.py
dellswitch.py ipmi.py raritanpdu.py
Author: rgass
Date: Tue Nov 30 18:27:55 2010
New Revision: 1040673
URL: http://svn.apache.org/viewvc?rev=1040673&view=rev
Log:
Changes to the constructors of these files.
Add some log messages
Modified:
incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/delldrac.py
incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/dellswitch.py
incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/ipmi.py
incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/raritanpdu.py
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=1040673&r1=1040672&r2=1040673&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 Tue Nov 30 18:27:55 2010
@@ -22,46 +22,25 @@ import sys
import os
import pexpect
import time
+import logging
+import tempfile
from systemmanagementinterface import SystemManagementInterface
-
-
-#class systemmagement():
- #def __init__(self, proto):
- #self.proto = proto
-
-def log(f):
- def myF(*args, **kw):
- print "calling %s%s" % (f.__name__, str(args))
- res = f(*args, **kw)
- print "returning from %s -> %s" % (f.__name__, str(res))
- return res
- myF.__name__ = f.__name__
- return myF
-
-import time
-
-def timeF(f):
- def myF(*args, **kw):
- start = time.time()
- res = f(*args, **kw)
- end = time.time()
- print "%s took %f" % (f.__name__, end-start)
- return res
- myF.__name__ = f.__name__
- return myF
+from zoni.extra.util import timeF, log
class dellDrac(SystemManagementInterface):
- def __init__(self, host):
- self.hostname = host['location']
- self.host = host['drac_name']
- self.user = host['drac_userid']
- self.password = host['drac_password']
- self.port = host['drac_port']
+ def __init__(self, config, nodeName, hostInfo):
+ self.config = config
+ self.hostname = hostInfo['location']
+ self.host = hostInfo['drac_name']
+ self.user = hostInfo['drac_userid']
+ self.password = hostInfo['drac_password']
+ self.port = hostInfo['drac_port']
self.powerStatus = None
- self.verbose = 0
+ self.verbose = False
self.server = "Server-" + str(self.port)
+ self.log = logging.getLogger(__name__)
def setVerbose(self, verbose):
self.verbose = verbose
@@ -75,50 +54,42 @@ class dellDrac(SystemManagementInterface
opt = child.expect(['Login:', pexpect.EOF, pexpect.TIMEOUT])
-
- #XXX Doesn't seem to do what I want:(
child.setecho(False)
if opt == 0:
- child.sendline(self.user)
time.sleep(.5)
+ child.sendline(self.user)
+ i=child.expect(["assword:", pexpect.EOF, pexpect.TIMEOUT])
child.sendline(self.password)
- time.sleep(.5)
i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
+ if i == 2:
+ self.log.error("Login to %s failed" % (switchIp))
+ return -1
else:
mesg = "Error"
- sys.stderr.write(mesg)
- exit(1)
+ self.log.error(mesg)
+ return -1
return child
@timeF
- @log
- def getPowerStatus(self):
+ def __setPowerStatus(self):
+ fout = tempfile.TemporaryFile()
child = self.__login()
+ child.logfile = fout
cmd = "getmodinfo -m " + self.server
child.sendline(cmd)
- #i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
- #exit()
- val = child.readline()
- val = child.readline()
- while self.server not in val:
- val = child.readline()
-
- if "ON" in val:
- mesg = self.hostname + " Power is on\n\n"
- self.powerStatus = 1
- if "OFF" in val:
- mesg = self.hostname + " Power is off\n\n"
- self.powerStatus = 0
-
- sys.stdout.write(mesg)
-
- #while status not in val:
- #val = child.readline()
- #
- #print "val for", status, "is ", val
- #i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
- #val = child.readlines()
+ i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
+ fout.seek(0)
+ for i in fout.readlines():
+ if "ON" in i and self.server in i:
+ mesg = self.hostname + " Power is on\n\n"
+ self.powerStatus = 1
+ if "OFF" in i and self.server in i:
+ mesg = self.hostname + " Power is off\n\n"
+ self.powerStatus = 0
+ self.log.info(mesg)
+
+ fout.close()
child.close()
child.terminate()
@@ -126,76 +97,110 @@ class dellDrac(SystemManagementInterface
@timeF
def isPowered(self):
if self.powerStatus == None:
- self.getPowerStatus()
+ self.__setPowerStatus()
if self.powerStatus:
- return 1;
- if not self.powerStatus:
return 0;
+ return 1;
+ def getPowerStatus(self):
+ return self.isPowered()
@timeF
def powerOn(self):
+ code = 0
+ fout = tempfile.TemporaryFile()
if self.powerStatus == 1:
mesg = self.hostname + " Power On\n\n"
- exit(1)
+ return 0
child = self.__login()
+ child.logfile = fout
cmd = "racadm serveraction -m " + self.server + " powerup"
child.sendline(cmd)
- val = child.readline()
- val = child.readline()
- if "OK" in val:
- mesg = self.hostname + " Power On\n\n"
- else:
- mesg = self.hostname + " Power On Fail\n\n"
- sys.stdout.write(mesg)
- #i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
+ i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
+ fout.seek(0)
+ for val in fout.readlines():
+ if "OK" in val:
+ mesg = self.hostname + " Power On\n\n"
+ self.log.info(mesg)
+ code = 1
+ else:
+ mesg = self.hostname + " Power On Fail\n\n"
+ self.log.info(mesg)
+ code = -1
+ fout.close()
child.terminate()
+ return code
@timeF
def powerOff(self):
+ code = 0
+ fout = tempfile.TemporaryFile()
child = self.__login()
+ child.logfile = fout
cmd = "racadm serveraction -m " + self.server + " powerdown"
child.sendline(cmd)
- val = child.readline()
- val = child.readline()
- if "OK" in val:
- mesg = self.hostname + " Power Off\n\n"
- else:
- mesg = self.hostname + " Power Off Fail\n\n"
- sys.stdout.write(mesg)
+ i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
+ fout.seek(0)
+ for val in fout.readlines():
+ if "OK" in val:
+ mesg = self.hostname + " Power Off\n\n"
+ self.log.info(mesg)
+ code = 1
+ else:
+ mesg = self.hostname + " Power Off Fail\n\n"
+ self.log.info(mesg)
+ code = -1
#i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
child.terminate()
+ fout.close()
+ return code
@timeF
def powerCycle(self):
+ code = 0
+ fout = tempfile.TemporaryFile()
child = self.__login()
+ child.logfile = fout
cmd = "racadm serveraction -m " + self.server + " powercycle"
child.sendline(cmd)
- val = child.readline()
- val = child.readline()
- if "OK" in val:
- mesg = self.hostname + " Power Cycle\n\n"
- else:
- mesg = self.hostname + " Power Cycle Fail\n\n"
- sys.stdout.write(mesg)
- #i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
+ i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
+ fout.seek(0)
+ for val in fout.readlines():
+ if "OK" in val:
+ mesg = self.hostname + " Power Cycle\n\n"
+ self.log.info(mesg)
+ code = 1
+ else:
+ mesg = self.hostname + " Power Cycle Fail\n\n"
+ self.log.info(mesg)
+ code = -1
child.terminate()
+ fout.close()
+ return code
@timeF
def powerReset(self):
+ code = 0
+ fout = tempfile.TemporaryFile()
child = self.__login()
+ child.logfile = fout
cmd = "racadm serveraction -m " + self.server + " hardreset"
child.sendline(cmd)
- val = child.readline()
- val = child.readline()
- if "OK" in val:
- mesg = self.hostname + " Power Reset\n\n"
- else:
- mesg = self.hostname + " Power Reset Fail\n\n"
- sys.stdout.write(mesg)
- #i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
+ i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
+ fout.seek(0)
+ for val in fout.readlines():
+ if "OK" in val:
+ mesg = self.hostname + " Power Reset\n\n"
+ self.log.info(mesg)
+ code = 1
+ else:
+ mesg = self.hostname + " Power Reset Fail\n\n"
+ self.log.info(mesg)
+ code = -1
child.terminate()
+ fout.close()
+ return code
def activateConsole(self):
child = self.__login()
@@ -203,5 +208,3 @@ class dellDrac(SystemManagementInterface
child.sendline(cmd)
i=child.expect(['DRAC/MC:', pexpect.EOF, pexpect.TIMEOUT])
child.terminate()
-
-#ipmitool -I lanplus -E -H r2r1c3b0-ipmi -U root chassis power status
Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/dellswitch.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/dellswitch.py?rev=1040673&r1=1040672&r2=1040673&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/dellswitch.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/dellswitch.py Tue Nov 30 18:27:55 2010
@@ -52,7 +52,6 @@ class HwDellSwitch(HwSwitchInterface):
self.verbose = verbose
def __login(self):
-
switchIp = "ssh " + self.host['hw_userid'] + "@" + self.host['hw_name']
child = pexpect.spawn(switchIp)
@@ -92,7 +91,7 @@ class HwDellSwitch(HwSwitchInterface):
def __getPrsLabel(self):
dadate = datetime.datetime.now().strftime("%Y%m%d-%H%M-%S")
- return "PRS_" + dadate
+ return "Zoni_" + dadate
def enableHostPort(self):
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=1040673&r1=1040672&r2=1040673&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 Tue Nov 30 18:27:55 2010
@@ -20,6 +20,9 @@
import sys
import os
+import subprocess
+import logging
+import string
from systemmanagementinterface import SystemManagementInterface
@@ -29,77 +32,86 @@ from systemmanagementinterface import Sy
#self.proto = proto
class Ipmi(SystemManagementInterface):
- def __init__(self, host, user, password):
- self.host = host + "-ipmi"
- self.password = password
- self.user = user
+ def __init__(self, config, nodeName, hostInfo):
+ # should send data obj instead of hostInfo
+ self.config = config
+ self.nodeName = nodeName + "-ipmi"
+ self.password = hostInfo['ipmi_password']
+ self.user = hostInfo['ipmi_user']
self.powerStatus = None
self.verbose = False
- self.ipmicmd = "ipmitool -I lanplus -U" + self.user + " -H" + self.host + \
- " -P " + self.password + " "
+ self.log = logging.getLogger(__name__)
+ self.ipmicmd = "ipmitool -I lanplus -U %s -H %s -P %s " % (self.user, self.nodeName, self.password)
+ print self.ipmicmd
def setVerbose(self, verbose):
self.verbose = verbose
- def getPowerStatus(self):
+ def __executeCmd(self, cmd):
+ a = subprocess.Popen(args=cmd.split(), stderr=subprocess.PIPE, stdout=subprocess.PIPE)
+ out= a.stdout.readline()
+ err = a.stderr.readline()
+ if self.verbose:
+ print "out is ", out
+ print "err is ", err
+ if err:
+ self.log.info("%s %s" % (self.nodeName, err))
+ return -1
+
+ self.log.info("%s %s" % (self.nodeName, out))
+ return 1
+
+
+ def __setPowerStatus(self):
if self.verbose:
print self.ipmicmd
cmd = self.ipmicmd + "chassis power status"
- a = os.popen(cmd)
- output = a.read()
-
- print "%s\n%s" % (self.host, output)
+ a = subprocess.Popen(args=cmd.split(), stderr=subprocess.PIPE, stdout=subprocess.PIPE)
+ output = a.stdout.readline()
+ myerr = a.stderr.readline()
+
if "off" in output:
self.powerStatus = 0
if "on" in output:
self.powerStatus = 1
- if "Unable" in output:
- print "unable to get the status"
- self.powerStatus = 0
-
+ if "Unable" in myerr:
+ self.powerStatus = -1
+
return output
- #return a.read()
- #for line in a.readlines():
- #print line
def isPowered(self):
if self.powerStatus == None:
- self.getPowerStatus()
- if self.powerStatus:
- return 1;
- if not self.powerStatus:
- return 0;
+ self.__setPowerStatus()
+ self.log.info("Hardware get power status : %s", self.powerStatus)
+ return self.powerStatus
+
+ def getPowerStatus(self):
+ self.log.info("Getpowerstatus :%s" % self.nodeName)
+ return self.isPowered()
def powerOn(self):
+ self.log.info("Hardware power on : %s", self.nodeName)
cmd = self.ipmicmd + "chassis power on"
- a = os.popen(cmd)
- output = a.read()
- print "output is ", output
+ return self.__executeCmd(cmd)
def powerOff(self):
+ self.log.info("Hardware power off : %s", self.nodeName)
cmd = self.ipmicmd + "chassis power off"
- a = os.popen(cmd)
- output = a.read()
- print "output is ", output
+ return self.__executeCmd(cmd)
def powerCycle(self):
+ self.log.info("Hardware power cycle : %s", self.nodeName)
cmd = self.ipmicmd + "chassis power cycle"
- a = os.popen(cmd)
- output = a.read()
- print "output is ", output
+ return self.__executeCmd(cmd)
def powerReset(self):
+ self.log.info("Hardware power reset : %s", self.nodeName)
cmd = self.ipmicmd + "chassis power reset"
- a = os.popen(cmd)
- output = a.read()
- print "output is ", output
+ return self.__executeCmd(cmd)
def activateConsole(self):
+ self.log.info("Hardware sol activate : %s", self.nodeName)
cmd = self.ipmicmd + "sol activate"
- a = os.popen(cmd)
- output = a.read()
- print "output is ", output
-
-#ipmitool -I lanplus -E -H r2r1c3b0-ipmi -U root chassis power status
+ return self.__executeCmd(cmd)
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=1040673&r1=1040672&r2=1040673&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 Tue Nov 30 18:27:55 2010
@@ -37,18 +37,20 @@ from zoni.hardware.systemmanagementinter
#self.proto = proto
class raritanDominionPx(SystemManagementInterface):
- def __init__(self, config, host=None):
+ def __init__(self, config, nodeName, hostInfo):
# Register
self.config = config
+ self.nodeName = nodeName
self.log = logging.getLogger(__name__)
self.verbose = False
+ self.powerStatus = None
- if host != None:
- self.host = host['location']
- self.pdu_name = host['pdu_name']
- self.port = host['pdu_port']
- self.user = host['pdu_userid']
- self.password = host['pdu_password']
+ if hostInfo != None:
+ self.host = nodeName
+ self.pdu_name = hostInfo['pdu_name']
+ self.port = hostInfo['pdu_port']
+ self.user = hostInfo['pdu_userid']
+ self.password = hostInfo['pdu_password']
self.oid = "1,3,6,1,4,1,13742,4,1,2,2,1"
self.oid_name = ",2"
@@ -56,7 +58,7 @@ class raritanDominionPx(SystemManagement
self.oid_status = ",3"
if self.getOffset():
- self.port = host['pdu_port'] - 1
+ self.port = hostInfo['pdu_port'] - 1
# this works
@@ -98,7 +100,7 @@ class raritanDominionPx(SystemManagement
return 1
- def getPowerStatus(self):
+ def __setPowerStatus(self):
thisoid = eval(str(self.oid) + str(self.oid_status) + "," + str(self.port))
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd( \
cmdgen.CommunityData('my-agent', self.user, 0), \
@@ -112,7 +114,7 @@ class raritanDominionPx(SystemManagement
self.powerStatus = 0
powerstat = "off"
- print "PDU Power for %s is %s" % (self.host, powerstat)
+ self.log.info("%s setPowerStatus %s" % (self.nodeName, self.powerStatus))
if output:
return 1
@@ -121,12 +123,13 @@ class raritanDominionPx(SystemManagement
def isPowered(self):
if self.powerStatus == None:
- self.getPowerStatus()
+ self.__setPowerStatus()
if self.powerStatus:
return 1;
- if not self.powerStatus:
- return 0;
+ return 0;
+ def getPowerStatus(self):
+ return self.isPowered()
def powerOn(self):
thisoid = eval(str(self.oid) + str(self.oid_status) + "," + str(self.port))
@@ -134,7 +137,7 @@ class raritanDominionPx(SystemManagement
cmdgen.CommunityData('my-agent', self.user, 1), \
cmdgen.UdpTransportTarget((self.pdu_name, 161)), \
(thisoid, rfc1902.Integer('1')))
- self.getPowerStatus()
+ return self.getPowerStatus()
def powerOff(self):
thisoid = eval(str(self.oid) + str(self.oid_status) + "," + str(self.port))
@@ -142,7 +145,7 @@ class raritanDominionPx(SystemManagement
cmdgen.CommunityData('my-agent', self.user, 1), \
cmdgen.UdpTransportTarget((self.pdu_name, 161)), \
(thisoid, rfc1902.Integer('0')))
- self.getPowerStatus()
+ return self.getPowerStatus()
def powerCycle(self):
self.powerOff()