コード例 #1
0
ファイル: hitparade.py プロジェクト: atombaby/python-moab
def get_node_reservations():
    """
    Return a dictionary where node is the key and RsvParent 
    is the value.  Reservation must be Type == User and 
    have a SubType of StandingReservation.
    """
    s = Scheduler()
    # Dictionary where 
    node_reservations = {}

    # Command to execute that returns some xml, initializes element tree.
    r = et.fromstring(
        s.doCommand( [ "mdiag", "--xml", '-r', ] )
    )

    # Element tree has data at the root, and likely 1 or more rsv children.
    for q in r.findall( 'rsv' ):
        # Instantiate a Reservation, where xml attributes map to object properties.
        # q.attrib is a dictionary of attributes and their values.
        rsv = Reservation( q.attrib )
        #if rsv.Type == "User" and rsv.SubType == "StandingReservation" and rsv.RsvGroup != "iactive":
        #if not is_private( rsv ):
        if is_private( rsv ):
            logging.debug( "Found reservation: %s", rsv.Name )
            for n in rsv.AllocNodeList:
                # Question here, any chance more than one reservation
                # could include the same node, but with different 
                # RsvParents?  Last in wins?
                node_reservations[ n ] = rsv.RsvParent
                logging.debug( "Added node %s to reserved node list", n )

    return node_reservations
コード例 #2
0
ファイル: hitparade.py プロジェクト: atombaby/python-moab
def get_jobs(all_jobs=False):
    """
    Build up a dictionary of jobs.  Key is job_id, value is
    a list containing AllocNodeList, User and Account.
    """
    s = Scheduler()
    r = et.fromstring(
        s.doCommand( [ "mdiag", "--xml", '-j', ] )
    )

    jobs = {}
    for j in r.findall( 'job' ):
        job = Job( dict( j.attrib.items() + j.find('req').items() ))
        # Add all running jobs if --all, otherwise filter out preemptees.
        if (job.State == 'Running' and all_jobs) or \
           (job.State == 'Running' and "PREEMPTEE" not in job.Flags and not
           all_jobs): 
            jobs[ job.JobID ] = [
                job.AllocNodeList,
                job.User,
                job.Account,
            ]
    return jobs
コード例 #3
0
ファイル: checkrm.py プロジェクト: atombaby/python-moab
from mwm.queue import getIdleJobSummary

CRITICAL = 2
WARNING = 1
OK = 0
pmsg = [ 'OK', 'WARNING', 'CRITICAL' ]


def update( cval, nval ):
    if nval > cval:
        return nval
    else:
        return cval

try:
    s = Scheduler()
except:
    print "UNABLE TO CONNECT TO SCHEDULER"
    sys.exit( CRITICAL )

message = []
xtv = OK

state = s.getRMData()['STATE']

if state == 'Active' and s.state == 'RUNNING':
    message.append( "RM and Scheduler running" )
    xtv = update( xtv, OK )

elif state == 'Active' and s.state != 'RUNNING':
    message.append( "SCHEDULER NOT RUNNING" )
コード例 #4
0
ファイル: hitparade.py プロジェクト: atombaby/python-moab
def get_counts(node_reservations, jobs):
    """
    Provide counts for total public core usage and 
    broken down by user and account.
    """
    s = Scheduler()

    # create count of public nodes in campus class
    r = et.fromstring(
        s.doCommand( [ "mdiag", "--xml", '-n', ] )
    )

    public_nodes = []
    public_cores = 0
    logging.debug( "Looking for public nodes" )
    for n in r.findall( 'node' ):
        node = Node( n.attrib )
        # When node.CFGCLASS does not contain 'campus', this is not a public
        # node. Also skip if node has an associated reservation. Node 
        # is added to public_nodes list in all other cases.
        if node.NODESTATE == 'Drained' or node.NODESTATE == 'Down':
            logging.debug( "node %s is %s", node.NODEID, node.NODESTATE )
            continue
        if 'campus' not in node.CFGCLASS:
            logging.debug( "node %s not in campus class", node.NODEID )
            continue
        if node.NODEID in node_reservations:
            logging.debug( "node %s in private reservation %s", node.NODEID, node_reservations[ node.NODEID ] )
            continue

        public_nodes.append( node.NODEID )
        logging.debug( "node %s added to public list",  node.NODEID )
        public_cores += node.RCPROC
        logging.debug( "added %s cores from node %s added to public core total", node.RCPROC, node.NODEID )

    cred_totals = {}
    # { 'cred':cores }
    # Copy the list to later subtract in-use nodes.
    public_nodes_free = public_nodes[:]
    for job in jobs.values():
        logging.debug( "Counting job with creds %s", job )
        for node in job[0]:
            job_cred = job[1] + " (" + job[2] + ")"
            if node in public_nodes:
                logging.debug( "node %s is public", node )
                o = [
                    job[0][node],
                    node,
                    'public',
                    job_cred,
                ]
                # Remove public nodes that have at least one 
                # core in use from public_nodes_free
                if node in public_nodes_free: 
                    del public_nodes_free[public_nodes_free.index(node)]
                try:
                    cred_totals[ job_cred ] = (
                        cred_totals[ job_cred ] + job[0][node]
                    )
                except KeyError:
                    cred_totals[ job_cred ] = job[0][node]

    logging.debug( "Nodes Free: %s", public_nodes_free )
    logging.debug( "Cred totals: %s", cred_totals )
    return cred_totals, public_cores, len(public_nodes), len(public_nodes_free)
コード例 #5
0
ファイル: nodesum.py プロジェクト: atombaby/python-moab
argv = parser.parse_args()

if argv.debug:
    logging.basicConfig( level=logging.DEBUG )
    print argv.debug
else:
    logging.basicConfig( level=logging.WARNING )

try:
    from mwm.scheduler import Scheduler
    from mwm.mtypes import Reservation, Job, Node
except ImportError:
    logging.exception( "Moab client libraries not found" )
    sys.exit(1)

s = Scheduler()

# Collect reservations
# { reservation name:mwm.Reservation.Name }
reservations = {}
r = et.fromstring(
    s.doCommand( [ "mdiag", "--xml", '-r', ] )
)

for q in r.findall( 'rsv' ):
    rsv = Reservation( q.attrib )
    reservations[ rsv.Name ] = rsv
    logging.debug( "Added reservation: %s", rsv.Name )

# Collect jobs
# { jobid:mwm.Job.JobID }