void instance_create_from_image_id(char *image_id, void (*completion_func)(char *instance_id, void *data), void *data) { struct deltacloud_api api; char *instance_id; int rc; rc = deltacloud_initialize(&api, "http://localhost:3001/api", "dep-wp", ""); if (rc < 0) { qb_log(LOG_ERR, "Failed to initialize libdeltacloud: %s", deltacloud_get_last_error_string()); qb_leave(); return; } rc = deltacloud_create_instance(&api, image_id, NULL, 0, &instance_id); if (rc < 0) { qb_log(LOG_ERR, "Failed to initialize libdeltacloud: %s", deltacloud_get_last_error_string()); qb_leave(); return; } completion_func(instance_id, data); deltacloud_free(&api); }
int main() { struct deltacloud_api api; struct deltacloud_instance instance; int ret = 2; // replace url and email with your domain info. if (deltacloud_initialize(&api, "http://ovirt.yourdomain.com:3002/api", "*****@*****.**", "123456") < 0) { fprintf(stderr, "Failed to initialize libdeltacloud: %s\n", deltacloud_get_last_error_string()); return 1; } // get the instance directly by name, replace with your image name if ( deltacloud_get_instance_by_name(&api, "kvm_test_image_64", &instance) ) { fprintf(stderr, "Failed to get deltacloud instances: %s\n", deltacloud_get_last_error_string()); return ret; } printf("We did it!\n"); printf("---Here are the details---\n"); printf("href =%s\n",instance.href); printf("id =%s\n",instance.id); printf("name =%s\n",instance.name); printf("owner_id =%s\n",instance.owner_id); printf("image_id =%s\n",instance.image_id); printf("image_href =%s\n",instance.image_href); printf("realm_id =%s\n",instance.realm_id); printf("realm_href =%s\n",instance.realm_href); printf("state =%s\n",instance.state); printf("launch_time =%s\n",instance.launch_time); // from here we can start the instance itself. // deltacloud_instance_start(&api, &instance) ret = 0; deltacloud_free(&api); return ret; }
void instance_destroy_by_instance_id(char *instance_id, void (*completion_func)(void *data), void *data) { struct deltacloud_api api; struct deltacloud_instance instance; int rc; rc = deltacloud_initialize(&api, "http://localhost:3001/api", "dep-wp", ""); if (rc < 0) { qb_log(LOG_ERR, "Failed to initialize libdeltacloud: %s", deltacloud_get_last_error_string()); qb_leave(); return; } rc = deltacloud_get_instance_by_id(&api, instance_id, &instance); deltacloud_instance_destroy(&api, &instance); completion_func(data); }
void image_id_get(char *image_name, void (*completion_func)(char *image_id, void *data), void *data) { static struct deltacloud_api api; struct deltacloud_image *images_head; struct deltacloud_image *images; int rc; qb_enter(); if (deltacloud_initialize(&api, "http://localhost:3001/api", "dep-wp", "") < 0) { qb_log(LOG_ERR, "Failed to initialize libdeltacloud: %s", deltacloud_get_last_error_string()); qb_leave(); return; } rc = deltacloud_get_images(&api, &images); if (rc < 0) { qb_log(LOG_ERR, "Failed to initialize libdeltacloud: %s", deltacloud_get_last_error_string()); qb_leave(); return; } for (images_head = images; images; images = images->next) { if (strcmp(images->name, image_name) == 0) { completion_func(images->id, data); break; } } deltacloud_free_image_list(&images_head); deltacloud_free(&api); qb_leave(); }
/* * External API */ void instance_state_get(char *instance_id, void (*completion_func)(char *status, char *ip_addr, void *data), void *data) { struct deltacloud_api api; struct deltacloud_instance instance; int rc; rc = deltacloud_initialize(&api, "http://localhost:3001/api", "dep-wp", ""); if (rc < 0) { qb_log(LOG_ERR, "Failed to initialize libdeltacloud: %s", deltacloud_get_last_error_string()); qb_leave(); return; } rc = deltacloud_get_instance_by_id(&api, instance_id, &instance); if (strcmp(instance.state, "RUNNING") == 0 && instance.private_addresses->address) { completion_func("ACTIVE", instance.private_addresses->address, data); } else { completion_func("PENDING", NULL, data); } }
int main(int argc, char *argv[]) { struct deltacloud_api api; struct deltacloud_api zeroapi; struct deltacloud_image image; struct deltacloud_image *images = NULL; //struct deltacloud_instance instance; //char *instid; //char *imgid; //int timeout; int ret = 3; if (argc != 4) { fprintf(stderr, "Usage: %s <url> <user> <password>\n", argv[0]); return 1; } memset(&zeroapi, 0, sizeof(struct deltacloud_api)); if (deltacloud_initialize(&api, argv[1], argv[2], argv[3]) < 0) { fprintf(stderr, "Failed to find links for the API: %s\n", deltacloud_get_last_error_string()); return 2; } /* test out deltacloud_supports_images */ if (deltacloud_supports_images(NULL) >= 0) { fprintf(stderr, "Expected deltacloud_supports_images to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_supports_images(&zeroapi) >= 0) { fprintf(stderr, "Expected deltacloud_supports_images to fail with uninitialized api, but succeeded\n"); goto cleanup; } if (deltacloud_supports_images(&api)) { /* test out deltacloud_get_images */ if (deltacloud_get_images(NULL, &images) >= 0) { fprintf(stderr, "Expected deltacloud_get_images to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_get_images(&api, NULL) >= 0) { fprintf(stderr, "Expected deltacloud_get_images to fail with NULL images, but succeeded\n"); goto cleanup; } if (deltacloud_get_images(&zeroapi, &images) >= 0) { fprintf(stderr, "Expected deltacloud_get_images to fail with unintialized api, but succeeded\n"); goto cleanup; } if (deltacloud_get_images(&api, &images) < 0) { fprintf(stderr, "Failed to get_images: %s\n", deltacloud_get_last_error_string()); goto cleanup; } print_image_list(images); if (images != NULL) { /* test out deltacloud_get_image_by_id */ if (deltacloud_get_image_by_id(NULL, images->id, &image) >= 0) { fprintf(stderr, "Expected deltacloud_get_image_by_id to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_get_image_by_id(&api, NULL, &image) >= 0) { fprintf(stderr, "Expected deltacloud_get_image_by_id to fail with NULL id, but succeeded\n"); goto cleanup; } if (deltacloud_get_image_by_id(&api, images->id, NULL) >= 0) { fprintf(stderr, "Expected deltacloud_get_image_by_id to fail with NULL image, but succeeded\n"); goto cleanup; } if (deltacloud_get_image_by_id(&api, "bogus_id", &image) >= 0) { fprintf(stderr, "Expected deltacloud_get_image_by_id to fail with bogus id, but succeeded\n"); goto cleanup; } if (deltacloud_get_image_by_id(&zeroapi, images->id, &image) >= 0) { fprintf(stderr, "Expected deltacloud_get_image_by_id to fail with unintialized api, but succeeded\n"); goto cleanup; } /* here we use the first image from the list above */ if (deltacloud_get_image_by_id(&api, images->id, &image) < 0) { fprintf(stderr, "Failed to get image by id: %s\n", deltacloud_get_last_error_string()); goto cleanup; } print_image(&image); deltacloud_free_image(&image); } /* FIXME: due to bugs in deltacloud, I can't seem to make this work * at present. We'll have to revisit. */ #if 0 if (deltacloud_supports_instances(&api)) { /* the first thing we need to do is create an instance that we will * snapshot from. In order to create an instance, we need to find * an image to base the instance off of. We fetch the list of images * and just use the first one */ if (deltacloud_get_images(&api, &images) < 0) { fprintf(stderr, "Failed to get images: %s\n", deltacloud_get_last_error_string()); goto cleanup; } if (deltacloud_create_instance(&api, images->id, NULL, 0, &instid) < 0) { deltacloud_free_image_list(&images); fprintf(stderr, "Failed to create instance: %s\n", deltacloud_get_last_error_string()); goto cleanup; } deltacloud_free_image_list(&images); if (wait_for_instance_boot(api, instid, &instance) != 1) { free(instid); goto cleanup; } free(instid); /* if we made it here, then the instance went to running. We can * now do operations on it */ if (deltacloud_create_image(&api, "newimage", &instance, NULL, 0, &imgid) < 0) { deltacloud_instance_destroy(&api, &instance); deltacloud_free_instance(&instance); fprintf(stderr, "Failed to create image from instance: %s\n", deltacloud_get_last_error_string()); goto cleanup; } free(imgid); deltacloud_instance_destroy(&api, &instance); deltacloud_free_instance(&instance); } else fprintf(stderr, "Instances are not supported, so image creation test is skipped\n"); #endif } else fprintf(stderr, "Images are not supported\n"); ret = 0; cleanup: deltacloud_free_image_list(&images); deltacloud_free(&api); return ret; }
int main(int argc, char *argv[]) { struct deltacloud_api api; struct deltacloud_api zeroapi; struct deltacloud_realm realm; struct deltacloud_realm *realms; int ret = 3; if (argc != 4) { fprintf(stderr, "Usage: %s <url> <user> <password>\n", argv[0]); return 1; } if (deltacloud_initialize(&api, argv[1], argv[2], argv[3]) < 0) { fprintf(stderr, "Failed to find links for the API: %s\n", deltacloud_get_last_error_string()); return 2; } memset(&zeroapi, 0, sizeof(struct deltacloud_api)); /* test out deltacloud_supports_realms */ if (deltacloud_supports_realms(NULL) >= 0) { fprintf(stderr, "Expected deltacloud_supports_realms to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_supports_realms(&zeroapi) >= 0) { fprintf(stderr, "Expected deltacloud_supports_realms to fail with uninitialized api, but succeeded\n"); goto cleanup; } if (deltacloud_supports_realms(&api)) { /* test out deltacloud_get_realms */ if (deltacloud_get_realms(NULL, &realms) >= 0) { fprintf(stderr, "Expected deltacloud_get_realms to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_get_realms(&api, NULL) >= 0) { fprintf(stderr, "Expected deltacloud_get_realms to fail with NULL realms, but succeeded\n"); goto cleanup; } if (deltacloud_get_realms(&zeroapi, &realms) >= 0) { fprintf(stderr, "Expected deltacloud_get_realms to fail with unintialized api, but succeeded\n"); goto cleanup; } if (deltacloud_get_realms(&api, &realms) < 0) { fprintf(stderr, "Failed to get_realms: %s\n", deltacloud_get_last_error_string()); goto cleanup; } print_realm_list(realms); if (realms != NULL) { /* test out deltacloud_get_realm_by_id */ if (deltacloud_get_realm_by_id(NULL, realms->id, &realm) >= 0) { fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_get_realm_by_id(&api, NULL, &realm) >= 0) { fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with NULL id, but succeeded\n"); goto cleanup; } if (deltacloud_get_realm_by_id(&api, realms->id, NULL) >= 0) { fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with NULL realm, but succeeded\n"); goto cleanup; } if (deltacloud_get_realm_by_id(&api, "bogus_id", &realm) >= 0) { fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with bogus id, but succeeded\n"); goto cleanup; } if (deltacloud_get_realm_by_id(&zeroapi, realms->id, &realm) >= 0) { fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with unintialized api, but succeeded\n"); goto cleanup; } /* here we use the first realm from the list above */ if (deltacloud_get_realm_by_id(&api, realms->id, &realm) < 0) { fprintf(stderr, "Failed to get realm by id: %s\n", deltacloud_get_last_error_string()); goto cleanup; } print_realm(&realm); deltacloud_free_realm(&realm); } } else fprintf(stderr, "Realms are not supported\n"); ret = 0; cleanup: deltacloud_free_realm_list(&realms); deltacloud_free(&api); return ret; }
int main(int argc, char *argv[]) { struct deltacloud_api api; struct deltacloud_api zeroapi; struct deltacloud_storage_snapshot *storage_snapshots; struct deltacloud_storage_snapshot storage_snapshot; int ret = 3; if (argc != 4) { fprintf(stderr, "Usage: %s <url> <user> <password>\n", argv[0]); return 1; } if (deltacloud_initialize(&api, argv[1], argv[2], argv[3]) < 0) { fprintf(stderr, "Failed to find links for the API: %s\n", deltacloud_get_last_error_string()); return 2; } memset(&zeroapi, 0, sizeof(struct deltacloud_api)); /* test out deltacloud_supports_storage_snapshots */ if (deltacloud_supports_storage_snapshots(NULL) >= 0) { fprintf(stderr, "Expected deltacloud_supports_storage_snapshots to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_supports_storage_snapshots(&zeroapi) >= 0) { fprintf(stderr, "Expected deltacloud_supports_storage_snapshots to fail with uninitialized api, but succeeded\n"); goto cleanup; } if (deltacloud_supports_storage_snapshots(&api)) { /* test out deltacloud_get_storage_snapshots */ if (deltacloud_get_storage_snapshots(NULL, &storage_snapshots) >= 0) { fprintf(stderr, "Expected deltacloud_get_storage_snapshots to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_get_storage_snapshots(&api, NULL) >= 0) { fprintf(stderr, "Expected deltacloud_get_storage_snapshots to fail with NULL storage_snapshots, but succeeded\n"); goto cleanup; } if (deltacloud_get_storage_snapshots(&zeroapi, &storage_snapshots) >= 0) { fprintf(stderr, "Expected deltacloud_get_storage_snapshots to fail with unintialized api, but succeeded\n"); goto cleanup; } if (deltacloud_get_storage_snapshots(&api, &storage_snapshots) < 0) { fprintf(stderr, "Failed to get_storage_snapshots: %s\n", deltacloud_get_last_error_string()); goto cleanup; } print_storage_snapshot_list(storage_snapshots); if (storage_snapshots != NULL) { /* test out deltacloud_get_storage_snapshot_by_id */ if (deltacloud_get_storage_snapshot_by_id(NULL, storage_snapshots->id, &storage_snapshot) >= 0) { fprintf(stderr, "Expected deltacloud_get_storage_snapshot_by_id to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_get_storage_snapshot_by_id(&api, NULL, &storage_snapshot) >= 0) { fprintf(stderr, "Expected deltacloud_get_storage_snapshot_by_id to fail with NULL id, but succeeded\n"); goto cleanup; } if (deltacloud_get_storage_snapshot_by_id(&api, storage_snapshots->id, NULL) >= 0) { fprintf(stderr, "Expected deltacloud_get_storage_snapshot_by_id to fail with NULL storage_snapshot, but succeeded\n"); goto cleanup; } if (deltacloud_get_storage_snapshot_by_id(&api, "bogus_id", &storage_snapshot) >= 0) { fprintf(stderr, "Expected deltacloud_get_storage_snapshot_by_id to fail with bogus id, but succeeded\n"); goto cleanup; } if (deltacloud_get_storage_snapshot_by_id(&zeroapi, storage_snapshots->id, &storage_snapshot) >= 0) { fprintf(stderr, "Expected deltacloud_get_storage_snapshot_by_id to fail with unintialized api, but succeeded\n"); goto cleanup; } /* here we use the first storage snapshot from the list above */ if (deltacloud_get_storage_snapshot_by_id(&api, storage_snapshots->id, &storage_snapshot) < 0) { fprintf(stderr, "Failed to get storage_snapshot by ID: %s\n", deltacloud_get_last_error_string()); deltacloud_free_storage_snapshot_list(&storage_snapshots); goto cleanup; } print_storage_snapshot(&storage_snapshot); deltacloud_free_storage_snapshot(&storage_snapshot); } deltacloud_free_storage_snapshot_list(&storage_snapshots); } else fprintf(stderr, "Storage Snapshots are not supported\n"); ret = 0; cleanup: deltacloud_free(&api); return ret; }