Reputation: 626
I am trying to make slurm-web code working. in restapi.py, there is a def sinfo() method which reads as follows:
@app.route('/sinfo', methods=['GET', 'OPTIONS'])
@crossdomain(origin=origins, methods=['GET'],
headers=['Accept', 'Content-Type', 'X-Requested-With', 'Authorization'])
@authentication_verify()
def sinfo():
# Partition and node lists are required
# to compute sinfo informations
partitions = get_from_cache(pyslurm.partition().get, 'get_partitions')
nodes = get_from_cache(pyslurm.node().get, 'get_nodes')
# Retreiving the state of each nodes
nodes_state = dict(
(node.lower(), attributes['state'].lower())
for node, attributes in nodes.iteritems()
)
# For all partitions, retrieving the states of each nodes
sinfo_data = {}
for name, attr in partitions.iteritems():
for node in list(NodeSet(attr['nodes'])):
key = (name, nodes_state[node])
if key not in sinfo_data.keys():
sinfo_data[key] = []
sinfo_data[key].append(node)
# Preparing the response
resp = []
for k, nodes in sinfo_data.iteritems():
name, state = k
partition = partitions[name]
avail = partition['state'].lower()
min_nodes = partition['min_nodes']
max_nodes = partition['max_nodes']
total_nodes = partition['total_nodes']
job_size = "{0}-{1}".format(min_nodes, max_nodes)
job_size = job_size.replace('UNLIMITED', 'infinite')
time_limit = partition['max_time_str'].replace('UNLIMITED', 'infinite')
# Creating the nodeset
nodeset = NodeSet()
map(nodeset.update, nodes)
resp.append({
'name': name,
'avail': avail,
'job_size': job_size,
'time_limit': time_limit,
'nodes': total_nodes,
'state': state,
'nodelist': str(nodeset),
})
# Jsonify can not works on list, thus using json.dumps
# And making sure headers are properly set
return make_response(json.dumps(resp), mimetype='application/json')
apache error log says that return make_response(json.dumps(resp), mimetype='application/json') TypeError: make_response() got an unexpected keyword argument 'mimetype'
I am using flase 1.0.2 and wondering what makes this error.
Upvotes: 0
Views: 232
Reputation: 24966
First, you'll need to indent that return
so that it happens at the end of sinfo()
. Then you can simplify by writing
from flask import jsonify
...
def sinfo():
...
return jsonify(resp)
Upvotes: 0