app = flask.Flask(APPNAME)
LOGLEVELS = {
- 'critical':logging.CRITICAL,
- 'error':logging.ERROR,
- 'warning':logging.WARNING,
- 'info':logging.INFO,
- 'debug':logging.DEBUG,
+ 'critical': logging.CRITICAL,
+ 'error': logging.ERROR,
+ 'warning': logging.WARNING,
+ 'info': logging.INFO,
+ 'debug': logging.DEBUG,
}
return int(osds[-1])
-METHOD_DICT = {'r':['GET'], 'w':['PUT', 'DELETE']}
+METHOD_DICT = {'r': ['GET'], 'w': ['PUT', 'DELETE']}
def api_setup(app, conf, cluster, clientname, clientid, args):
signatures, module, perms, and help; stuff them away in the app.ceph_urls
dict. Also save app.ceph_sigdict for help() handling.
'''
- def get_command_descriptions(cluster, target=('mon','')):
+ def get_command_descriptions(cluster, target=('mon', '')):
ret, outbuf, outs = json_command(cluster, target,
prefix='get_command_descriptions',
timeout=30)
for k in METHOD_DICT.iterkeys():
if k in perm:
methods = METHOD_DICT[k]
- urldict = {'paramsig':params,
- 'help':cmddict['help'],
- 'module':cmddict['module'],
- 'perm':perm,
- 'flavor':flavor,
- 'methods':methods,
+ urldict = {'paramsig': params,
+ 'help': cmddict['help'],
+ 'module': cmddict['module'],
+ 'perm': perm,
+ 'flavor': flavor,
+ 'methods': methods,
}
# app.ceph_urls contains a list of urldicts (usually only one long)
# tack it onto the front of sig
if flavor == 'tell':
tellsig = parse_funcsig(['tell',
- {'name':'target', 'type':'CephOsdName'}])
+ {'name': 'target', 'type': 'CephOsdName'}])
sig = tellsig + sig
for desc in sig:
# XXX There ought to be a better discovery mechanism than an HTML table
s = '<html><body><table border=1><th>Possible commands:</th><th>Method</th><th>Description</th>'
- permmap = {'r':'GET', 'rw':'PUT', 'rx':'GET', 'rwx':'PUT'}
+ permmap = {'r': 'GET', 'rw': 'PUT', 'rx': 'GET', 'rwx': 'PUT'}
line = ''
for cmdsig in sorted(app.ceph_sigdict.itervalues(), cmp=descsort):
concise = concise_sig(cmdsig['sig'])
if 'json' in fmt:
try:
native_output = json.loads(output or '[]')
- response = json.dumps({"output":native_output,
- "status":statusmsg})
+ response = json.dumps({"output": native_output,
+ "status": statusmsg})
except:
return flask.make_response("Error decoding JSON from " +
output, 500)
# one is tempted to do this with xml.etree, but figuring out how
# to 'un-XML' the XML-dumped output so it can be reassembled into
# a piece of the tree here is beyond me right now.
- #ET = xml.etree.ElementTree
- #resp_elem = ET.Element('response')
- #o = ET.SubElement(resp_elem, 'output')
- #o.text = output
- #s = ET.SubElement(resp_elem, 'status')
- #s.text = statusmsg
- #response = ET.tostring(resp_elem)
+ # ET = xml.etree.ElementTree
+ # resp_elem = ET.Element('response')
+ # o = ET.SubElement(resp_elem, 'output')
+ # o.text = output
+ # s = ET.SubElement(resp_elem, 'status')
+ # s.text = statusmsg
+ # response = ET.tostring(resp_elem)
response = '''
<response>
<output>
if not ep.startswith(app.ceph_baseurl):
return make_response(fmt, '', 'Page not found', 404)
- rel_ep = ep[len(app.ceph_baseurl)+1:]
+ rel_ep = ep[len(app.ceph_baseurl) + 1:]
# Extensions override Accept: headers override defaults
if not fmt:
response = make_response(fmt, outbuf, outs or 'OK', 200)
if fmt:
- contenttype = 'application/' + fmt.replace('-pretty','')
+ contenttype = 'application/' + fmt.replace('-pretty', '')
else:
contenttype = 'text/plain'
response.headers['Content-Type'] = contenttype