mirror of
https://github.com/xcat2/confluent.git
synced 2024-11-22 17:43:14 +00:00
Provide common entry point for input processing
This commit is contained in:
parent
51c80cdd74
commit
ada6302c2d
@ -3,3 +3,6 @@ class ConfluentException(Exception):
|
||||
|
||||
class NotFoundException(ConfluentException):
|
||||
pass
|
||||
|
||||
class InvalidArgumentException(ConfluentException):
|
||||
pass
|
||||
|
@ -227,6 +227,10 @@ def resourcehandler(env, start_response):
|
||||
start_response('404 Not found', headers)
|
||||
yield "404 - Request path not recognized"
|
||||
return
|
||||
except exc.InvalidArgumentException:
|
||||
start_response('400 Bad Request', headers)
|
||||
yield '400 - Bad Request'
|
||||
return
|
||||
start_response('200 OK', headers)
|
||||
if mimetype == 'text/html':
|
||||
for datum in _assemble_html(hdlr, resource, querydict):
|
||||
|
@ -3,6 +3,7 @@
|
||||
# This module implements client/server messages emitted from plugins.
|
||||
# Things are defined here to 'encourage' developers to coordinate information
|
||||
# format. This is also how different data formats are supported
|
||||
import confluent.exceptions as exc
|
||||
import json
|
||||
|
||||
class ConfluentMessage(object):
|
||||
@ -35,11 +36,50 @@ class ConfluentMessage(object):
|
||||
snippet += '<input type="checkbox" name="restexplorerhonorkey" '
|
||||
snippet += 'value="%s">' % (key)
|
||||
return snippet
|
||||
def get_input_message(path, operation, inputdata, nodes=None):
|
||||
if 'power/state' in path and operation != 'retrieve':
|
||||
return InputPowerMessage(path, nodes, inputdata)
|
||||
|
||||
|
||||
valid_powerstates = set([
|
||||
'on',
|
||||
'off',
|
||||
'reset',
|
||||
'boot',
|
||||
])
|
||||
|
||||
|
||||
class InputPowerMessage(ConfluentMessage):
|
||||
|
||||
def __init__(self, path, nodes, inputdata):
|
||||
self.powerbynode = {}
|
||||
if not inputdata:
|
||||
raise exc.InvalidArgumentException()
|
||||
if ('powerstate' not in inputdata):
|
||||
#assume we have nested information
|
||||
for key in nodes:
|
||||
if key not in inputdata:
|
||||
raise exc.InvalidArgumentException()
|
||||
datum = inputdata[key]
|
||||
if ('powerstate' not in datum or
|
||||
datum['powerstate'] not in valid_powerstates):
|
||||
raise exc.InvalidArgumentException()
|
||||
self.powerbynode[key] = datum['powerstate']
|
||||
else: # we have a powerstate argument not by node
|
||||
datum = inputdata
|
||||
if ('powerstate' not in datum or
|
||||
datum['powerstate'] not in valid_powerstates):
|
||||
raise exc.InvalidArgumentException()
|
||||
for node in nodes:
|
||||
self.powerbynode[node] = datum['powerstate']
|
||||
|
||||
def powerstate(self, node):
|
||||
return self.powerbynode[node]
|
||||
|
||||
|
||||
class PowerState(ConfluentMessage):
|
||||
|
||||
def __init__(self, node, state):
|
||||
def __init__(self, node, state, querydict=None):
|
||||
self.kvpairs = {
|
||||
node: {
|
||||
'powerstate': { 'label': 'Power', 'value': state, }
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
import confluent.interface.console as console
|
||||
import confluent.exceptions as exc
|
||||
import confluent.messages as msg
|
||||
import os
|
||||
import sys
|
||||
|
||||
@ -99,6 +100,7 @@ def handle_path(path, operation, configmanager, inputdata=None):
|
||||
node, _, element = node.partition("/")
|
||||
if element not in nodeelements:
|
||||
raise exc.NotFoundException("Invalid element requested")
|
||||
inputdata = msg.get_input_message(element, operation, inputdata, (node,))
|
||||
plugroute = nodeelements[element]
|
||||
if 'handler' in plugroute: #fixed handler definition
|
||||
passvalue = pluginmap[plugroute['handler']].__dict__[operation](
|
||||
|
@ -257,7 +257,9 @@ class IpmiHandler(object):
|
||||
return msg.PowerState(node=self.node,
|
||||
state=power['powerstate'])
|
||||
elif 'update' == self.op:
|
||||
self.call_ipmicmd(self.ipmicmd.set_power, self.inputdata['powerstate'])
|
||||
powerstate = self.inputdata.powerstate(self.node)
|
||||
#TODO: call with wait argument
|
||||
self.call_ipmicmd(self.ipmicmd.set_power, powerstate)
|
||||
power = self.call_ipmicmd(self.ipmicmd.get_power)
|
||||
return msg.PowerState(node=self.node,
|
||||
state=power['powerstate'])
|
||||
|
Loading…
Reference in New Issue
Block a user