Changeset 321


Ignore:
Timestamp:
09/29/14 15:12:50 (10 years ago)
Author:
dennis
Message:

Added a new feature which allows you to specify jobnumbers to see the status of the nodes

Location:
trunk/examples
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/new_rack_pbsmon.py

    r316 r321  
    306306    p.new_data_structure()
    307307
    308     attr = [ 'state', 'jobs', 'properties' ]
     308    attr = [ 'state', 'jobs', 'properties', 'jobs' ]
    309309
    310310    try:
     
    426426    return [ item for index, item in decorated ]
    427427
    428 def print_table(properties=None):
     428def print_table(properties=None, jobs=None):
    429429    global START_RACK
    430430    global OPT_SKIP_EMPTY_RACKS
     
    475475            try:
    476476                if properties and compare_lists(properties,nodes[ rack ][ node ]['properties']):
    477                     if TERMINAL_COLOR:
     477                    prop_color = True
     478                else:
     479                    prop_color = False
     480
     481                if jobs and compare_lists(jobs, nodes[ rack ][ node ]['jobs']):
     482                    job_color = True
     483                else:
     484                    job_color = False
     485
     486                if prop_color or job_color:
     487                    if TERMINAL_COLOR and prop_color and job_color:
    478488                        _print(color.GREEN + nodes[ rack ][ node ][ 'state_char' ] + color.END, end=' ')
     489                    elif TERMINAL_COLOR and  prop_color:
     490                        _print(color.BLUE + nodes[ rack ][ node ][ 'state_char' ] + color.END, end=' ')
     491                    elif TERMINAL_COLOR and  job_color:
     492                        _print(color.YELLOW + nodes[ rack ][ node ][ 'state_char' ] + color.END, end=' ')
    479493                    else:
    480494                        _print('M', end=' ')
     
    557571        if not (n & 1):
    558572            _print()
    559 
    560 def print_extended(hosts=None, properties=None):
     573 
     574    if TERMINAL_COLOR:
     575        _print()
     576        _print('Colors has been enabled for your terminal:')
     577        _print(' - ' + color.YELLOW + 'Matched jobs' + color.END)
     578        _print(' - ' + color.BLUE + 'Matched properties' + color.END)
     579        _print(' - ' + color.GREEN + 'Matched jobs and properties' + color.END)
     580
     581def print_extended(hosts=None, properties=None, jobs=None):
    561582    global LENGTH_NODE
    562583    global LENGTH_STATE
     
    569590    rows_str = list()
    570591    ihosts = real_sort( ihosts )
    571 
    572592    for node in ihosts:
    573593        attr = nodes[ node ]
     594
     595        if jobs and not compare_lists(jobs, attr['jobs']):
     596            continue
    574597
    575598        if properties and not compare_lists(properties, attr['properties']):
     
    597620
    598621    parser.add_argument('nodes', metavar='NODES', nargs='*', type=str)
    599     parser.add_argument( "-t", "--table", dest="table", action="store_true", help="Show an table", default=PRINT_TABLE )
    600     parser.add_argument( "-l", "--list", dest="extended", action="store_true", help="Show node rows with state and jobinfo", default=PRINT_EXTENDED )
    601     parser.add_argument( "-s", "--summary", dest="summary", action="store_true", help="Display a short summary", default=False )
    602     parser.add_argument( "-a", "--all", dest="summary", action="store_true", help="Display a short summary" )
    603     parser.add_argument( "-w", "--wide", dest="wide", action="store_true", help="Wide display for node status ( only when -t is used )" )
    604     parser.add_argument( "-S", "--servername", dest="servername", help="Change the default servername", default=None )
    605     parser.add_argument( "-p", "--properties", dest="properties", help="Show nodes with property, you can use more than 1 property by using , (this is always een and) ie. -p infiniband,mem64gb", default=None)
     622    parser.add_argument("-t", "--table", dest="table", action="store_true", help="Show an table", default=PRINT_TABLE )
     623    parser.add_argument("-l", "--list", dest="extended", action="store_true", help="Show node rows with state and jobinfo", default=PRINT_EXTENDED )
     624    parser.add_argument("-s", "--summary", dest="summary", action="store_true", help="Display a short summary", default=False )
     625    parser.add_argument("-a", "--all", dest="summary", action="store_true", help="Display a short summary" )
     626    parser.add_argument("-w", "--wide", dest="wide", action="store_true", help="Wide display for node status ( only when -t is used )" )
     627    parser.add_argument("-S", "--servername", dest="servername", help="Change the default servername", default=None )
     628    parser.add_argument("-p", "--properties", dest="properties", help="Show nodes with property, you can use more than 1 property by using , (this is always een and) ie. -p infiniband,mem64gb", default=None)
     629    parser.add_argument("-j", "--job", dest="jobs", help="Show which nodes are uses by a job", default=None)
    606630    parser.add_argument('--version', action='version', version=pbs.version)
    607631
     
    629653        args.properties = [ item.strip() for item in args.properties.split(',') ]
    630654
     655    if args.jobs:
     656        args.jobs = [ item.strip() for item in args.jobs.split(',') ]
     657
    631658    if args.extended:
    632         print_extended(args.nodes, args.properties)
     659        print_extended(args.nodes, args.properties, args.jobs)
    633660    elif args.table:
    634         print_table(args.properties)
     661        print_table(args.properties, args.jobs)
    635662    else:
    636663        _print('Something is wrong, bye!', file=sys.stderr)
  • trunk/examples/sara_nodes.py

    r295 r321  
    167167    return rlist
    168168
     169def get_nodes(jobs):
     170
     171    p = PBSQuery.PBSQuery()
     172    nodes = list()
     173
     174    for job in jobs:
     175        exec_hosts = p.getjob(job, ['exec_host'])
     176        if not exec_hosts or 'exec_host' not in exec_hosts:
     177            continue
     178        for exec_host in exec_hosts['exec_host'][0].split('+'):
     179            hostname = exec_host.split('/')[0]
     180            if hostname not in nodes:
     181                nodes.append(hostname)
     182    return nodes
     183
    169184## END functions for hostrange parsing
    170185####
     
    548563    )
    549564    parser.add_argument('nodes', metavar='NODES', nargs='*', type=str)
     565    parser.add_argument('-j', '--jobs', action='store_true', help='use job id\'s instead of nodenames')
    550566    parser.add_argument('-v','--verbose', action='store_true', help='enables verbose mode')
    551567    parser.add_argument('-n','--dry-run', action='store_true', help='enables dry-run mode')
     
    573589        _print('func:__main__ checking type of operation', file=sys.stderr)
    574590
    575     if args.nodes:
     591    if args.nodes and args.jobs:
     592        args.nodes = get_nodes(args.nodes)
     593    elif args.nodes:
    576594        args.nodes = parse_args(args.nodes)
    577595
Note: See TracChangeset for help on using the changeset viewer.