Changeset 314


Ignore:
Timestamp:
06/04/14 11:15:48 (10 years ago)
Author:
dennis
Message:

New version of new_rack_pbsmon, now with option -p to filter the output based on node properties, it is a and operation. For example -p infiniband,mem64gb select all nodes with properties infiniband and mem64gb

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/new_rack_pbsmon.py

    r295 r314  
    3636from PBSQuery import PBSQuery
    3737from PBSQuery import PBSError
     38
     39## This RE pattern is used for the hostrange
     40HOSTRANGE = r'\[([0-9az\-,]+)\]'
    3841
    3942# Remark: When both are True, extended view is being printed
     
    97100    pbs_ND_total            : ' '
    98101}
     102
     103## Color support?
     104import curses
     105curses.setupterm()
     106if curses.tigetnum("colors") > 8:
     107    TERMINAL_COLOR=True
     108else:
     109    TERMINAL_COLOR=False
    99110
    100111####
     
    126137                write(kwargs.get('end', '\n'))
    127138
     139class color:
     140    PURPLE = '\033[95m'
     141    CYAN = '\033[96m'
     142    DARKCYAN = '\033[36m'
     143    BLUE = '\033[94m'
     144    GREEN = '\033[92m'
     145    YELLOW = '\033[93m'
     146    RED = '\033[91m'
     147    BOLD = '\033[1m'
     148    UNDERLINE = '\033[4m'
     149    END = '\033[0m'
     150
     151def compare_lists(list_a, list_b):
     152    return not any(x not in list_b for x in list_a)
     153
    128154## Import argparse here, as I need the _print function
    129155try:
     
    342368            else:
    343369                nodes_dict[ racknr ][ nodenr ][ 'jobs' ] = []
     370
     371            if attr.has_key( 'properties' ):
     372                nodes_dict[ racknr ][ nodenr ][ 'properties' ] = attr.properties
     373            else:
     374                nodes_dict[ racknr ][ nodenr ][ 'properties' ] = []
     375
    344376        else:
    345377            hosts_list.append( node )
     
    352384                nodes_dict[ node ][ 'jobs' ] = []
    353385
     386            if attr.has_key( 'properties' ):
     387                nodes_dict[ node ][ 'properties' ] = attr.properties
     388            else:
     389                nodes_dict[ node ][ 'properties' ] = []
     390
    354391    if not racknode:
    355392        return nodes_dict, hosts_list
     
    389426    return [ item for index, item in decorated ]
    390427
    391 def print_table():
     428def print_table(properties=None):
    392429    global START_RACK
    393430    global OPT_SKIP_EMPTY_RACKS
     
    437474                    continue
    438475            try:
    439                 _print(nodes[ rack ][ node ][ 'state_char' ], end=' ')
     476                if properties and compare_lists(properties,nodes[ rack ][ node ]['properties']):
     477                    if TERMINAL_COLOR:
     478                        _print(color.GREEN + nodes[ rack ][ node ][ 'state_char' ] + color.END, end=' ')
     479                    else:
     480                        _print('M', end=' ')
     481                else:
     482                    _print(nodes[ rack ][ node ][ 'state_char' ], end=' ')
    440483            except KeyError:
    441484                _print(' ', end=' ')
     
    515558            _print()
    516559
    517 def print_extended( hosts=None ):
     560def print_extended(hosts=None, properties=None):
    518561    global LENGTH_NODE
    519562    global LENGTH_STATE
     
    529572    for node in ihosts:
    530573        attr = nodes[ node ]
     574
     575        if properties and not compare_lists(properties, attr['properties']):
     576            continue
     577
    531578        row_str = EXTENDED_PATTERNS[ 'row' ] % ( ( LENGTH_NODE + 2 ), node, ( LENGTH_STATE + 2 ), attr[ 'state' ], ','.join( attr[ 'jobs' ] ) )
    532579
     
    556603    parser.add_argument( "-w", "--wide", dest="wide", action="store_true", help="Wide display for node status ( only when -t is used )" )
    557604    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)
    558606
    559607    args = parser.parse_args()
     608
    560609    if args.nodes:
    561610        args.nodes = parse_args(args.nodes)
     
    576625        args.extended = False
    577626
     627    if args.properties:
     628        args.properties = [ item.strip() for item in args.properties.split(',') ]
     629
    578630    if args.extended:
    579         print_extended( args.nodes )
     631        print_extended(args.nodes, args.properties)
    580632    elif args.table:
    581         print_table()
     633        print_table(args.properties)
    582634    else:
    583635        _print('Something is wrong, bye!', file=sys.stderr)
Note: See TracChangeset for help on using the changeset viewer.