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')
def get_jobs_by_qos(): jobs = get_from_cache(pyslurm.job().get, 'get_jobs') qos = get_from_cache(pyslurm.qos().get, 'get_qos') returned_qos = {} for qos_id, q in qos.iteritems(): returned_jobs = {} # filter jobs by node for jobid, job in jobs.iteritems(): if qos_id == job['qos']: returned_jobs[jobid] = job returned_qos[qos_id] = filter_entities('jobs', returned_jobs) return returned_qos
def get_jobs_by_nodes(): jobs = get_from_cache(pyslurm.job().get, 'get_jobs') nodes = get_from_cache(pyslurm.node().get, 'get_nodes') returned_nodes = {} for node_id, node in nodes.iteritems(): returned_jobs = {} # filter jobs by node for jobid, job in jobs.iteritems(): nodes_list = job['cpus_allocated'].keys() if node_id in nodes_list: returned_jobs[jobid] = job returned_nodes[node_id] = filter_entities('jobs', returned_jobs) return returned_nodes
def get_qos(): try: qos = get_from_cache(pyslurm.qos().get, 'get_qos') # for all TRES limits of all QOS, replace TRES type IDs by their # textual form using tres_convert_ids() for qos_name in qos: xqos = qos[qos_name] for key, value in xqos.iteritems(): if value is not None and key.find('_tres') > 0: qos[qos_name][key] = convert_tres_ids(value) except Exception as e: qos = {'error': str(e)} return qos
def get_jobs(): jobs = get_from_cache(pyslurm.job().get, 'get_jobs') for jobid, job in jobs.iteritems(): # add login and user's name (additionally to UID) for each job try: fill_job_user(job) except (KeyError): pass # convert nodeset in array of nodes if job["nodes"] is not None: jobs[jobid]["nodeset"] = list( NodeSet(job["nodes"].encode('ascii', 'ignore'))) return filter_entities('jobs', jobs)
def get_jobs_by_node_id(node_id): jobs = get_from_cache(pyslurm.job().get, 'get_jobs') returned_jobs = {} # filter jobs by node for jobid, job in jobs.iteritems(): nodes_list = job['cpus_allocated'].keys() if node_id in nodes_list: returned_jobs[jobid] = job for jobid, job in returned_jobs.iteritems(): fill_job_user(job) return filter_entities('jobs', returned_jobs)
def get_topology(): try: topology = get_from_cache(pyslurm.topology().get, 'get_topology') # As of pyslurm 15.08.0~git20160229-2, switches and nodes dict members # are strings (or None eventually) representing the hostlist of devices # connected to the switch. These hostlist are expanded in lists using # Clustershell Nodeset() into new corresponding *list members. for switch in topology.itervalues(): if switch['switches'] is not None: switch['switchlist'] = list(NodeSet(switch['switches'])) if switch['nodes'] is not None: switch['nodelist'] = list(NodeSet(switch['nodes'])) except Exception as e: topology = {'error': str(e)} return topology
def show_job(job_id): # PySLURM >= 16.05 expects a string in parameter of job.find_id() and # returns a list. The expected job dict is the 1st element of this list. job = get_from_cache(pyslurm.job.find_id, 'show_job', str(job_id))[0] onlyUsersJobs = False fill_job_user(job) if auth_enabled: # If auth_enabled is true, getting the current user becomes # possible because authentification_verify decorator has been # already checked. currentUser = get_current_user() onlyUsersJobs = check_private_data_for_entity(currentUser, 'jobs') if (onlyUsersJobs and job['login'] != currentUser.login): raise AllUnauthorizedError return job
def get_jobs_by_node_ids(): jobs = get_from_cache(pyslurm.job().get, 'get_jobs') nodes = json.loads(request.data).get('nodes', []) returned_jobs = {} # filter jobs by node for jobid, job in jobs.iteritems(): nodes_list = job['cpus_allocated'].keys() for node_id in nodes: if node_id in nodes_list: returned_jobs[jobid] = job for jobid, job in returned_jobs.iteritems(): fill_job_user(job) return filter_entities('jobs', returned_jobs)
def get_partitions(): partitions = get_from_cache(pyslurm.partition().get, 'get_partitions') return partitions
def get_reservations(): reservations = get_from_cache(pyslurm.reservation().get, 'get_reservations') return filter_entities('reservations', reservations)
def get_racks(): try: racks = get_from_cache(parse_racks, 'get_racks') except Exception as e: racks = {'error': str(e)} return racks
def get_nodes(): nodes = get_from_cache(pyslurm.node().get, 'get_nodes') return nodes
def get_config(service): return jsonify(get_from_cache(service)), 200