コード例 #1
0
ファイル: opt.c プロジェクト: mattkappel/slurm
/*
 * opt_env(): used by initialize_and_process_args to set options via
 *            environment variables. See comments above for how to
 *            extend srun to process different vars
 */
static void _opt_env(void)
{
	char *val;

	if ( (val=getenv("SCANCEL_ACCOUNT")) ) {
		opt.account = xstrtolower(xstrdup(val));
	}

	if ( (val=getenv("SCANCEL_BATCH")) ) {
		if (strcasecmp(val, "true") == 0)
			opt.batch       = true;
		else if (strcasecmp(val, "T") == 0)
			opt.batch       = true;
		else if (strcasecmp(val, "false") == 0)
			opt.batch       = false;
		else if (strcasecmp(val, "F") == 0)
			opt.batch       = false;
		else
			error ("Unrecognized SCANCEL_BATCH value: %s",
				val);
	}

	if (getenv("SCANCEL_CTLD"))
		opt.ctld = true;

	if ( (val=getenv("SCANCEL_INTERACTIVE")) ) {
		if (strcasecmp(val, "true") == 0)
			opt.interactive = true;
		else if (strcasecmp(val, "T") == 0)
			opt.interactive = true;
		else if (strcasecmp(val, "false") == 0)
			opt.interactive = false;
		else if (strcasecmp(val, "F") == 0)
			opt.interactive = false;
		else
			error ("Unrecognized SCANCEL_INTERACTIVE value: %s",
				val);
	}

	if ( (val=getenv("SCANCEL_NAME")) ) {
		opt.job_name = xstrdup(val);
	}

	if ( (val=getenv("SCANCEL_PARTITION")) ) {
		opt.partition = xstrdup(val);
	}

	if ( (val=getenv("SCANCEL_QOS")) ) {
		opt.qos = xstrtolower(xstrdup(val));
	}

	if ( (val=getenv("SCANCEL_STATE")) ) {
		opt.state = _xlate_state_name(val, true);
	}

	if ( (val=getenv("SCANCEL_USER")) ) {
		opt.user_name = xstrdup(val);
	}

	if ( (val=getenv("SCANCEL_VERBOSE")) ) {
		if (strcasecmp(val, "true") == 0)
			opt.verbose = 1;
		else if (strcasecmp(val, "T") == 0)
			opt.verbose = 1;
		else if (strcasecmp(val, "false") == 0)
			opt.verbose = 0;
		else if (strcasecmp(val, "F") == 0)
			opt.verbose = 0;
		else
			error ("Unrecognized SCANCEL_VERBOSE value: %s",
				val);
	}

	if ( (val=getenv("SCANCEL_WCKEY")) ) {
		opt.wckey = xstrdup(val);
	}
}
コード例 #2
0
ファイル: opt.c プロジェクト: mattkappel/slurm
/*
 * opt_args() : set options via commandline args and getopt_long
 */
static void _opt_args(int argc, char **argv)
{
	int opt_char;
	int option_index;
	static struct option long_options[] = {
		{"account",	required_argument, 0, 'A'},
		{"batch",	no_argument,       0, 'b'},
		{"ctld",	no_argument,	   0, OPT_LONG_CTLD},
		{"help",        no_argument,       0, OPT_LONG_HELP},
		{"interactive", no_argument,       0, 'i'},
		{"cluster",     required_argument, 0, 'M'},
		{"clusters",    required_argument, 0, 'M'},
		{"name",        required_argument, 0, 'n'},
		{"nodelist",    required_argument, 0, 'w'},
		{"partition",   required_argument, 0, 'p'},
		{"qos",         required_argument, 0, 'q'},
		{"quiet",       no_argument,       0, 'Q'},
		{"reservation", required_argument, 0, 'R'},
		{"signal",      required_argument, 0, 's'},
		{"state",       required_argument, 0, 't'},
		{"usage",       no_argument,       0, OPT_LONG_USAGE},
		{"user",        required_argument, 0, 'u'},
		{"verbose",     no_argument,       0, 'v'},
		{"version",     no_argument,       0, 'V'},
		{"wckey",       required_argument, 0, OPT_LONG_WCKEY},
		{NULL,          0,                 0, 0}
	};

	while ((opt_char = getopt_long(argc, argv, "A:biM:n:p:Qq:R:s:t:u:vVw:",
				       long_options, &option_index)) != -1) {
		switch (opt_char) {
		case (int)'?':
			fprintf(stderr,
				"Try \"scancel --help\" for more "
				"information\n");
			exit(1);
			break;
		case (int)'A':
			opt.account = xstrtolower(xstrdup(optarg));
			break;
		case (int)'b':
			opt.batch = true;
			break;
		case OPT_LONG_CTLD:
			opt.ctld = true;
			break;
		case (int)'i':
			opt.interactive = true;
			break;
		case (int)'M':
			opt.ctld = true;
			FREE_NULL_LIST(opt.clusters);
			opt.clusters = slurmdb_get_info_cluster(optarg);
			if (!opt.clusters) {
				print_db_notok(optarg, 0);
				exit(1);
			}
			working_cluster_rec = list_peek(opt.clusters);
			break;
		case (int)'n':
			opt.job_name = xstrdup(optarg);
			break;
		case (int)'p':
			opt.partition = xstrdup(optarg);
			break;
		case (int)'Q':
			opt.verbose = -1;
			break;
		case (int)'q':
			opt.qos = xstrtolower(xstrdup(optarg));
			break;
		case (int)'R':
			opt.reservation = xstrdup(optarg);
			break;
		case (int)'s':
			opt.signal = _xlate_signal_name(optarg);
			break;
		case (int)'t':
			opt.state = _xlate_state_name(optarg, false);
			break;
		case (int)'u':
			opt.user_name = xstrdup(optarg);
			break;
		case (int)'v':
			opt.verbose++;
			break;
		case (int)'V':
			print_slurm_version ();
			exit(0);
		case (int)'w':
			opt.nodelist = xstrdup(optarg);
			break;
		case OPT_LONG_WCKEY:
			opt.wckey = xstrdup(optarg);
			break;
		case OPT_LONG_HELP:
			_help();
			exit(0);
		case OPT_LONG_USAGE:
			_usage();
			exit(0);
		}
	}

	if (optind < argc) {
		char **rest = argv + optind;
		opt.job_list = rest;
		_xlate_job_step_ids(rest);
	}

	if (!_opt_verify())
		exit(1);
}
コード例 #3
0
extern int sacctmgr_list_qos(int argc, char *argv[])
{
    int rc = SLURM_SUCCESS;
    slurmdb_qos_cond_t *qos_cond = xmalloc(sizeof(slurmdb_qos_cond_t));
    int i=0;
    ListIterator itr = NULL;
    ListIterator itr2 = NULL;
    slurmdb_qos_rec_t *qos = NULL;
    List qos_list = NULL;
    int field_count = 0;

    print_field_t *field = NULL;

    List format_list = list_create(slurm_destroy_char);
    List print_fields_list; /* types are of print_field_t */

    for (i=0; i<argc; i++) {
        int command_len = strlen(argv[i]);
        if (!strncasecmp (argv[i], "Where", MAX(command_len, 5))
                || !strncasecmp (argv[i], "Set", MAX(command_len, 3)))
            i++;
        _set_cond(&i, argc, argv, qos_cond, format_list);
    }

    if(exit_code) {
        slurmdb_destroy_qos_cond(qos_cond);
        list_destroy(format_list);
        return SLURM_ERROR;
    } else if(!list_count(format_list)) {
        slurm_addto_char_list(format_list,
                              "Name,Prio,GraceT,Preempt,PreemptM,"
                              "Flags%40,UsageThres,UsageFactor,"
                              "GrpCPUs,GrpCPUMins,GrpCPURunMins,"
                              "GrpJ,GrpMEM,GrpN,GrpS,GrpW,"
                              "MaxCPUs,MaxCPUMins,MaxN,MaxW,"
                              "MaxCPUsPerUser,"
                              "MaxJobsPerUser,MaxNodesPerUser,"
                              "MaxSubmitJobsPerUser");
    }

    print_fields_list = sacctmgr_process_format_list(format_list);
    list_destroy(format_list);

    if(exit_code) {
        list_destroy(print_fields_list);
        return SLURM_ERROR;
    }
    qos_list = acct_storage_g_get_qos(db_conn, my_uid, qos_cond);
    slurmdb_destroy_qos_cond(qos_cond);

    if(!qos_list) {
        exit_code=1;
        fprintf(stderr, " Problem with query.\n");
        list_destroy(print_fields_list);
        return SLURM_ERROR;
    }
    itr = list_iterator_create(qos_list);
    itr2 = list_iterator_create(print_fields_list);
    print_fields_header(print_fields_list);

    field_count = list_count(print_fields_list);

    while((qos = list_next(itr))) {
        int curr_inx = 1;
        while((field = list_next(itr2))) {
            switch(field->type) {
            case PRINT_DESC:
                field->print_routine(
                    field, qos->description,
                    (curr_inx == field_count));
                break;
            case PRINT_FLAGS:
            {
                char *tmp_char = slurmdb_qos_flags_str(
                                     qos->flags);
                field->print_routine(
                    field,
                    tmp_char,
                    (curr_inx == field_count));
                xfree(tmp_char);
                break;
            }
            case PRINT_UT:
                field->print_routine(
                    field, qos->usage_thres,
                    (curr_inx == field_count));
                break;
            case PRINT_GRACE:
                field->print_routine(
                    field, (uint64_t)qos->grace_time,
                    (curr_inx == field_count));
                break;
            case PRINT_GRPCM:
                field->print_routine(
                    field,
                    qos->grp_cpu_mins,
                    (curr_inx == field_count));
                break;
            case PRINT_GRPCRM:
                field->print_routine(
                    field,
                    qos->grp_cpu_run_mins,
                    (curr_inx == field_count));
                break;
            case PRINT_GRPC:
                field->print_routine(field,
                                     qos->grp_cpus,
                                     (curr_inx == field_count));
                break;
            case PRINT_GRPJ:
                field->print_routine(field,
                                     qos->grp_jobs,
                                     (curr_inx == field_count));
                break;
            case PRINT_GRPMEM:
                field->print_routine(field,
                                     qos->grp_mem,
                                     (curr_inx == field_count));
                break;
            case PRINT_GRPN:
                field->print_routine(field,
                                     qos->grp_nodes,
                                     (curr_inx == field_count));
                break;
            case PRINT_GRPS:
                field->print_routine(field,
                                     qos->grp_submit_jobs,
                                     (curr_inx == field_count));
                break;
            case PRINT_GRPW:
                field->print_routine(
                    field,
                    qos->grp_wall,
                    (curr_inx == field_count));
                break;
            case PRINT_ID:
                field->print_routine(
                    field, qos->id,
                    (curr_inx == field_count));
                break;
            case PRINT_MAXCM:
                field->print_routine(
                    field,
                    qos->max_cpu_mins_pj,
                    (curr_inx == field_count));
                break;
            case PRINT_MAXCRM:
                field->print_routine(
                    field,
                    qos->max_cpu_run_mins_pu,
                    (curr_inx == field_count));
                break;
            case PRINT_MAXC:
                field->print_routine(field,
                                     qos->max_cpus_pj,
                                     (curr_inx == field_count));
                break;
            case PRINT_MAXCU:
                field->print_routine(field,
                                     qos->max_cpus_pu,
                                     (curr_inx == field_count));
                break;
            case PRINT_MAXJ:
                field->print_routine(field,
                                     qos->max_jobs_pu,
                                     (curr_inx == field_count));
                break;
            case PRINT_MAXN:
                field->print_routine(field,
                                     qos->max_nodes_pj,
                                     (curr_inx == field_count));
                break;
            case PRINT_MAXNU:
                field->print_routine(field,
                                     qos->max_nodes_pu,
                                     (curr_inx == field_count));
                break;
            case PRINT_MAXS:
                field->print_routine(field,
                                     qos->max_submit_jobs_pu,
                                     (curr_inx == field_count));
                break;
            case PRINT_MAXW:
                field->print_routine(
                    field,
                    qos->max_wall_pj,
                    (curr_inx == field_count));
                break;
            case PRINT_NAME:
                field->print_routine(
                    field, qos->name,
                    (curr_inx == field_count));
                break;
            case PRINT_PREE:
                if(!g_qos_list)
                    g_qos_list = acct_storage_g_get_qos(
                                     db_conn, my_uid, NULL);

                field->print_routine(
                    field, g_qos_list, qos->preempt_bitstr,
                    (curr_inx == field_count));
                break;
            case PRINT_PREEM:
            {
                char *tmp_char = "cluster";
                if(qos->preempt_mode)
                    tmp_char = xstrtolower(
                                   preempt_mode_string(
                                       qos->preempt_mode));
                field->print_routine(
                    field,
                    tmp_char,
                    (curr_inx == field_count));
                break;
            }
            case PRINT_PRIO:
                field->print_routine(
                    field, qos->priority,
                    (curr_inx == field_count));
                break;
            case PRINT_UF:
                field->print_routine(
                    field, qos->usage_factor,
                    (curr_inx == field_count));
                break;
            default:
                field->print_routine(
                    field, NULL,
                    (curr_inx == field_count));
                break;
            }
            curr_inx++;
        }
        list_iterator_reset(itr2);
        printf("\n");
    }
    list_iterator_destroy(itr2);
    list_iterator_destroy(itr);
    list_destroy(qos_list);
    list_destroy(print_fields_list);

    return rc;
}