static bool complete_domains(void *parsed_arguments, const char *current_argument, size_t current_argument_len, DPtrArray *possibilities, void *UNUSED(data)) { domain_set_t *ds; FETCH_ACCOUNT_DOMAINS(ds); if (COMMAND_SUCCESS != fetch_domains(ds, FALSE, NULL)) { return FALSE; } return complete_from_hashtable_keys(parsed_arguments, current_argument, current_argument_len, possibilities, ds->domains); }
int main(int argc, char *argv[]) { int ret = EXIT_FAILURE; virConnectPtr conn = NULL; const char *uri = NULL; const char *dom_name = NULL; unsigned int seconds = 1; /* Suspend domain for this long */ const int connect_flags = 0; /* No connect flags for now */ if (parse_argv(argc, argv, &uri, &dom_name, &seconds) < 0) goto cleanup; DEBUG("Proceeding with uri=%s dom_name=%s seconds=%u", uri, dom_name, seconds); if (!(conn = virConnectOpenAuth(uri, virConnectAuthPtrDefault, connect_flags))) { ERROR("Failed to connect to hypervisor"); goto cleanup; } DEBUG("Successfully connected"); if (!dom_name) { if (fetch_domains(conn) == 0) ret = EXIT_SUCCESS; goto cleanup; } if (suspend_and_resume(conn, dom_name, seconds) < 0) goto cleanup; ret = EXIT_SUCCESS; cleanup: if (conn) { int tmp; tmp = virConnectClose(conn); if (tmp < 0) { ERROR("Failed to disconnect from the hypervisor"); ret = EXIT_FAILURE; } else if (tmp > 0) { ERROR("One or more references were leaked after " "disconnect from the hypervisor"); ret = EXIT_FAILURE; } else { DEBUG("Connection successfully closed"); } } return ret; }
static command_status_t domain_check(COMMAND_ARGS) { bool success; domain_set_t *ds; USED(arg); USED(mainopts); FETCH_ACCOUNT_DOMAINS(ds); // populate if ((success = (COMMAND_SUCCESS == fetch_domains(ds, FALSE, error)))) { time_t now; Iterator it; now = time(NULL); hashtable_to_iterator(&it, ds->domains); for (iterator_first(&it); success && iterator_is_valid(&it); iterator_next(&it)) { request_t *req; json_document_t *doc; const char *domain_name; iterator_current(&it, (void **) &domain_name); // request req = request_new(REQUEST_FLAG_SIGN, HTTP_GET, NULL, error, API_BASE_URL "/domain/%s/serviceInfos", domain_name); success = request_execute(req, RESPONSE_JSON, (void **) &doc, error); request_destroy(req); // response if (success) { time_t domain_expiration; json_value_t root, expiration; root = json_document_get_root(doc); if (json_object_get_property(root, "expiration", &expiration)) { if (date_parse_to_timestamp(json_get_string(expiration), NULL, &domain_expiration)) { int diff_days; diff_days = date_diff_in_days(domain_expiration, now); if (diff_days > 0 && diff_days < 3000) { printf("%s expires in %d days\n", domain_name, diff_days); } } } json_document_destroy(doc); } } iterator_close(&it); } return success ? COMMAND_SUCCESS : COMMAND_FAILURE; }
static command_status_t domain_list(COMMAND_ARGS) { domain_set_t *ds; command_status_t ret; domain_record_argument_t *args; USED(mainopts); args = (domain_record_argument_t *) arg; FETCH_ACCOUNT_DOMAINS(ds); // populate if (COMMAND_SUCCESS != (ret = fetch_domains(ds, args->nocache, error))) { return ret; } // display hashtable_puts_keys(ds->domains); return COMMAND_SUCCESS; }