From d2d7f04f49e91c87be29893f5b54a19d98a6a60e Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 6 Feb 2014 11:08:55 -0500 Subject: [PATCH] Further simplify ipmi plugin With the threading complications removed from worry, continue making the ipmi plugin more straightforward to read, maintain, and evolve. --- plugins/hardwaremanagement/ipmi.py | 76 +++++++++++++++--------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/plugins/hardwaremanagement/ipmi.py b/plugins/hardwaremanagement/ipmi.py index 0f22e693..facdbb87 100644 --- a/plugins/hardwaremanagement/ipmi.py +++ b/plugins/hardwaremanagement/ipmi.py @@ -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'])