2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-01-28 11:57:37 +00:00

Further simplify ipmi plugin

With the threading complications removed from worry,
continue making the ipmi plugin more straightforward
to read, maintain, and evolve.
This commit is contained in:
Jarrod Johnson 2014-02-06 11:08:55 -05:00
parent 80d4518a49
commit d2d7f04f49

View File

@ -4,6 +4,7 @@ import confluent.interface.console as conapi
import confluent.messages as msg
import eventlet
import eventlet.event
import eventlet.green.threading as threading
import eventlet.greenpool as greenpool
import eventlet.queue
import os
@ -123,9 +124,6 @@ def perform_request(operator, node, element, configdata, inputdata):
class IpmiHandler(object):
def __iter__():
return self
def __init__(self, operation, node, element, cfd, inputdata):
self.broken = False
eventlet.sleep(0)
@ -136,6 +134,7 @@ class IpmiHandler(object):
self.op = operation
connparams = get_conn_params(node, self.cfg)
self.ipmicmd = None
self._logevt = threading.Event()
self.inputdata = inputdata
self.ipmicmd = ipmicommand.Command(bmc=connparams['bmc'],
userid=connparams['username'],
@ -143,57 +142,58 @@ class IpmiHandler(object):
kg=connparams['kg'],
port=connparams['port'],
onlogon=self.logged)
print "spin on logon"
while not (self.loggedin or self.broken):
print "on"
console.session.Session.wait_for_rsp(timeout=600)
print "hmph..."
bootdevices = {
'optical': 'cd'
}
def logged(self, response, ipmicmd):
print "huzzah"
if 'error' in response:
self.broken = True
self.error = response['error']
else:
self.loggedin = True
self._logevt.set()
def handle_request(self):
bootdevices = {
'optical': 'cd'
}
while not (self.loggedin or self.broken):
console.session.Session.wait_for_rsp(timeout=600)
self._logevt.wait()
if self.broken:
if self.error == 'timeout':
raise exc.TargetEndpointTimeout()
else:
raise Exception(self.error)
if self.element == [ 'power', 'state' ]:
if 'read' == self.op:
power = self.ipmicmd.get_power()
return msg.PowerState(node=self.node,
state=power['powerstate'])
elif 'update' == self.op:
powerstate = self.inputdata.powerstate(self.node)
#TODO: call with wait argument
self.ipmicmd.set_power(powerstate)
power = self.ipmicmd.get_power()
return msg.PowerState(node=self.node,
state=power['powerstate'])
return self.power()
elif self.element == [ 'boot', 'device' ]:
if 'read' == self.op:
bootdev = self.ipmicmd.get_bootdev()
if bootdev['bootdev'] in bootdevices:
bootdev['bootdev'] = bootdevices[bootdev['bootdev']]
return msg.BootDevice(node=self.node,
device=bootdev['bootdev'])
elif 'update' == self.op:
bootdev = self.inputdata.bootdevice(self.node)
bootdev = self.ipmicmd.set_bootdev(bootdev)
if bootdev['bootdev'] in bootdevices:
bootdev['bootdev'] = bootdevices[bootdev['bootdev']]
return msg.BootDevice(node=self.node,
device=bootdev['bootdev'])
return self.bootdevice()
def bootdevice(self):
if 'read' == self.op:
bootdev = self.ipmicmd.get_bootdev()
if bootdev['bootdev'] in self.bootdevices:
bootdev['bootdev'] = self.bootdevices[bootdev['bootdev']]
return msg.BootDevice(node=self.node,
device=bootdev['bootdev'])
elif 'update' == self.op:
bootdev = self.inputdata.bootdevice(self.node)
bootdev = self.ipmicmd.set_bootdev(bootdev)
if bootdev['bootdev'] in self.bootdevices:
bootdev['bootdev'] = self.bootdevices[bootdev['bootdev']]
return msg.BootDevice(node=self.node,
device=bootdev['bootdev'])
def power(self):
if 'read' == self.op:
power = self.ipmicmd.get_power()
return msg.PowerState(node=self.node,
state=power['powerstate'])
elif 'update' == self.op:
powerstate = self.inputdata.powerstate(self.node)
#TODO: call with wait argument
self.ipmicmd.set_power(powerstate)
power = self.ipmicmd.get_power()
return msg.PowerState(node=self.node,
state=power['powerstate'])