Exemplo n.º 1
0
def get_nodes_dict():
    """Get the pbs_nodes equivalent info as dict"""
    query = get_query()
    node_states = query.getnodes([])
    for name, full_state in node_states.items():
        # just add states
        states = full_state[ATTR_STATE]
        if ND_free in states and ATTR_JOBS in full_state:
            _log.debug('Added free_and_job node %s' % (name))
            states.insert(0, ND_free_and_job)
        if ND_free in states and ATTR_JOBS not in full_state:
            _log.debug('Append idle node %s' % (name))
            states.append(ND_idle)  # append it, not insert
        if ND_offline in states and ATTR_JOBS not in full_state:
            _log.debug('Append idle node %s' % (name))
            states.append(ND_idle)

        if ATTR_ERROR in full_state:
            _log.debug('Added error node %s' % (name))
            states.insert(0, ND_error)
        if ND_down in states and ATTR_ERROR in full_state:
            _log.debug('Added down_on_error node %s' % (name))
            states.insert(0, ND_down_on_error)

        # extend the node dict with derived dict (for convenience)
        derived = {}
        if ATTR_JOBS in full_state:
            jobs = full_state.get_jobs()
            if not all(JOBID_REG.search(x.strip()) for x in jobs):
                _log.debug('Added bad node %s for jobs %s' % (name, jobs))
                states.insert(0, ND_bad)
            derived[ATTR_JOBS] = jobs

        derived[ATTR_STATES] = [str(x) for x in states]
        make_state_map(derived)

        if ATTR_NP in full_state:
            derived[ATTR_NP] = int(full_state[ATTR_NP][0])
        if ATTR_STATUS in full_state:
            status = full_state[ATTR_STATUS]
            for prop in ['physmem', 'totmem', 'size']:
                if prop not in status:
                    continue
                val = status.get(prop)[0]
                if prop in ('size',):
                    # 'size': ['539214180kb:539416640kb']
                    # - use 2nd field
                    val = val.split(':')[1]
                derived[prop] = str2byte(val)

        full_state['derived'] = derived
        _log.debug("node %s derived data %s " % (name, derived))

    return node_states
Exemplo n.º 2
0
def get_nodes_dict():
    """Get the pbs_nodes equivalent info as dict"""
    query = get_query()
    node_states = query.getnodes([])
    for name, full_state in node_states.items():
        # just add states
        states = full_state[ATTR_STATE]
        if ND_free in states and ATTR_JOBS in full_state:
            _log.debug('Added free_and_job node %s' % (name))
            states.insert(0, ND_free_and_job)
        if ND_free in states and ATTR_JOBS not in full_state:
            _log.debug('Append idle node %s' % (name))
            states.append(ND_idle)  # append it, not insert
        if ND_offline in states and ATTR_JOBS not in full_state:
            _log.debug('Append idle node %s' % (name))
            states.append(ND_idle)

        if ATTR_ERROR in full_state:
            _log.debug('Added error node %s' % (name))
            states.insert(0, ND_error)
        if ND_down in states and ATTR_ERROR in full_state:
            _log.debug('Added down_on_error node %s' % (name))
            states.insert(0, ND_down_on_error)

        # extend the node dict with derived dict (for convenience)
        derived = {}
        if ATTR_JOBS in full_state:
            jobs = full_state.get_jobs()
            if not all(JOBID_REG.search(x.strip()) for x in jobs):
                _log.debug('Added bad node %s for jobs %s' % (name, jobs))
                states.insert(0, ND_bad)
            derived[ATTR_JOBS] = jobs

        derived[ATTR_STATES] = [str(x) for x in states]
        make_state_map(derived)

        if ATTR_NP in full_state:
            derived[ATTR_NP] = int(full_state[ATTR_NP][0])
        if ATTR_STATUS in full_state:
            status = full_state[ATTR_STATUS]
            for prop in ['physmem', 'totmem', 'size']:
                if prop not in status:
                    continue
                val = status.get(prop)[0]
                if prop in ('size', ):
                    # 'size': ['539214180kb:539416640kb']
                    # - use 2nd field
                    val = val.split(':')[1]
                derived[prop] = str2byte(val)

        full_state['derived'] = derived
        _log.debug("node %s derived data %s " % (name, derived))

    return node_states
Exemplo n.º 3
0
def get_jobs(attrs=None):
    """
    Get the jobs

    attrs is an optional list of PBS ATTR_ attribute names
        default is None, which uses a predefined set of attributes, i.e. not all
        if attrs is string 'ALL', gather all attributes
    """
    query = get_query()

    attrib_list = None

    if isinstance(attrs, basestring) and attrs == 'ALL':
        attrs = None
    elif attrs is None:
        attrs = DEFAULT_ATTRS

    if attrs is not None:
        attrib_list = filter(None, [getattr(pbs, 'ATTR_'+x, None) for x in attrs])

    jobs = query.getjobs(attrib_list=attrib_list)
    return jobs
Exemplo n.º 4
0
def get_jobs():
    """Get the jobs"""
    query = get_query()
    jobs = query.getjobs()
    return jobs
Exemplo n.º 5
0
def get_queues():
    """Get the queues"""
    query = get_query()
    queues = query.getqueues()
    return queues
Exemplo n.º 6
0
def get_queues():
    """Get the queues"""
    query = get_query()
    queues = query.getqueues()
    return queues