Esempio n. 1
0
/* sacctmgr_list_reservation()
 */
int sacctmgr_list_reservation(int argc, char **argv)
{
        List reservation_list;
        ListIterator itr;
	ListIterator itr2;
	List format_list = list_create(slurm_destroy_char);
	List print_fields_list;
        slurmdb_reservation_cond_t *reservation_cond =
		xmalloc(sizeof(slurmdb_reservation_cond_t));
        slurmdb_reservation_rec_t *reservation;
	int field_count, i;
	print_field_t *field;
	char *tmp_char;

 	/* If we don't have any arguments make sure we set up the
	   time correctly for just the past day.
	*/
	if (argc == 0) {
                struct tm start_tm;
		reservation_cond->time_start = time(NULL);

                if (!slurm_localtime_r(&reservation_cond->time_start,
				       &start_tm)) {
                        fprintf(stderr,
                                " Couldn't get localtime from %ld",
                                (long)reservation_cond->time_start);
                        exit_code = 1;
                        return 0;
                }
                start_tm.tm_sec = 0;
                start_tm.tm_min = 0;
                start_tm.tm_hour = 0;
                start_tm.tm_mday--;
                start_tm.tm_isdst = -1;
                reservation_cond->time_start = slurm_mktime(&start_tm);
        }
   	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, reservation_cond, format_list);
	}

	if (exit_code) {
		slurmdb_destroy_reservation_cond(reservation_cond);
		FREE_NULL_LIST(format_list);
		return SLURM_ERROR;
	}

	if (!list_count(format_list)) {
		/* Append to the format list the fields
		 * we want to print, these are the data structure
		 * members of the type returned by slurmdbd
		 */
		slurm_addto_char_list(format_list,
				      "Cluster,Name%15,TRES%30,"
				      "TimeStart,TimeEnd");
	}

	reservation_list = acct_storage_g_get_reservations(
		db_conn, my_uid, reservation_cond);
	slurmdb_destroy_reservation_cond(reservation_cond);

	if (!reservation_list) {
		exit_code=1;
		fprintf(stderr, " Problem with query.\n");
		FREE_NULL_LIST(format_list);
		return SLURM_ERROR;
	}


	/* Process the format list creating a list of
	 * print field_t structures
	 */
	print_fields_list = sacctmgr_process_format_list(format_list);
	FREE_NULL_LIST(format_list);

        itr = list_iterator_create(reservation_list);
	itr2 = list_iterator_create(print_fields_list);
	print_fields_header(print_fields_list);
	field_count = list_count(print_fields_list);

	/* For each reservation prints the data structure members
	 */
        while ((reservation = list_next(itr))) {
		while ((field = list_next(itr2))) {
			switch (field->type) {
			case PRINT_ASSOC_NAME:
				field->print_routine(
					field,
					reservation->assocs,
					field_count);
				break;
			case PRINT_CLUSTER:
				field->print_routine(
					field,
					reservation->cluster,
					field_count);
				break;
			case PRINT_FLAGS:
				tmp_char = reservation_flags_string(
					reservation->flags);
				field->print_routine(
					field,
					tmp_char,
					field_count);
				xfree(tmp_char);
				break;
			case PRINT_ID:
				field->print_routine(field,
						     reservation->id,
						     field_count);
				break;
			case PRINT_NAME:
				field->print_routine(field,
						     reservation->name,
						     field_count);
				break;
			case PRINT_NODENAME:
				field->print_routine(
					field,
					reservation->nodes,
					field_count);
				break;
			case PRINT_TIMEEND:
				field->print_routine(
					field,
					reservation->time_end,
					field_count);
				break;
			case PRINT_TIMESTART:
				field->print_routine(
					field,
					reservation->time_start,
					field_count);
				break;
			case PRINT_TRES:
				if (!g_tres_list) {
					slurmdb_tres_cond_t tres_cond;
					memset(&tres_cond, 0,
					       sizeof(slurmdb_tres_cond_t));
					tres_cond.with_deleted = 1;
					g_tres_list = slurmdb_tres_get(
						db_conn, &tres_cond);
				}

				tmp_char = slurmdb_make_tres_string_from_simple(
					reservation->tres_str, g_tres_list);
				field->print_routine(field,
						     tmp_char,
						     field_count);
				xfree(tmp_char);
				break;
			}
		}
		list_iterator_reset(itr2);
		printf("\n");
        }
	list_iterator_destroy(itr);
	list_iterator_destroy(itr2);
	FREE_NULL_LIST(reservation_list);
	FREE_NULL_LIST(print_fields_list);

        return 0;
}
Esempio n. 2
0
/*
 * get info from the storage
 * IN:  slurmdb_reservation_cond_t *
 * RET: List of slurmdb_reservation_rec_t *
 * note List needs to be freed when called
 */
extern List slurmdb_reservations_get(void *db_conn,
				     slurmdb_reservation_cond_t *resv_cond)
{
	return acct_storage_g_get_reservations(db_conn, getuid(), resv_cond);
}