2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-23 01:53:28 +00:00

Fix API explorer to do list type attributes

This commit is contained in:
Jarrod Johnson 2014-02-13 15:55:26 -05:00
parent 41c4183045
commit 722d0fe128
4 changed files with 17 additions and 8 deletions

View File

@ -52,7 +52,7 @@ nic = {
# 'node', which can be considered a 'system' or a 'vm'
node = {
'groups': {
'type': (list, tuple),
'type': list,
'default': 'all',
'description': ('List of static groups for which this node is '
'considered a member'),

View File

@ -575,7 +575,7 @@ class ConfigManager(object):
for attrname in attribmap[node].iterkeys():
if (attrname not in attributes.node or
('type' in attributes.node[attrname] and
type(attribmap[node][attrname]) not in attributes.node[attrname]['type'])):
not isinstance(attribmap[node][attrname],attributes.node[attrname]['type'])):
raise ValueError
newdict = {}
if (isinstance(attribmap[node][attrname], str)):

View File

@ -38,11 +38,15 @@ def node_creation_resources():
if attr.startswith("secret."):
yield confluent.messages.CryptedAttributes(
kv={attr: None},
desc=attribs.node[attr]['description']).html() + '<br>'
desc=attribs.node[attr]['description']).html() + '<br>\n'
elif 'type' in attribs.node[attr] and list == attribs.node[attr]['type']:
yield confluent.messages.ListAttributes(
kv={attr: []},
desc=attribs.node[attr]['description']).html() + '<br>\n'
else:
yield confluent.messages.Attributes(
kv={attr: None},
desc=attribs.node[attr]['description']).html() + '<br>'
desc=attribs.node[attr]['description']).html() + '<br>\n'
create_resource_functions = {
'/node/': node_creation_resources,

View File

@ -45,6 +45,10 @@ class ConfluentMessage(object):
value = '********'
if isinstance(val, list):
snippet += key + ":"
if len(val) == 0:
snippet += ('<input type="{0}" name="{1}" value="" '
' "title="{2}">'
).format(type, key, self.desc)
for v in val:
snippet += ('<input type="{0}" name="{1}" value="{2}" '
' "title="{3}">'
@ -274,11 +278,12 @@ class Attributes(ConfluentMessage):
class ListAttributes(ConfluentMessage):
def __init__(self, node, kv, desc=''):
def __init__(self, node=None, kv=None, desc=''):
self.desc = desc
self .kvpairs = {
node: kv
}
if node is None:
self.kvpairs = kv
else:
self .kvpairs = {node: kv}
class CryptedAttributes(Attributes):