extern int sacctmgr_delete_account(int argc, char *argv[]) { int rc = SLURM_SUCCESS; slurmdb_account_cond_t *acct_cond = xmalloc(sizeof(slurmdb_account_cond_t)); int i=0; List ret_list = NULL, local_assoc_list = NULL; ListIterator itr = NULL; int cond_set = 0, prev_set = 0; 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++; prev_set = _set_cond(&i, argc, argv, acct_cond, NULL); cond_set |= prev_set; } if (!cond_set) { exit_code=1; fprintf(stderr, " No conditions given to remove, not executing.\n"); slurmdb_destroy_account_cond(acct_cond); return SLURM_ERROR; } if (exit_code) { slurmdb_destroy_account_cond(acct_cond); return SLURM_ERROR; } /* check to see if person is trying to remove root account. This is * bad, and should not be allowed outside of deleting a cluster. */ if (acct_cond->assoc_cond && acct_cond->assoc_cond->acct_list && list_count(acct_cond->assoc_cond->acct_list)) { char *tmp_char = NULL; itr = list_iterator_create(acct_cond->assoc_cond->acct_list); while((tmp_char = list_next(itr))) { if (!strcasecmp(tmp_char, "root")) break; } list_iterator_destroy(itr); if (tmp_char) { exit_code=1; fprintf(stderr, " You are not allowed to remove " "the root account.\n" " Use remove cluster instead.\n"); slurmdb_destroy_account_cond(acct_cond); return SLURM_ERROR; } } acct_cond->assoc_cond->only_defs = 1; local_assoc_list = acct_storage_g_get_associations( db_conn, my_uid, acct_cond->assoc_cond); acct_cond->assoc_cond->only_defs = 0; notice_thread_init(); if (cond_set == 1) { ret_list = acct_storage_g_remove_accounts( db_conn, my_uid, acct_cond); } else if (cond_set & 2) { ret_list = acct_storage_g_remove_associations( db_conn, my_uid, acct_cond->assoc_cond); } rc = errno; notice_thread_fini(); slurmdb_destroy_account_cond(acct_cond); if (ret_list && list_count(ret_list)) { char *object = NULL; ListIterator itr = NULL; /* Check to see if person is trying to remove a default * account of a user. _isdefault only works with the * output from acct_storage_g_remove_accounts, and * with a previously got assoc_list. */ if (_isdefault(cond_set, ret_list, local_assoc_list)) { exit_code=1; fprintf(stderr, " Please either remove the " "accounts listed " "above from list and resubmit,\n" " or change these users default account to " "remove the account(s).\n" " Changes Discarded\n"); acct_storage_g_commit(db_conn, 0); goto end_it; } itr = list_iterator_create(ret_list); /* If there were jobs running with an association to be deleted, don't. */ if (rc == ESLURM_JOBS_RUNNING_ON_ASSOC) { fprintf(stderr, " Error with request: %s\n", slurm_strerror(rc)); while((object = list_next(itr))) { fprintf(stderr," %s\n", object); } acct_storage_g_commit(db_conn, 0); goto end_it; } if (cond_set == 1) { printf(" Deleting accounts...\n"); } else if (cond_set & 2) { printf(" Deleting account associations...\n"); } while((object = list_next(itr))) { printf(" %s\n", object); } list_iterator_destroy(itr); if (commit_check("Would you like to commit changes?")) { acct_storage_g_commit(db_conn, 1); } else { printf(" Changes Discarded\n"); acct_storage_g_commit(db_conn, 0); } } else if (ret_list) { printf(" Nothing deleted\n"); rc = SLURM_ERROR; } else { exit_code=1; fprintf(stderr, " Error with request: %s\n", slurm_strerror(errno)); rc = SLURM_ERROR; } end_it: if (ret_list) list_destroy(ret_list); if (local_assoc_list) list_destroy(local_assoc_list); return rc; }
extern int sacctmgr_delete_qos(int argc, char *argv[]) { int rc = SLURM_SUCCESS; slurmdb_qos_cond_t *qos_cond = xmalloc(sizeof(slurmdb_qos_cond_t)); int i=0; List ret_list = NULL; int set = 0; 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 += _set_cond(&i, argc, argv, qos_cond, NULL); } if(!set) { exit_code=1; fprintf(stderr, " No conditions given to remove, not executing.\n"); slurmdb_destroy_qos_cond(qos_cond); return SLURM_ERROR; } else if(set == -1) { slurmdb_destroy_qos_cond(qos_cond); return SLURM_ERROR; } if (!g_qos_list) g_qos_list = acct_storage_g_get_qos( db_conn, my_uid, NULL); notice_thread_init(); ret_list = acct_storage_g_remove_qos(db_conn, my_uid, qos_cond); notice_thread_fini(); slurmdb_destroy_qos_cond(qos_cond); if(ret_list && list_count(ret_list)) { char *object = NULL; ListIterator itr = NULL; /* Check to see if person is trying to remove a default * qos of an association. _isdefault only works with the * output from acct_storage_g_remove_qos, and * with a previously got g_qos_list. */ if (_isdefault(ret_list)) { exit_code=1; fprintf(stderr, " Please either remove the qos' listed " "above from list and resubmit,\n" " or change the default qos to " "remove the qos.\n" " Changes Discarded\n"); acct_storage_g_commit(db_conn, 0); goto end_it; } itr = list_iterator_create(ret_list); printf(" Deleting QOS(s)...\n"); while((object = list_next(itr))) { printf(" %s\n", object); } list_iterator_destroy(itr); if(commit_check("Would you like to commit changes?")) { acct_storage_g_commit(db_conn, 1); } else { printf(" Changes Discarded\n"); acct_storage_g_commit(db_conn, 0); } } else if(ret_list) { printf(" Nothing deleted\n"); } else { exit_code=1; fprintf(stderr, " Error with request: %s\n", slurm_strerror(errno)); rc = SLURM_ERROR; } end_it: if(ret_list) list_destroy(ret_list); return rc; }