mirror of
https://github.com/xcat2/confluent.git
synced 2025-01-23 08:04:09 +00:00
Merge branch 'master' of /gsa/pokgsa/projects/x/xcat/git/confluent
Conflicts: confluent/httpapi.py
This commit is contained in:
commit
892b6b53dd
confluent
@ -57,12 +57,12 @@ node = {
|
||||
'description': ('List of static groups for which this node is'
|
||||
'considered a member'),
|
||||
},
|
||||
'type': {
|
||||
'description': ('Classification of node as system, vm, etc')
|
||||
},
|
||||
'id': {
|
||||
'description': ('Numeric identifier for node')
|
||||
},
|
||||
#'type': {
|
||||
# 'description': ('Classification of node as system, vm, etc')
|
||||
#},
|
||||
#'id': {
|
||||
# 'description': ('Numeric identifier for node')
|
||||
#},
|
||||
# 'location.timezone': {
|
||||
# 'description': 'POSIX timezone to apply to this node',
|
||||
# },
|
||||
|
@ -6,6 +6,7 @@
|
||||
import base64
|
||||
import Cookie
|
||||
import confluent.auth as auth
|
||||
import confluent.config.attributes as attribs
|
||||
import confluent.consoleserver as consoleserver
|
||||
import confluent.exceptions as exc
|
||||
import confluent.messages
|
||||
@ -31,6 +32,22 @@ opmap = {
|
||||
'DELETE': 'delete',
|
||||
}
|
||||
|
||||
def node_creation_resources():
|
||||
yield confluent.messages.Attributes(
|
||||
kv={ 'name': None}, desc="Name of the node").html() + '<br>'
|
||||
for attr in sorted(attribs.node.iterkeys()):
|
||||
if attr.startswith("secret."):
|
||||
yield confluent.messages.CryptedAttributes(
|
||||
kv={ attr: None }, desc=attribs.node[attr]['description']).html() + \
|
||||
'<br>'
|
||||
else:
|
||||
yield confluent.messages.Attributes(
|
||||
kv={ attr: None }, desc=attribs.node[attr]['description']).html() + \
|
||||
'<br>'
|
||||
|
||||
create_resource_functions = {
|
||||
'/node/': node_creation_resources,
|
||||
}
|
||||
|
||||
def _sessioncleaner():
|
||||
while (1):
|
||||
@ -248,7 +265,7 @@ def resourcehandler(env, start_response):
|
||||
|
||||
def _assemble_html(responses, resource, querydict, url):
|
||||
yield '<html><head><title>' \
|
||||
'Confluent REST Explorer: ' + resource + '</title></head>' \
|
||||
'Confluent REST Explorer: ' + url + '</title></head>' \
|
||||
'<body><form action="' + resource + '" method="post">'
|
||||
if querydict:
|
||||
yield 'Response to input data:<br>' + \
|
||||
@ -275,8 +292,19 @@ def _assemble_html(responses, resource, querydict, url):
|
||||
pendingrsp.append(rsp)
|
||||
for rsp in pendingrsp:
|
||||
yield rsp.html()+ "<br>"
|
||||
print url
|
||||
if not iscollection:
|
||||
if iscollection:
|
||||
localpath = url[:-2]
|
||||
try:
|
||||
firstpass = True
|
||||
for y in create_resource_functions[url]():
|
||||
if firstpass:
|
||||
yield "<hr>Define new %s:<BR>" % url.split("/")[-2]
|
||||
firstpass = False
|
||||
yield y
|
||||
yield '<input value="create" name="restexplorerop" type="submit"></form></body></html>'
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
yield '<input value="update" name="restexplorerop" type="submit"></form></body></html>'
|
||||
|
||||
|
||||
|
@ -35,25 +35,31 @@ class ConfluentMessage(object):
|
||||
value = self.defaultvalue
|
||||
note = ''
|
||||
type = self.defaulttype
|
||||
try:
|
||||
desc = self.desc
|
||||
except:
|
||||
desc = ''
|
||||
if 'value' in val:
|
||||
value = val['value']
|
||||
if value is None:
|
||||
value = ''
|
||||
if 'note' in val:
|
||||
note = '(' + val['note'] + ')'
|
||||
if isinstance(val, list):
|
||||
snippet += key + ":"
|
||||
for v in val:
|
||||
snippet += \
|
||||
'<input type="%s" name="%s" value="%s">%s' % (
|
||||
type, key, v, note)
|
||||
'<input type="%s" name="%s" value="%s" title="%s">%s' % (
|
||||
type, key, v, desc, note)
|
||||
snippet += \
|
||||
'<input type="%s" name="%s" value="">%s' % (
|
||||
type, key, note)
|
||||
'<input type="%s" name="%s" value="" title="%s">%s' % (
|
||||
type, key, desc, note)
|
||||
snippet += '<input type="checkbox" name="restexplorerhonorkey" '
|
||||
snippet += 'value="%s">' % (key)
|
||||
return snippet
|
||||
snippet += key + ":" + \
|
||||
'<input type="%s" name="%s" value="%s">%s' % (
|
||||
type, key, value, note)
|
||||
'<input type="%s" name="%s" value="%s" title="%s">%s' % (
|
||||
type, key, value, desc, note)
|
||||
snippet += '<input type="checkbox" name="restexplorerhonorkey" '
|
||||
snippet += 'value="%s">' % (key)
|
||||
return snippet
|
||||
@ -247,13 +253,17 @@ class PowerState(ConfluentChoiceMessage):
|
||||
}
|
||||
|
||||
class Attributes(ConfluentMessage):
|
||||
def __init__(self, node, kv):
|
||||
def __init__(self, node=None, kv=None, desc=None):
|
||||
self.desc = desc
|
||||
nkv = {}
|
||||
for key in kv.iterkeys():
|
||||
nkv[key] = { 'value': kv[key] }
|
||||
self.kvpairs = {
|
||||
node: nkv
|
||||
}
|
||||
if node is None:
|
||||
self.kvpairs = nkv
|
||||
else:
|
||||
self.kvpairs = {
|
||||
node: nkv
|
||||
}
|
||||
|
||||
class ListAttributes(ConfluentMessage):
|
||||
def __init__(self, node, kv):
|
||||
@ -264,11 +274,15 @@ class ListAttributes(ConfluentMessage):
|
||||
class CryptedAttributes(Attributes):
|
||||
defaulttype = 'password'
|
||||
|
||||
def __init__(self, node, kv):
|
||||
def __init__(self, node=None, kv=None, desc=None):
|
||||
# for now, just keep the dictionary keys and discard crypt value
|
||||
self.desc = desc
|
||||
nkv = {}
|
||||
for key in kv.iterkeys():
|
||||
nkv[key] = { 'note': 'Encrypted' }
|
||||
self.kvpairs = {
|
||||
node: nkv
|
||||
}
|
||||
if node is None:
|
||||
self.kvpairs = nkv
|
||||
else:
|
||||
self.kvpairs = {
|
||||
node: nkv
|
||||
}
|
||||
|
@ -123,10 +123,21 @@ def enumerate_node_collection(collectionpath, configmanager):
|
||||
return iterate_resources(collection)
|
||||
|
||||
|
||||
def create_node(inputdata, configmanager):
|
||||
try:
|
||||
nodename = inputdata['name']
|
||||
del inputdata['name']
|
||||
attribmap = { nodename: inputdata }
|
||||
except KeyError:
|
||||
raise exc.InvalidArgumentException()
|
||||
configmanager.set_node_attributes(attribmap)
|
||||
|
||||
|
||||
def enumerate_collections(collections):
|
||||
for collection in collections:
|
||||
yield msg.ChildCollection(collection)
|
||||
|
||||
|
||||
def handle_path(path, operation, configmanager, inputdata=None):
|
||||
'''Given a full path request, return an object.
|
||||
|
||||
@ -152,6 +163,11 @@ def handle_path(path, operation, configmanager, inputdata=None):
|
||||
try:
|
||||
node = pathcomponents[1]
|
||||
except IndexError: # doesn't actually have a long enough path
|
||||
# this is enumerating a list of nodes
|
||||
if operation == "delete":
|
||||
raise exc.InvalidArgumentException()
|
||||
if operation == "create":
|
||||
create_node(inputdata, configmanager)
|
||||
return iterate_collections(configmanager.get_nodes())
|
||||
if iscollection:
|
||||
if operation == "delete":
|
||||
|
Loading…
x
Reference in New Issue
Block a user