def main(): """ get-bootable-blocks main """ # setup logging for client. The clients should call this before doing anything else. client_utils.setup_logging(logging.INFO) # list of callback with its arguments callbacks = [ # <cb function> <cb args> [ cb_debug , () ], [ cb_gtzero , (True,) ], # return int [ cb_bgq_geo , () ] ] # Get the version information opt_def = __doc__.replace('__revision__',__revision__) opt_def = opt_def.replace('__version__',__version__) parser = ArgParse(opt_def,callbacks) parser.parse_it() # parse the command line opts = parser.options args = parser.args if parser.no_args(): client_utils.print_usage(parser) sys.exit(1) block_loc = args[0] idle_blocks = client_utils.component_call(SYSMGR, False, 'get_idle_blocks', (block_loc, opts.query_size, opts.geo_list)) client_utils.logger.info("\n".join(idle_blocks))
def validate_args(parser): """ Validate nodeadm arguments. """ spec = {} # map of destination option strings and parsed values opts = {} # old map opt2spec = {} opt_count = client_utils.get_options(spec, opts, opt2spec, parser) if (parser.no_args() and not parser.options.list_nstates) or opt_count == 0: client_utils.print_usage(parser) sys.exit(1) impl = client_utils.component_call(SYSMGR, False, 'get_implementation', ()) # make sure we're on a cluster-system if "cluster_system" != impl: client_utils.logger.error( "nodeadm is only supported on cluster systems. Try partlist instead." ) sys.exit(0) # Check mutually exclusive options mutually_exclusive_option_lists = [['down', 'up', 'list_nstates', 'queue']] if opt_count > 1: client_utils.validate_conflicting_options( parser, mutually_exclusive_option_lists)
def validate_args(parser): """ Validate arguments """ spec = {} opts = {} opt2spec = {} opt_count = client_utils.get_options(spec, opts, opt2spec, parser) if opt_count == 0: client_utils.print_usage(parser) sys.exit(1) opts_wo_args = ['list_blocks', 'xml', 'dump', 'savestate', 'boot_stop', 'boot_start', 'boot_status', 'list_io', 'autoboot_start', 'autoboot_stop', 'autoboot_status'] # Make sure jobid or queue is supplied for the appropriate commands if parser.no_args() and not [opt for opt in spec if opt in opts_wo_args]: client_utils.logger.error("At least one partition must be supplied") sys.exit(1) # Check mutually exclusive options base_list = ['add', 'delete', 'enable', 'disable', 'activate', 'deactivate', 'fail', 'unfail', 'xml', 'savestate', 'list_blocks', 'dump', 'boot_stop', 'boot_start', 'boot_status'] list_1 = base_list + ['queue'] list_2 = base_list + ['rmq','appq'] list_3 = ['pg_list', 'blockinfo','clean_block', 'list_blocks', 'rmq','appq'] list_4 = ['list_io', 'rmq', 'appq'] mux_option_lists = [list_1, list_2, list_3, list_4] if opt_count > 1: client_utils.validate_conflicting_options(parser, mux_option_lists)
def validate_args(parser): """ Validate nodeadm arguments. """ spec = {} # map of destination option strings and parsed values opts = {} # old map opt2spec = {} opt_count = client_utils.get_options(spec,opts,opt2spec,parser) if (parser.no_args() and not parser.options.list_nstates) or opt_count == 0: client_utils.print_usage(parser) sys.exit(1) impl = client_utils.component_call(SYSMGR, False, 'get_implementation', ()) # make sure we're on a cluster-system if impl not in ['cluster_system', 'alps_system']: client_utils.logger.error("nodeadm is only supported on cluster systems. Try partlist instead.") sys.exit(0) # Check mutually exclusive options mutually_exclusive_option_lists = [['down', 'up', 'list_nstates', 'list_details', 'queue']] if opt_count > 1: client_utils.validate_conflicting_options(parser, mutually_exclusive_option_lists)
def validate_args(parser, opt_count): """ Validate qalter arguments """ # Check if any altering options entered if opt_count == 0: client_utils.print_usage(parser, "No required options provided") sys.exit(1) # get jobids from the argument list jobids = client_utils.validate_jobid_args(parser) return jobids
def validate_args(parser,user): """ Validate qmove arguments. """ if len(parser.args) < 2: client_utils.print_usage(parser) sys.exit(1) # get jobids from the argument list jobids = client_utils.get_jobids(parser.args[1:]) jobs = [{'tag':'job', 'user':user, 'jobid':jobid, 'project':'*', 'notify':'*', 'walltime':'*', 'queue':'*', 'procs':'*', 'nodes':'*'} for jobid in jobids] queue = parser.args[0] return queue,jobs
def main(): """ userres main """ # setup logging for client. The clients should call this before doing anything else. client_utils.setup_logging(logging.INFO) # list of callback with its arguments callbacks = [( cb_debug, ())] # Get the version information opt_def = __doc__.replace('__revision__',__revision__) opt_def = opt_def.replace('__version__',__version__) parser = ArgParse(opt_def,callbacks) parser.parse_it() # parse the command line args = parser.args if parser.no_args(): client_utils.print_usage(parser) sys.exit(1) # Check if reservation exists spec = [{'name': rname, 'users':"*", 'start':'*', 'cycle':'*', 'duration':'*'} for rname in args] result = client_utils.component_call(SCHMGR, False, 'get_reservations', (spec,)) if len(result) and len(result) != len(args): client_utils.logger.error("Reservation subset matched") elif not result: client_utils.logger.error("No Reservations matched") sys.exit(1) user_name = client_utils.getuid() for spec in result: if not spec['users'] or user_name not in spec['users'].split(":"): client_utils.logger.error("You are not a user of reservation '%s' and so cannot alter it.", spec['name']) continue if spec['cycle']: updates = update_start_time(spec, user_name) else: client_utils.component_call(SCHMGR, False, 'del_reservations', ([{'name':spec['name']}], user_name)) client_utils.logger.info("Releasing reservation '%s'", spec['name'])
def validate_args(parser, spec, opt_count): """ Validate qalter arguments """ opts_wo_args = ['debug', 'getq', 'savestate', 'setjobid'] # no argument options # handle release or hold options if hasattr(parser.options, 'admin_hold'): opt_count += 1 spec['admin_hold'] = parser.options.admin_hold if hasattr(parser.options, 'user_hold'): opt_count += 1 spec['user_hold'] = parser.options.user_hold # Make sure jobid or queue is supplied for the appropriate commands if parser.no_args() and not [opt for opt in spec if opt in opts_wo_args]: client_utils.print_usage(parser) sys.exit(1) # Check required options if opt_count == 0: client_utils.logger.error("At least one option must be specified") sys.exit(1) check_option_conflicts(opt_count, parser) if parser.options.addq != None or \ parser.options.delq != None or \ parser.options.getq != None or \ parser.options.qdata != None: # set queue options # queue job change request jobs = [{'tag': 'queue', 'name': qname} for qname in parser.args] else: # get jobids from the argument list jobids = client_utils.get_jobids(parser.args) jobs = [{ 'tag': 'job', 'jobid': int(jobid), 'location': '*', 'walltime': '*' } for jobid in jobids] return jobs
def validate_options(parser, opt_count): """ Validate qsub arguments """ # Check if any required option entered if opt_count == 0: client_utils.print_usage(parser, "No required options provided") sys.exit(1) # If no time supplied flag it and exit if parser.options.walltime == None: client_utils.logger.error("'time' not provided") sys.exit(1) # If no nodecount give then flag it an exit if parser.options.nodes == None: client_utils.logger.error("'nodecount' not provided") sys.exit(1)
def validate_args(parser): """ Validate arguments """ spec = {} opts = {} opt2spec = {} opt_count = client_utils.get_options(spec, opts, opt2spec, parser) if opt_count == 0: client_utils.print_usage(parser) sys.exit(1) opts_wo_args = [ 'list_blocks', 'xml', 'dump', 'savestate', 'boot_stop', 'boot_start', 'boot_status', 'list_io', 'autoboot_start', 'autoboot_stop', 'autoboot_status' ] # Make sure jobid or queue is supplied for the appropriate commands if parser.no_args() and not [opt for opt in spec if opt in opts_wo_args]: client_utils.logger.error("At least one partition must be supplied") sys.exit(1) # Check mutually exclusive options base_list = [ 'add', 'delete', 'enable', 'disable', 'activate', 'deactivate', 'fail', 'unfail', 'xml', 'savestate', 'list_blocks', 'dump', 'boot_stop', 'boot_start', 'boot_status' ] list_1 = base_list + ['queue'] list_2 = base_list + ['rmq', 'appq'] list_3 = [ 'pg_list', 'blockinfo', 'clean_block', 'list_blocks', 'rmq', 'appq' ] list_4 = ['list_io', 'rmq', 'appq'] mux_option_lists = [list_1, list_2, list_3, list_4] if opt_count > 1: client_utils.validate_conflicting_options(parser, mux_option_lists)
def validate_args(parser, args): """ Validate arguments """ spec = {} opts = {} opt2spec = {} opt_count = client_utils.get_options(spec, opts, opt2spec, parser) if opt_count == 0: client_utils.print_usage(parser, "No required options provided") sys.exit(1) # Make sure jobid or queue is supplied for the appropriate commands args_opts = [opt for opt in spec if opt in ['adjust', 'dep_frac']] if parser.no_args() and args_opts: client_utils.logger.error("At least one jobid must be supplied") sys.exit(1) elif not parser.no_args(): if not args_opts: client_utils.logger.error("No arguments needed") else: for i in range(len(args)): if args[i] == '*': continue try: args[i] = int(args[i]) except ValueError: client_utils.logger.error( "jobid must be an integer, found '%s'" % args[i]) sys.exit(1) # Check mutually exclusive options mutually_exclusive_option_lists = [[ 'stop', 'start', 'stat', 'reread', 'savestate', 'adjust' ], ['stop', 'start', 'stat', 'reread', 'savestate', 'dep_frac']] if opt_count > 1: client_utils.validate_conflicting_options( parser, mutually_exclusive_option_lists)
def main(): """ releaseres main """ # setup logging for client. The clients should call this before doing anything else. client_utils.setup_logging(logging.INFO) # list of callback with its arguments callbacks = [(cb_debug, ())] # Get the version information opt_def = __doc__.replace('__revision__', __revision__) opt_def = opt_def.replace('__version__', __version__) parser = ArgParse(opt_def, callbacks) parser.parse_it() # parse the command line args = parser.args if parser.no_args(): client_utils.print_usage(parser) sys.exit(1) # Check if reservation exists spec = [{'name': arg, 'partitions': '*'} for arg in args] result = client_utils.component_call(SCHMGR, False, 'get_reservations', (spec, )) if len(result) and len(result) != len(args): client_utils.logger.error("Reservation subset matched") elif not result: client_utils.logger.error("No Reservations matched") sys.exit(1) result = client_utils.component_call(SCHMGR, False, 'release_reservations', (spec, client_utils.getuid())) for resinfo in result: partitions = resinfo['partitions'].split(':') client_utils.logger.info( "Released reservation '%s' for partitions: %s", resinfo['name'], str(partitions))
def validate_args(parser, spec, opt_count): """ Validate qalter arguments """ opts_wo_args = ["debug", "getq", "savestate", "setjobid"] # no argument options # handle release or hold options if hasattr(parser.options, "admin_hold"): opt_count += 1 spec["admin_hold"] = parser.options.admin_hold if hasattr(parser.options, "user_hold"): opt_count += 1 spec["user_hold"] = parser.options.user_hold # Make sure jobid or queue is supplied for the appropriate commands if parser.no_args() and not [opt for opt in spec if opt in opts_wo_args]: client_utils.print_usage(parser) sys.exit(1) # Check required options if opt_count == 0: client_utils.logger.error("At least one option must be specified") sys.exit(1) check_option_conflicts(opt_count, parser) if ( parser.options.addq != None or parser.options.delq != None or parser.options.getq != None or parser.options.qdata != None ): # set queue options # queue job change request jobs = [{"tag": "queue", "name": qname} for qname in parser.args] else: # get jobids from the argument list jobids = client_utils.get_jobids(parser.args) jobs = [{"tag": "job", "jobid": int(jobid), "location": "*", "walltime": "*"} for jobid in jobids] return jobs
def validate_args(parser, args): """ Validate arguments """ spec = {} opts = {} opt2spec = {} opt_count = client_utils.get_options(spec, opts, opt2spec, parser) if opt_count == 0: client_utils.print_usage(parser, "No required options provided") sys.exit(1) # Make sure jobid or queue is supplied for the appropriate commands args_opts = [opt for opt in spec if opt in ['adjust','dep_frac']] if parser.no_args() and args_opts: client_utils.logger.error("At least one jobid must be supplied") sys.exit(1) elif not parser.no_args(): if not args_opts: client_utils.logger.error("No arguments needed") else: for i in range(len(args)): if args[i] == '*': continue try: args[i] = int(args[i]) except ValueError: client_utils.logger.error("jobid must be an integer, found '%s'" % args[i]) sys.exit(1) # Check mutually exclusive options mutually_exclusive_option_lists = [['stop', 'start', 'stat', 'reread', 'savestate', 'adjust'], ['stop', 'start', 'stat', 'reread', 'savestate', 'dep_frac']] if opt_count > 1: client_utils.validate_conflicting_options(parser, mutually_exclusive_option_lists)
def validate_args(parser, spec, opt_count): """ Validate qalter arguments """ opts_wo_args = ['debug', 'getq', 'savestate', 'setjobid'] # no argument options # handle release or hold options if hasattr(parser.options, 'admin_hold'): opt_count += 1 spec['admin_hold'] = parser.options.admin_hold if hasattr(parser.options, 'user_hold'): opt_count += 1 spec['user_hold'] = parser.options.user_hold # Make sure jobid or queue is supplied for the appropriate commands if parser.no_args() and not [opt for opt in spec if opt in opts_wo_args]: client_utils.print_usage(parser) sys.exit(1) # Check required options if opt_count == 0: client_utils.logger.error("At least one option must be specified") sys.exit(1) check_option_conflicts(opt_count, parser) if parser.options.addq != None or \ parser.options.delq != None or \ parser.options.getq != None or \ parser.options.qdata != None: # set queue options # queue job change request jobs = [{'tag':'queue', 'name':qname} for qname in parser.args] else: # get jobids from the argument list jobids = client_utils.get_jobids(parser.args) jobs = [{'tag':'job', 'jobid':int(jobid), 'location':'*', 'walltime':'*'} for jobid in jobids] return jobs
def main(): """ releaseres main """ # setup logging for client. The clients should call this before doing anything else. client_utils.setup_logging(logging.INFO) # list of callback with its arguments callbacks = [(cb_debug, ())] # Get the version information opt_def = __doc__.replace("__revision__", __revision__) opt_def = opt_def.replace("__version__", __version__) parser = ArgParse(opt_def, callbacks) parser.parse_it() # parse the command line args = parser.args if parser.no_args(): client_utils.print_usage(parser) sys.exit(1) # Check if reservation exists spec = [{"name": arg, "partitions": "*"} for arg in args] result = client_utils.component_call(SCHMGR, False, "get_reservations", (spec,)) if len(result) and len(result) != len(args): client_utils.logger.error("Reservation subset matched") elif not result: client_utils.logger.error("No Reservations matched") sys.exit(1) result = client_utils.component_call(SCHMGR, False, "release_reservations", (spec, client_utils.getuid())) for resinfo in result: partitions = resinfo["partitions"].split(":") client_utils.logger.info("Released reservation '%s' for partitions: %s", resinfo["name"], str(partitions))
def validate_args(parser, user): """ Validate qmove arguments. """ if len(parser.args) < 2: client_utils.print_usage(parser) sys.exit(1) # get jobids from the argument list jobids = client_utils.get_jobids(parser.args[1:]) jobs = [{ 'tag': 'job', 'user': user, 'jobid': jobid, 'project': '*', 'notify': '*', 'walltime': '*', 'queue': '*', 'procs': '*', 'nodes': '*' } for jobid in jobids] queue = parser.args[0] return queue, jobs
def validate_args(parser,spec,opt_count): """ Validate setres arguments. Will return true if we want to continue processing options. """ system_type = client_utils.component_call(SYSMGR, False, 'get_implementation', ()) if parser.options.partitions != None: parser.args += [part for part in parser.options.partitions.split(':')] if parser.options.cycle_id != None or parser.options.res_id != None: only_id_change = True if not parser.no_args() or (opt_count != 0): client_utils.logger.error('No partition arguments or other options allowed with id change options') sys.exit(1) else: only_id_change = False if parser.options.force_id and not only_id_change: client_utils.logger.error("--force_id can only be used with --cycle_id and/or --res_id.") sys.exit(1) if only_id_change: # make the ID change and we are done with setres if parser.options.res_id != None: set_res_id(parser) if parser.options.cycle_id != None: set_cycle_id(parser) continue_processing_options = False # quit, setres is done else: if parser.options.name is None: client_utils.print_usage(parser) sys.exit(1) if parser.no_args() and (parser.options.modify_res == None): client_utils.logger.error("Must supply either -p with value or partitions as arguments") sys.exit(1) if parser.options.start == None and parser.options.modify_res == None: client_utils.logger.error("Must supply a start time for the reservation with -s") sys.exit(1) if parser.options.duration == None and parser.options.modify_res == None: client_utils.logger.error("Must supply a duration time for the reservation with -d") sys.exit(1) if parser.options.defer != None and (parser.options.start != None or parser.options.cycle != None): client_utils.logger.error("Cannot use -D while changing start or cycle time") sys.exit(1) # if we have command line arguments put them in spec if system_type in ['alps_system']: if not parser.no_args(): nodes = [] for arg in parser.args: nodes.extend(expand_num_list(arg)) compact_nodes = compact_num_list(nodes) verify_locations([compact_nodes]) spec['partitions'] = compact_nodes else: if not parser.no_args(): verify_locations(parser.args) if not parser.no_args(): spec['partitions'] = ":".join(parser.args) continue_processing_options = True # continue, setres is not done. return continue_processing_options
def validate_args(parser, spec): """ If the argument is a script job it will validate it, and get the Cobalt directives """ #an executable cannot be specified for interactive jobs if parser.options.mode == 'interactive' and (not parser.no_args()): client_utils.logger.error("An executable may not be specified if using the interactive option.") sys.exit(1) elif parser.options.mode == 'interactive': #Bypass the rest of the checks for interactive jobs. return # if no excecutable specified then flag it an exit if parser.no_args(): client_utils.print_usage(parser, "No executable or script specified") sys.exit(1) # Check if it is a valid executable/file cmd = parser.args[0].replace(' ','') if cmd[0] != '/': cmd = spec['cwd'] + '/' + cmd if not os.path.isfile(cmd): client_utils.logger.error("command %s not found, or is not a file" % cmd) sys.exit(1) if not os.access(cmd, os.X_OK | os.R_OK): client_utils.logger.error("command %s is not executable" % cmd) sys.exit(1) # if there are any arguments for the specified command store them in spec spec['command'] = cmd if len(parser.args) > 1: spec['args'] = parser.args[1:] else: spec['args'] = [] tag = '#COBALT ' len_tag = len(tag) fd = open(cmd, 'r') line = fd.readline() reparse = False if line[0:2] == '#!': line = fd.readline() new_argv = [] while len(line) > len_tag: if line[:len_tag] != tag: break if new_argv == []: new_argv = ['--mode','script'] reparse = True new_argv += line[len_tag:].split() line = fd.readline() sys.argv = [sys.argv[0]] + new_argv + sys.argv[1:] fd.close() # check for multiple --env options specified if sys.argv.count('--en') + sys.argv.count('--env') > 1: # consolidate the --env options (this will update sys.argv) env_union() reparse = True return reparse
def validate_args(parser, spec, opt_count): """ Validate setres arguments. Will return true if we want to continue processing options. """ if parser.options.partitions != None: parser.args += [part for part in parser.options.partitions.split(':')] if parser.options.cycle_id != None or parser.options.res_id != None: only_id_change = True if not parser.no_args() or (opt_count != 0): client_utils.logger.error( 'No partition arguments or other options allowed with id change options' ) sys.exit(1) else: only_id_change = False if parser.options.force_id and not only_id_change: client_utils.logger.error( "--force_id can only be used with --cycle_id and/or --res_id.") sys.exit(1) if only_id_change: # make the ID change and we are done with setres if parser.options.res_id != None: set_res_id(parser) if parser.options.cycle_id != None: set_cycle_id(parser) continue_processing_options = False # quit, setres is done else: if parser.options.name is None: client_utils.print_usage(parser) sys.exit(1) if parser.no_args() and (parser.options.modify_res == None): client_utils.logger.error( "Must supply either -p with value or partitions as arguments") sys.exit(1) if parser.options.start == None and parser.options.modify_res == None: client_utils.logger.error( "Must supply a start time for the reservation with -s") sys.exit(1) if parser.options.duration == None and parser.options.modify_res == None: client_utils.logger.error( "Must supply a duration time for the reservation with -d") sys.exit(1) if parser.options.defer != None and (parser.options.start != None or parser.options.cycle != None): client_utils.logger.error( "Cannot use -D while changing start or cycle time") sys.exit(1) # if we have args then verify the args (partitions) if not parser.no_args(): verify_locations(parser.args) # if we have command line arguments put them in spec if not parser.no_args(): spec['partitions'] = ":".join(parser.args) continue_processing_options = True # continue, setres is not done. return continue_processing_options
def validate_args(parser, spec): """ If the argument is a script job it will validate it, and get the Cobalt directives """ #an executable cannot be specified for interactive jobs if parser.options.mode == 'interactive' and (not parser.no_args()): client_utils.logger.error( "An executable may not be specified if using the interactive option." ) sys.exit(1) elif parser.options.mode == 'interactive': #Bypass the rest of the checks for interactive jobs. return # if no excecutable specified then flag it an exit if parser.no_args(): client_utils.print_usage(parser, "No executable or script specified") sys.exit(1) # Check if it is a valid executable/file cmd = parser.args[0].replace(' ', '') if cmd[0] != '/': cmd = spec['cwd'] + '/' + cmd if not os.path.isfile(cmd): client_utils.logger.error("command %s not found, or is not a file" % cmd) sys.exit(1) if not os.access(cmd, os.X_OK | os.R_OK): client_utils.logger.error("command %s is not executable" % cmd) sys.exit(1) # if there are any arguments for the specified command store them in spec spec['command'] = cmd if len(parser.args) > 1: spec['args'] = parser.args[1:] else: spec['args'] = [] tag = '#COBALT ' len_tag = len(tag) fd = open(cmd, 'r') line = fd.readline() reparse = False if line[0:2] == '#!': line = fd.readline() new_argv = [] while len(line) > len_tag: if line[:len_tag] != tag: break if new_argv == []: new_argv = ['--mode', 'script'] reparse = True new_argv += line[len_tag:].split() line = fd.readline() sys.argv = [sys.argv[0]] + new_argv + sys.argv[1:] fd.close() # check for multiple --env options specified if sys.argv.count('--en') + sys.argv.count('--env') > 1: # consolidate the --env options (this will update sys.argv) env_union() reparse = True return reparse