mirror of
https://github.com/xcat2/confluent.git
synced 2024-11-22 17:43:14 +00:00
Wire up input to plugins for create/read
This commit is contained in:
parent
9765d2c2bb
commit
3fa61dc8f9
@ -203,7 +203,8 @@ def resourcehandler(env, start_response):
|
||||
operation = opmap[env['REQUEST_METHOD']]
|
||||
resource = '.' + env['PATH_INFO'][env['PATH_INFO'].rindex('/'):]
|
||||
try:
|
||||
hdlr = pluginapi.handle_path(env['PATH_INFO'], operation, cfgmgr)
|
||||
hdlr = pluginapi.handle_path(env['PATH_INFO'], operation,
|
||||
cfgmgr, querydict)
|
||||
except exc.NotFoundException:
|
||||
start_response('404 Not found', headers)
|
||||
yield "404 - Request path not recognized"
|
||||
|
@ -84,7 +84,7 @@ def stripnode(iterablersp, node):
|
||||
i.strip_node(node)
|
||||
yield i
|
||||
|
||||
def handle_path(path, operation, configmanager):
|
||||
def handle_path(path, operation, configmanager, inputdata=None):
|
||||
'''Given a full path request, return an object.
|
||||
|
||||
The plugins should generally return some sort of iterator.
|
||||
@ -103,7 +103,8 @@ def handle_path(path, operation, configmanager):
|
||||
if 'handler' in plugroute: #fixed handler definition
|
||||
passvalue = pluginmap[plugroute['handler']].__dict__[operation](
|
||||
nodes=(node,), element=element,
|
||||
configmanager=configmanager)
|
||||
configmanager=configmanager,
|
||||
inputdata=inputdata)
|
||||
elif 'pluginattrs' in plugroute:
|
||||
nodeattr = configmanager.get_node_attributes(
|
||||
[node], plugroute['pluginattrs'])
|
||||
@ -111,10 +112,12 @@ def handle_path(path, operation, configmanager):
|
||||
if attrname in nodeattr[node]:
|
||||
passvalue = pluginmap[nodeattr[node][attrname]['value']].__dict__[operation](
|
||||
nodes=(node,), element=element,
|
||||
configmanager=configmanager)
|
||||
configmanager=configmanager,
|
||||
inputdata=inputdata)
|
||||
if 'default' in plugroute:
|
||||
passvalue = pluginmap[plugroute['default']].__dict__[operation](
|
||||
nodes=(node,), element=element, configmanager=configmanager)
|
||||
nodes=(node,), element=element, configmanager=configmanager,
|
||||
inputdata=inputdata)
|
||||
if isinstance(passvalue, console.Console):
|
||||
return passvalue
|
||||
else:
|
||||
|
@ -1,6 +1,6 @@
|
||||
import confluent.messages as msg
|
||||
|
||||
def retrieve(nodes, element, configmanager):
|
||||
def retrieve(nodes, element, configmanager, inputdata):
|
||||
attributes = configmanager.get_node_attributes(nodes)
|
||||
for node in attributes.iterkeys():
|
||||
for attribute in attributes[node].iterkeys():
|
||||
|
@ -168,7 +168,7 @@ class IpmiConsole(confluent.interface.console.Console):
|
||||
|
||||
|
||||
class IpmiIterator(object):
|
||||
def __init__(self, operator, nodes, element, cfg):
|
||||
def __init__(self, operator, nodes, element, cfg, inputdata):
|
||||
crypt = cfg.decrypt
|
||||
cfg.decrypt = True
|
||||
configdata = cfg.get_node_attributes(nodes,
|
||||
@ -178,7 +178,7 @@ class IpmiIterator(object):
|
||||
cfg.decrypt = crypt
|
||||
self.gpile = greenpool.GreenPile()
|
||||
for node in nodes:
|
||||
self.gpile.spawn(perform_request, operator, node, element, configdata)
|
||||
self.gpile.spawn(perform_request, operator, node, element, configdata, inputdata)
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
@ -189,15 +189,15 @@ class IpmiIterator(object):
|
||||
return ndata
|
||||
|
||||
|
||||
def perform_request(operator, node, element, configdata):
|
||||
return IpmiHandler(operator, node, element, configdata).handle_request()
|
||||
def perform_request(operator, node, element, configdata, inputdata):
|
||||
return IpmiHandler(operator, node, element, configdata, inputdata).handle_request()
|
||||
|
||||
|
||||
class IpmiHandler(object):
|
||||
def __iter__():
|
||||
return self
|
||||
|
||||
def __init__(self, operation, node, element, cfd):
|
||||
def __init__(self, operation, node, element, cfd, inputdata):
|
||||
global chainpulled
|
||||
global _ipmithread
|
||||
global pullchain
|
||||
@ -212,6 +212,7 @@ class IpmiHandler(object):
|
||||
self.op = operation
|
||||
connparams = get_conn_params(node, self.cfg)
|
||||
self.ipmicmd = None
|
||||
self.inputdata = inputdata
|
||||
ipmiq.append((ipmicommand.Command,{'bmc': connparams['bmc'],
|
||||
'userid': connparams['username'],
|
||||
'password': connparams['passphrase'],
|
||||
@ -255,18 +256,26 @@ class IpmiHandler(object):
|
||||
power = self.call_ipmicmd(self.ipmicmd.get_power)
|
||||
return msg.PowerState(node=self.node,
|
||||
state=power['powerstate'])
|
||||
elif 'update' == self.op:
|
||||
self.call_ipmicmd(self.ipmicmd.set_power, self.inputdata['powerstate'])
|
||||
power = self.call_ipmicmd(self.ipmicmd.get_power)
|
||||
print repr(power)
|
||||
|
||||
def create(nodes, element, configmanager):
|
||||
|
||||
|
||||
def create(nodes, element, configmanager, inputdata):
|
||||
if element == '_console/session':
|
||||
if len(nodes) > 1:
|
||||
raise Exception("_console/session does not support multiple nodes")
|
||||
return IpmiConsole(nodes[0], configmanager)
|
||||
else:
|
||||
raise Exception(
|
||||
"TODO(jbjohnso): ipmi api implementation of %s" % element)
|
||||
return IpmiIterator('update', nodes, element, configmanager, inputdata)
|
||||
|
||||
def update(nodes, element, configmanager, inputdata):
|
||||
create(nodes, element, configmanager, inputdata)
|
||||
|
||||
|
||||
|
||||
def retrieve(nodes, element, configmanager):
|
||||
return IpmiIterator('read', nodes, element, configmanager)
|
||||
def retrieve(nodes, element, configmanager, inputdata):
|
||||
return IpmiIterator('read', nodes, element, configmanager, inputdata)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user