def main(): """ qdel 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 , () ] ] # Get the version information opt_def = __doc__.replace('__revision__',__revision__) opt_def = opt_def.replace('__version__',__version__) parser = ArgParse(opt_def,callbacks) user = client_utils.getuid() # Set required default values: None parser.parse_it() # parse the command line jobids = client_utils.validate_jobid_args(parser) jobs = [{'tag':'job', 'user':user, 'jobid':jobid} for jobid in jobids] deleted_jobs = client_utils.component_call(QUEMGR, True, 'del_jobs', (jobs, False, user)) time.sleep(1) if deleted_jobs: data = [('JobID','User')] + [(job.get('jobid'), job.get('user')) for job in deleted_jobs] client_utils.logger.info(" Deleted Jobs") client_utils.print_tabular(data)
def getq(info): """ get queue """ response = client_utils.component_call(QUEMGR, True, 'get_queues', (info, )) for que in response: if que['maxtime'] is not None: que['maxtime'] = "%02d:%02d:00" % (divmod(int(que.get('maxtime')), 60)) if que['mintime'] is not None: que['mintime'] = "%02d:%02d:00" % (divmod(int(que.get('mintime')), 60)) header = [('Queue', 'Users', 'Groups', 'MinTime', 'MaxTime', 'MaxRunning', 'MaxQueued', 'MaxUserNodes', 'MaxNodeHours', 'TotalNodes', 'AdminEmail', 'State', 'Cron', 'Policy', 'Priority')] datatoprint = [(que['name'], que['users'], que['groups'], que['mintime'], que['maxtime'], que['maxrunning'], que['maxqueued'], que['maxusernodes'], que['maxnodehours'], que['totalnodes'], que['adminemail'], que['state'], que['cron'], que['policy'], que['priority']) for que in response] datatoprint.sort() client_utils.print_tabular(header + datatoprint) return response
def getq(info): """ get queue """ response = client_utils.component_call(QUEMGR, True, "get_queues", (info,)) for que in response: if que["maxtime"] is not None: que["maxtime"] = "%02d:%02d:00" % (divmod(int(que.get("maxtime")), 60)) if que["mintime"] is not None: que["mintime"] = "%02d:%02d:00" % (divmod(int(que.get("mintime")), 60)) header = [ ( "Queue", "Users", "Groups", "MinTime", "MaxTime", "MaxRunning", "MaxQueued", "MaxUserNodes", "MaxNodeHours", "TotalNodes", "AdminEmail", "State", "Cron", "Policy", "Priority", ) ] datatoprint = [ ( que["name"], que["users"], que["groups"], que["mintime"], que["maxtime"], que["maxrunning"], que["maxqueued"], que["maxusernodes"], que["maxnodehours"], que["totalnodes"], que["adminemail"], que["state"], que["cron"], que["policy"], que["priority"], ) for que in response ] datatoprint.sort() client_utils.print_tabular(header + datatoprint) return response
def process_the_output(output, parser, hinfo): """ process the qstat output """ fields = ['score'] if parser.options.sort == None else [ f.lower() for f in parser.options.sort ] lower_case_header = [str(h).lower() for h in hinfo.header] idxes = [] for f in fields: try: idx = lower_case_header.index(f) idxes.append(idx) except: pass if not idxes: idxes.append(0) def _my_cmp(left, right): for idx in idxes: try: val = cmp(float(left[idx]), float(right[idx])) except: val = cmp(left[idx], right[idx]) if val == 0: continue else: return val return 0 output.sort(_my_cmp) if parser.options.reverse != None: output.reverse() if "short_state" in lower_case_header: idx = lower_case_header.index("short_state") hinfo.header[idx] = "S" if "score" in lower_case_header: idx = lower_case_header.index("score") for line in output: line[idx] = human_format(float(line[idx])) if parser.options.long != None: client_utils.print_vertical( [tuple(x) for x in [hinfo.header] + output]) else: client_utils.print_tabular([tuple(x) for x in [hinfo.header] + output])
def process_the_output(output,parser,hinfo): """ process the qstat output """ fields = ['score'] if parser.options.sort == None else [f.lower() for f in parser.options.sort] lower_case_header = [str(h).lower() for h in hinfo.header] idxes = [] for f in fields: try: idx = lower_case_header.index(f) idxes.append(idx) except: pass if not idxes: idxes.append(0) def _my_cmp(left, right): for idx in idxes: try: val = cmp(float(left[idx]), float(right[idx])) except: val = cmp(left[idx], right[idx]) if val == 0: continue else: return val return 0 output.sort(_my_cmp) if parser.options.reverse != None: output.reverse() if "short_state" in lower_case_header: idx = lower_case_header.index("short_state") hinfo.header[idx] = "S" if "score" in lower_case_header: idx = lower_case_header.index("score") for line in output: line[idx] = human_format(float(line[idx])) if parser.options.long != None: client_utils.print_vertical([tuple(x) for x in [hinfo.header] + output]) else: client_utils.print_tabular([tuple(x) for x in [hinfo.header] + output])
def main(): """ slpstat 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, ()] ] # Get the version information opt_def = __doc__.replace('__revision__', __revision__) opt_def = opt_def.replace('__version__', __version__) parser = ArgParse(opt_def, callbacks) # Set required default values: None parser.parse_it() # parse the command line if not parser.no_args(): client_utils.logger.error('No arguments needed') services = client_utils.component_call(SLPMGR, False, 'get_services', ([{ 'tag': 'service', 'name': '*', 'stamp': '*', 'location': '*' }], )) if services: header = [('Name', 'Location', 'Update Time')] output = [(service['name'], service['location'], time.strftime("%c", time.localtime(service['stamp']))) for service in services] client_utils.print_tabular(header + [tuple(item) for item in output]) else: client_utils.logger.info("no services registered")
def main(): """ slpstat 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 , () ] ] # Get the version information opt_def = __doc__.replace('__revision__',__revision__) opt_def = opt_def.replace('__version__',__version__) parser = ArgParse(opt_def,callbacks) # Set required default values: None parser.parse_it() # parse the command line if not parser.no_args(): client_utils.logger.error('No arguments needed') services = client_utils.component_call(SLPMGR, False, 'get_services', ([{'tag':'service', 'name':'*', 'stamp':'*', 'location':'*'}],)) if services: header = [('Name', 'Location', 'Update Time')] output = [ (service['name'], service['location'], time.strftime("%c", time.localtime(service['stamp']))) for service in services ] client_utils.print_tabular(header + [tuple(item) for item in output]) else: client_utils.logger.info("no services registered")
def main(): """ qdel 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, ()] ] # Get the version information opt_def = __doc__.replace('__revision__', __revision__) opt_def = opt_def.replace('__version__', __version__) parser = ArgParse(opt_def, callbacks) user = client_utils.getuid() # Set required default values: None parser.parse_it() # parse the command line jobids = client_utils.validate_jobid_args(parser) jobs = [{'tag': 'job', 'user': user, 'jobid': jobid} for jobid in jobids] deleted_jobs = client_utils.component_call(QUEMGR, True, 'del_jobs', (jobs, False, user)) time.sleep(1) if deleted_jobs: data = [('JobID', 'User')] + [(job.get('jobid'), job.get('user')) for job in deleted_jobs] client_utils.logger.info(" Deleted Jobs") client_utils.print_tabular(data)
def getq(info): """ get queue """ response = client_utils.component_call(QUEMGR, True, 'get_queues', (info,)) for que in response: if que['maxtime'] is not None: que['maxtime'] = "%02d:%02d:00" % (divmod(int(que.get('maxtime')), 60)) if que['mintime'] is not None: que['mintime'] = "%02d:%02d:00" % (divmod(int(que.get('mintime')), 60)) header = [('Queue', 'Users', 'Groups', 'MinTime', 'MaxTime', 'MaxRunning', 'MaxTotalJobs', 'MaxQueued', 'MaxUserNodes', 'MaxNodeHours', 'TotalNodes', 'AdminEmail', 'State', 'Cron', 'Policy', 'Priority')] datatoprint = [(que['name'], que['users'], que['groups'], que['mintime'], que['maxtime'], que['maxrunning'], que['maxtotaljobs'], que['maxqueued'], que['maxusernodes'], que['maxnodehours'], que['totalnodes'], que['adminemail'], que['state'], que['cron'], que['policy'], que['priority']) for que in response] datatoprint.sort() client_utils.print_tabular(header + datatoprint) return response
def main(): """ showres 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 , () ] ] # 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 if not parser.no_args(): client_utils.logger.error("No arguments needed") if parser.options.verbose != None and parser.options.really_verbose != None: client_utils.logger.error('Only use -l or -x not both') sys.exit(1) cluster = False if 'cluster' in client_utils.component_call(SYSMGR, False, 'get_implementation', ()): cluster = True reservations = client_utils.component_call(SCHMGR, False, 'get_reservations', ([{'name':'*', 'users':'*','start':'*', 'duration':'*', 'partitions':'*', 'cycle': '*', 'queue': '*', 'res_id': '*', 'cycle_id': '*','project':'*', 'block_passthrough':'*'}], )) output = [] verbose = False really_verbose = False header = [('Reservation', 'Queue', 'User', 'Start', 'Duration','Passthrough', 'Partitions', 'Remaining','T-Minus')] if parser.options.verbose: verbose = True header = [('Reservation', 'Queue', 'User', 'Start', 'Duration', 'End Time', 'Cycle Time', 'Passthrough', 'Partitions', 'Remaining', 'T-Minus')] elif parser.options.really_verbose: really_verbose = True header = [('Reservation', 'Queue', 'User', 'Start', 'Duration','End Time', 'Cycle Time','Passthrough','Partitions', 'Project', 'ResID', 'CycleID', 'Remaining', 'T-Minus' )] for res in reservations: passthrough = "Allowed" if res['block_passthrough']: passthrough = "Blocked" start = float(res['start']) duration = float(res['duration']) now = time.time() deltatime = now - start remaining = "inactive" if deltatime < 0.0 else client_utils.get_elapsed_time(deltatime, duration, True) remaining = "00:00:00" if '-' in remaining else remaining tminus = "active" if deltatime >= 0.0 else client_utils.get_elapsed_time(deltatime, duration, True) # do some crazy stuff to make reservations which cycle display the # "next" start time if res['cycle']: cycle = float(res['cycle']) periods = math.floor((now - start)/cycle) # reservations can't become active until they pass the start time # -- so negative periods aren't allowed if periods < 0: pass # if we are still inside the reservation, show when it started elif (now - start) % cycle < duration: start += periods * cycle # if we are in the dead time after the reservation ended, show # when the next one starts else: start += (periods+1) * cycle if res['cycle_id'] == None: res['cycle_id'] = '-' if res['cycle']: cycle = float(res['cycle']) if cycle < (60 * 60 * 24): cycle = "%02d:%02d" % (cycle/3600, (cycle/60)%60) else: cycle = "%0.1f days" % (cycle / (60 * 60 * 24)) else: cycle = None dmin = (duration/60)%60 dhour = duration/3600 time_fmt = "%c" starttime = time.strftime(time_fmt, time.localtime(start)) endtime = time.strftime(time_fmt, time.localtime(start + duration)) if parser.options.oldts == None: #time_fmt += " %z (%Z)" starttime = client_utils.sec_to_str(start) endtime = client_utils.sec_to_str(start + duration) if really_verbose: output.append((res['name'], res['queue'], res['users'], starttime,"%02d:%02d" % (dhour, dmin), endtime, cycle, passthrough, mergelist(res['partitions'], cluster), res['project'], res['res_id'], res['cycle_id'], remaining, tminus)) elif verbose: output.append((res['name'], res['queue'], res['users'], starttime,"%02d:%02d" % (dhour, dmin), endtime, cycle, passthrough, mergelist(res['partitions'], cluster), remaining, tminus)) else: output.append((res['name'], res['queue'], res['users'], starttime,"%02d:%02d" % (dhour, dmin), passthrough, mergelist(res['partitions'], cluster), remaining, tminus)) output.sort( (lambda x,y: cmp( time.mktime(time.strptime(x[3].split('+')[0].split('-')[0].strip(), time_fmt)), time.mktime(time.strptime(y[3].split('+')[0].split('-')[0].strip(), time_fmt))) ) ) client_utils.print_tabular(header + output)
def main(): """ showres 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, ()] ] # 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 if not parser.no_args(): client_utils.logger.error("No arguments needed") if parser.options.verbose != None and parser.options.really_verbose != None: client_utils.logger.error('Only use -l or -x not both') sys.exit(1) cluster = False if 'cluster' in client_utils.component_call(SYSMGR, False, 'get_implementation', ()): cluster = True reservations = client_utils.component_call(SCHMGR, False, 'get_reservations', ([{ 'name': '*', 'users': '*', 'start': '*', 'duration': '*', 'partitions': '*', 'cycle': '*', 'queue': '*', 'res_id': '*', 'cycle_id': '*', 'project': '*', 'block_passthrough': '*' }], )) output = [] verbose = False really_verbose = False header = [('Reservation', 'Queue', 'User', 'Start', 'Duration', 'Passthrough', 'Partitions', 'Remaining', 'T-Minus')] if parser.options.verbose: verbose = True header = [ ('Reservation', 'Queue', 'User', 'Start', 'Duration', 'End Time', 'Cycle Time', 'Passthrough', 'Partitions', 'Remaining', 'T-Minus') ] elif parser.options.really_verbose: really_verbose = True header = [('Reservation', 'Queue', 'User', 'Start', 'Duration', 'End Time', 'Cycle Time', 'Passthrough', 'Partitions', 'Project', 'ResID', 'CycleID', 'Remaining', 'T-Minus')] for res in reservations: passthrough = "Allowed" if res['block_passthrough']: passthrough = "Blocked" start = float(res['start']) duration = float(res['duration']) now = time.time() deltatime = now - start remaining = "inactive" if deltatime < 0.0 else client_utils.get_elapsed_time( deltatime, duration, True) remaining = "00:00:00" if '-' in remaining else remaining tminus = "active" if deltatime >= 0.0 else client_utils.get_elapsed_time( deltatime, duration, True) # do some crazy stuff to make reservations which cycle display the # "next" start time if res['cycle']: cycle = float(res['cycle']) periods = math.floor((now - start) / cycle) # reservations can't become active until they pass the start time # -- so negative periods aren't allowed if periods < 0: pass # if we are still inside the reservation, show when it started elif (now - start) % cycle < duration: start += periods * cycle # if we are in the dead time after the reservation ended, show # when the next one starts else: start += (periods + 1) * cycle if res['cycle_id'] == None: res['cycle_id'] = '-' if res['cycle']: cycle = float(res['cycle']) if cycle < (60 * 60 * 24): cycle = "%02d:%02d" % (cycle / 3600, (cycle / 60) % 60) else: cycle = "%0.1f days" % (cycle / (60 * 60 * 24)) else: cycle = None dmin = (duration / 60) % 60 dhour = duration / 3600 time_fmt = "%c" starttime = time.strftime(time_fmt, time.localtime(start)) endtime = time.strftime(time_fmt, time.localtime(start + duration)) if parser.options.oldts == None: #time_fmt += " %z (%Z)" starttime = client_utils.sec_to_str(start) endtime = client_utils.sec_to_str(start + duration) if really_verbose: output.append( (res['name'], res['queue'], res['users'], starttime, "%02d:%02d" % (dhour, dmin), endtime, cycle, passthrough, mergelist(res['partitions'], cluster), res['project'], res['res_id'], res['cycle_id'], remaining, tminus)) elif verbose: output.append( (res['name'], res['queue'], res['users'], starttime, "%02d:%02d" % (dhour, dmin), endtime, cycle, passthrough, mergelist(res['partitions'], cluster), remaining, tminus)) else: output.append((res['name'], res['queue'], res['users'], starttime, "%02d:%02d" % (dhour, dmin), passthrough, mergelist(res['partitions'], cluster), remaining, tminus)) output.sort((lambda x, y: cmp( time.mktime( time.strptime(x[3].split('+')[0].split('-')[0].strip(), time_fmt)), time.mktime( time.strptime(y[3].split('+')[0].split('-')[0].strip(), time_fmt))) )) client_utils.print_tabular(header + output)