def edit_std_out(config_file, job_id): """ Edit job stdout file. """ config = get_config(config_file) edit_file(config, 'out', job_id)
def edit_std_err(config_file, job_id): """ Edit job stdout file. """ config = get_config(config_file) edit_file(config, 'err', job_id)
def edit_job(config_file, file_type, job_id): """ Edit job command script. """ config = get_config(config_file) edit_file(config, file_type, job_id)
def slqu(config_file, user_name, long, sort_keys): """ Query some user's jobs in LoadLeveler. """ config = get_config(config_file) if sort_keys: sort_keys = tuple(sort_keys.split(":")) query_user_slq(config, user_name, sort_keys, long)
def all_filters(config_file): config = get_config(config_file) model_dict = get_query_response(config) filters_path = Path(Path(__file__).parent.parent, "filters") filters = load_filters([filters_path]) for filter_name in filters: filter_class = filters[filter_name] if not filter_class.USE_IN_DEFAULT: continue filter_object = filter_class() filter_items = filter_object.apply(model_dict['items']) click.echo('{filter_name}:'.format( filter_name=click.style(filter_object.name, bold=True))) max_class_length = 0 max_owner_length = 0 for an_item in filter_items: job_partition = get_property_data(an_item, "squeue.partition") if len(job_partition) > max_class_length: max_class_length = len(job_partition) job_account = get_property_data(an_item, "squeue.account") if len(job_account) > max_owner_length: max_owner_length = len(job_account) sort_query_items(filter_items) for an_item in filter_items: job_id = get_property_data(an_item, "squeue.job_id") job_partition = get_property_data(an_item, "squeue.partition") job_account = get_property_data(an_item, "squeue.account") job_command = get_property_data(an_item, "squeue.command") job_state = get_property_data(an_item, "squeue.state") job_submit_time = get_property_data(an_item, "squeue.submit_time") click.echo( "{job_id} {job_state} {job_partition} {job_account} {job_submit_time} {job_command}" .format( job_id=click.style(job_id, bold=True), job_partition=click.style( ("{job_partition: <" + str(max_class_length) + "}").format(job_partition=job_partition), fg='blue'), job_account=click.style( ("{job_account: <" + str(max_owner_length) + "}").format(job_account=job_account), fg='cyan'), job_submit_time=click.style( job_submit_time.strftime("%m/%d %H:%M"), fg='blue'), job_command=job_command, job_state=click.style( "{job_state: <2}".format(job_state=job_state), fg='yellow'), )) click.echo()
def command(config_file, user_list, partition_list, sort_keys, params): """ Query jobs in Slurm and show in a detailed format. """ config = get_config(config_file) if params is None: params = '' if user_list: params += ' -u {user_list}'.format(user_list=" ".join(user_list)) if partition_list: params += ' -p {partition_list}'.format( partition_list=" ".join(partition_list)) if sort_keys: sort_keys = tuple(sort_keys.split(":")) from slurm_client import HAS_PYSLURM if not HAS_PYSLURM: from slurm_client.common.cli.squeue import get_query_response model_dict = get_query_response(config, params) else: from slurm_client.common.api.job import get_query_response model_dict = get_query_response(config) items = model_dict['items'] sort_query_items(items, sort_keys) for an_item in items: job_id = get_property_data(an_item, "squeue.job_id") job_partition = get_property_data(an_item, "squeue.partition") job_account = get_property_data(an_item, "squeue.account") job_command = get_property_data(an_item, "squeue.command") job_state = get_property_data(an_item, "squeue.state") job_submit_time = get_property_data(an_item, "squeue.submit_time") click.echo( """{job_id} {job_state} {job_partition} {job_account} {job_submit_time} Command: {job_command}""".format(job_id=click.style(str(job_id), bold=True), job_partition=click.style(job_partition, fg='blue'), job_account=click.style(job_account, fg='cyan'), job_submit_time=click.style( job_submit_time.strftime("%m/%d %H:%M"), fg='blue'), job_command=job_command, job_state=click.style(job_state, fg='yellow'))) if HAS_PYSLURM: std_out = get_property_data(an_item, "squeue.std_out") std_err = get_property_data(an_item, "squeue.std_err") click.echo(""" Out: {std_out} Err: {std_err}""".format(std_out=std_out, std_err=std_err)) click.echo("")
def command(config_file, user_list, partition_list, sort_keys, params, command_pattern): """ Query jobs in Slurm and show in a simple format. """ config = get_config(config_file) if params is None: params = '' if user_list: params += ' -u {user_list}'.format(user_list=" ".join(user_list)) if partition_list: params += ' -p {partition_list}'.format( partition_list=" ".join(partition_list)) if sort_keys: sort_keys = tuple(sort_keys.split(":")) model_dict = get_query_response(config, params) max_class_length = 0 max_owner_length = 0 for an_item in model_dict['items']: job_partition = get_property_data(an_item, "squeue.partition") if len(job_partition) > max_class_length: max_class_length = len(job_partition) job_account = get_property_data(an_item, "squeue.account") if len(job_account) > max_owner_length: max_owner_length = len(job_account) items = model_dict['items'] if command_pattern: from slurm_client.filters.command import command_filter filter_object = command_filter.CommandFilter(command_pattern) items = filter_object.apply(items) sort_query_items(items, sort_keys) for an_item in items: job_id = get_property_data(an_item, "squeue.job_id") job_partition = get_property_data(an_item, "squeue.partition") job_account = get_property_data(an_item, "squeue.account") job_command = get_property_data(an_item, "squeue.command") job_state = get_property_data(an_item, "squeue.state") job_submit_time = get_property_data(an_item, "squeue.submit_time") click.echo( "{job_id} {job_state} {job_partition} {job_account} {job_submit_time} {job_command}" .format( job_id=click.style(job_id, bold=True), job_partition=click.style( ("{job_partition: <" + str(max_class_length) + "}").format(job_partition=job_partition), fg='blue'), job_account=click.style( ("{job_account: <" + str(max_owner_length) + "}").format(job_account=job_account), fg='cyan'), job_submit_time=click.style( job_submit_time.strftime("%m/%d %H:%M"), fg='blue'), job_command=job_command, job_state=click.style( "{job_state: <2}".format(job_state=job_state), fg='yellow'), ))
def command(config_file, sort_keys, params): """ Show partition info. """ config = get_config(config_file) if params is None: params = '' if sort_keys: sort_keys = tuple(sort_keys.split(":")) print_header = True model_dict = get_query_response(config, params) items = model_dict['items'] sort_query_response_items(items, sort_keys) max_partition_length = 10 max_nodes_status_length = 20 max_cpus_status_length = 30 for an_item in items: partition_name = get_property_data(an_item, "sinfo.partition") if len(partition_name) > max_partition_length: max_partition_length = len(partition_name) nodes_status = get_property_data(an_item, "sinfo.nodes") if len(nodes_status) > max_nodes_status_length: max_nodes_status_length = len(nodes_status) cpus_status = get_property_data(an_item, "sinfo.cpus") if len(cpus_status) > max_cpus_status_length: max_cpus_status_length = len(cpus_status) if print_header: click.echo( "{partition_name} {avail_status} {nodes_status} {cpus_status}". format(partition_name=click.style( ("{partition_name: <" + str(max_partition_length) + "}").format(partition_name='Partition'), bold=True), avail_status=click.style( "{avail_status: <5}".format(avail_status='Avail'), bold=True), nodes_status=click.style( ("{nodes_status: >" + str(max_nodes_status_length) + "}").format(nodes_status='Nodes(A/I/O/T)'), bold=True), cpus_status=click.style( ("{cpus_status: >" + str(max_cpus_status_length) + "}").format(cpus_status='CPUs(A/I/O/T)'), bold=True))) for an_item in items: partition_name = get_property_data(an_item, "sinfo.partition") avail_status = get_property_data(an_item, "sinfo.avail") nodes_status = get_property_data(an_item, "sinfo.nodes") cpus_status = get_property_data(an_item, "sinfo.cpus") click.echo( "{partition_name} {avail_status} {nodes_status} {cpus_status}". format(partition_name=click.style( ("{partition_name: <" + str(max_partition_length) + "}").format(partition_name=partition_name), bold=True), avail_status=click.style( "{avail_status: <5}".format(avail_status=avail_status), fg='blue'), nodes_status=click.style( ("{nodes_status: >" + str(max_nodes_status_length) + "}").format(nodes_status=nodes_status), fg='cyan'), cpus_status=click.style( ("{cpus_status: >" + str(max_cpus_status_length) + "}").format(cpus_status=cpus_status), fg='magenta')))
def command(config_file, sort_keys, params): """ Show accounting data for all jobs. """ config = get_config(config_file) if params is None: params = '' if sort_keys: sort_keys = tuple(sort_keys.split(":")) print_header = True model_dict = get_query_response(config, params) items = model_dict['items'] sort_query_response_items(items, sort_keys) column_config = [ { 'title': 'Job ID', 'id': 'sacct.job_id', 'col_length': 10, 'style': { 'title': { 'align': '>', 'echo_param': { 'bold': True } }, 'value': { 'align': '>', 'echo_param': { 'bold': True } } } }, { 'title': 'Partition', 'id': 'sacct.partition', 'col_length': 10, 'style': { 'title': { 'align': '>', 'echo_param': { } }, 'value': { 'align': '>', 'echo_param': { } } } }, { 'title': 'Account', 'id': 'sacct.account', 'col_length': 7, 'style': { 'title': { 'align': '>', 'echo_param': { } }, 'value': { 'align': '>', 'echo_param': { } } } }, { 'title': 'Nodes', 'id': 'sacct.alloc_nodes', 'col_length': 8, 'style': { 'title': { 'align': '>', 'echo_param': { } }, 'value': { 'align': '>', 'echo_param': { } } } }, { 'title': 'CPUs', 'id': 'sacct.alloc_cpus', 'col_length': 8, 'style': { 'title': { 'align': '>', 'echo_param': { } }, 'value': { 'align': '>', 'echo_param': { } } } }, { 'title': 'State', 'id': 'sacct.state', 'col_length': 8, 'style': { 'title': { 'align': '>', 'echo_param': { 'fg': 'yellow' } }, 'value': { 'align': '>', 'echo_param': { 'fg': 'yellow' } } } }, { 'title': 'Exit Code', 'id': 'sacct.exit_code', 'col_length': 12, 'style': { 'title': { 'align': '>', 'echo_param': { } }, 'value': { 'align': '>', 'echo_param': { } } } }, { 'title': 'Eligible', 'id': 'sacct.eligible', 'col_length': 12, 'style': { 'title': { 'align': '>', 'echo_param': { 'fg': 'cyan' } }, 'value': { 'align': '>', 'echo_param': { 'fg': 'cyan' } } } }, { 'title': 'End', 'id': 'sacct.end', 'col_length': 12, 'style': { 'title': { 'align': '>', 'echo_param': { 'fg': 'magenta' } }, 'value': { 'align': '>', 'echo_param': { 'fg': 'magenta' } } } }, ] table_data = [] for an_item in items: row_data = [] for a_column in column_config: value = get_property_data(an_item, a_column['id']) col_length = a_column['col_length'] if len(str(value)) > col_length: a_column['col_length'] = len(str(value)) row_data.append(value) table_data.append(row_data) title_token = [] if print_header: for a_column in column_config: col_title = ("{title: " + a_column['style']['title']['align'] + str(a_column['col_length']) + "}").format( title=a_column['title'] ) token_string = click.style(col_title, **a_column['style']['title']['echo_param']) title_token.append(token_string) click.echo(' '.join(title_token)) for a_row in table_data: row_token = [] index = 0 for a_column in column_config: col_title = ("{value: " + a_column['style']['value']['align'] + str(a_column['col_length']) + "}").format( value=a_row[index] ) token_string = click.style(col_title, **a_column['style']['value']['echo_param']) row_token.append(token_string) index += 1 click.echo(' '.join(row_token))