Changeset 321
- Timestamp:
- 09/29/14 15:12:50 (10 years ago)
- Location:
- trunk/examples
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/new_rack_pbsmon.py
r316 r321 306 306 p.new_data_structure() 307 307 308 attr = [ 'state', 'jobs', 'properties' ]308 attr = [ 'state', 'jobs', 'properties', 'jobs' ] 309 309 310 310 try: … … 426 426 return [ item for index, item in decorated ] 427 427 428 def print_table(properties=None ):428 def print_table(properties=None, jobs=None): 429 429 global START_RACK 430 430 global OPT_SKIP_EMPTY_RACKS … … 475 475 try: 476 476 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: 478 488 _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=' ') 479 493 else: 480 494 _print('M', end=' ') … … 557 571 if not (n & 1): 558 572 _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 581 def print_extended(hosts=None, properties=None, jobs=None): 561 582 global LENGTH_NODE 562 583 global LENGTH_STATE … … 569 590 rows_str = list() 570 591 ihosts = real_sort( ihosts ) 571 572 592 for node in ihosts: 573 593 attr = nodes[ node ] 594 595 if jobs and not compare_lists(jobs, attr['jobs']): 596 continue 574 597 575 598 if properties and not compare_lists(properties, attr['properties']): … … 597 620 598 621 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) 606 630 parser.add_argument('--version', action='version', version=pbs.version) 607 631 … … 629 653 args.properties = [ item.strip() for item in args.properties.split(',') ] 630 654 655 if args.jobs: 656 args.jobs = [ item.strip() for item in args.jobs.split(',') ] 657 631 658 if args.extended: 632 print_extended(args.nodes, args.properties )659 print_extended(args.nodes, args.properties, args.jobs) 633 660 elif args.table: 634 print_table(args.properties )661 print_table(args.properties, args.jobs) 635 662 else: 636 663 _print('Something is wrong, bye!', file=sys.stderr) -
trunk/examples/sara_nodes.py
r295 r321 167 167 return rlist 168 168 169 def 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 169 184 ## END functions for hostrange parsing 170 185 #### … … 548 563 ) 549 564 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') 550 566 parser.add_argument('-v','--verbose', action='store_true', help='enables verbose mode') 551 567 parser.add_argument('-n','--dry-run', action='store_true', help='enables dry-run mode') … … 573 589 _print('func:__main__ checking type of operation', file=sys.stderr) 574 590 575 if args.nodes: 591 if args.nodes and args.jobs: 592 args.nodes = get_nodes(args.nodes) 593 elif args.nodes: 576 594 args.nodes = parse_args(args.nodes) 577 595
Note: See TracChangeset
for help on using the changeset viewer.