Ejemplo n.º 1
0
int main(int argc, char **argv)
{
    ncMetadata meta = { "correlate-me-please", "eucalyptus" };
    virtualMachine params = { 64, 1, 1, "m1.small", NULL, NULL, NULL, NULL, NULL, {}, 0 };
    char *nc_hostport = DEFAULT_NC_HOSTPORT;
    char *walrus_hostport = DEFAULT_WALRUS_HOSTPORT;
    char *instance_id = NULL;
    char *image_id = NULL;
    char *image_manifest = NULL;
    char *kernel_id = NULL;
    char *kernel_manifest = NULL;
    char *ramdisk_id = NULL;
    char *ramdisk_manifest = NULL;
    char *reservation_id = NULL;
    char *uu_id = NULL;
    char *mac_addr = strdup(DEFAULT_MAC_ADDR);
    char *public_ip = strdup(DEFAULT_PUBLIC_IP);
    char *volume_id = NULL;
    char *remote_dev = NULL;
    char *local_dev = NULL;
    int force = 0;
    char *user_data = NULL;
    char *launch_index = NULL;
    char **group_names = NULL;
    int group_names_size = 0;
    char *timestamp_str = NULL;
    char *command = NULL;
    int local = 0;
    int count = 1;
    int ch;

    while ((ch = getopt(argc, argv, "lhdn:w:i:m:k:r:e:a:c:h:u:p:V:R:L:FU:I:G:v:t:")) != -1) {
        switch (ch) {
        case 'c':
            count = atoi(optarg);
            break;
        case 'd':
            debug = 1;
            break;
        case 'l':
            local = 1;
            break;
        case 'n':
            nc_hostport = optarg;
            break;
        case 'w':
            walrus_hostport = optarg;
            break;
        case 'i':
            instance_id = optarg;
            break;
        case 'p':
            public_ip = optarg;
            break;
        case 'm':
            image_id = strtok(optarg, ":");
            image_manifest = strtok(NULL, ":");
            if (image_id == NULL || image_manifest == NULL) {
                fprintf(stderr, "ERROR: could not parse image [id:manifest] paramters (try -h)\n");
                exit(1);
            }
            break;
        case 'k':
            kernel_id = strtok(optarg, ":");
            kernel_manifest = strtok(NULL, ":");
            if (kernel_id == NULL || kernel_manifest == NULL) {
                fprintf(stderr, "ERROR: could not parse kernel [id:manifest] paramters (try -h)\n");
                exit(1);
            }
            break;
        case 'r':
            ramdisk_id = strtok(optarg, ":");
            ramdisk_manifest = strtok(NULL, ":");
            if (ramdisk_id == NULL || ramdisk_manifest == NULL) {
                fprintf(stderr, "ERROR: could not parse ramdisk [id:manifest] paramters (try -h)\n");
                exit(1);
            }
            break;
        case 'e':
            reservation_id = optarg;
            break;
        case 'u':
            uu_id = optarg;
            break;
        case 'a':
            mac_addr = optarg;
            break;
        case 'V':
            volume_id = optarg;
            break;
        case 'R':
            remote_dev = optarg;
            break;
        case 'L':
            local_dev = optarg;
            break;
        case 'F':
            force = 1;
            break;
        case 'U':
            user_data = optarg;
            break;
        case 'I':
            launch_index = optarg;
            break;
        case 'G':
            {
                int i;
                group_names_size = 1;
                for (i = 0; optarg[i]; i++)
                    if (optarg[i] == ':')
                        group_names_size++;
                group_names = malloc(sizeof(char *) * group_names_size);
                if (group_names == NULL) {
                    fprintf(stderr, "ERROR: out of memory for group_names[]\n");
                    exit(1);
                }
                group_names[0] = strtok(optarg, ":");
                for (i = 1; i < group_names_size; i++)
                    group_names[i] = strtok(NULL, ":");
                break;
            }
        case 'v':
            if (add_vbr(optarg, &params)) {
                fprintf(stderr, "ERROR: could not parse the virtual boot record (try -h)\n");
                exit(1);
            }
            break;
        case 't':
            timestamp_str = optarg;
            break;
        case 'h':
            usage();            // will exit
        case '?':
        default:
            fprintf(stderr, "ERROR: unknown parameter (try -h)\n");
            exit(1);
        }
    }
    argc -= optind;
    argv += optind;

    if (argc > 0) {
        command = argv[0];
        if (argc > 1) {
            fprintf(stderr, "WARNING: too many parameters, using first one as command\n");
        }
    } else {
        fprintf(stderr, "ERROR: command not specified (try -h)\n");
        exit(1);
    }

    ncStub *stub;
    char configFile[1024], policyFile[1024];
    char *euca_home;
    int rc, use_wssec;
    char *tmpstr;

    euca_home = getenv("EUCALYPTUS");
    if (!euca_home) {
        euca_home = "";
    }
    snprintf(configFile, 1024, EUCALYPTUS_CONF_LOCATION, euca_home);
    snprintf(policyFile, 1024, EUCALYPTUS_KEYS_DIR "/nc-client-policy.xml", euca_home);
    rc = get_conf_var(configFile, "ENABLE_WS_SECURITY", &tmpstr);
    if (rc != 1) {
        /* Default to enabled */
        use_wssec = 1;
    } else {
        if (!strcmp(tmpstr, "Y")) {
            use_wssec = 1;
        } else {
            use_wssec = 0;
        }
    }

    char nc_url[BUFSIZE];
    snprintf(nc_url, BUFSIZE, "http://%s%s", nc_hostport, NC_ENDPOINT);
    if (debug)
        printf("connecting to NC at %s\n", nc_url);
    stub = ncStubCreate(nc_url, "NCclient.log", NULL);
    if (!stub) {
        fprintf(stderr, "ERROR: failed to connect to Web service\n");
        exit(2);
    }

    char walrus_url[BUFSIZE];
    snprintf(walrus_url, BUFSIZE, "http://%s%s", walrus_hostport, WALRUS_ENDPOINT);
    serviceInfoType *si = &(meta.services[meta.servicesLen++]);
    safe_strncpy(si->type, "walrus", sizeof(si->type));
    safe_strncpy(si->name, "walrus", sizeof(si->name));
    safe_strncpy(si->uris[0], walrus_url, sizeof(si->uris[0]));
    si->urisLen = 1;

    if (use_wssec && !local) {
        if (debug)
            printf("using policy file %s\n", policyFile);
        rc = InitWSSEC(stub->env, stub->stub, policyFile);
        if (rc) {
            fprintf(stderr, "ERROR: cannot initialize WS-SEC policy from %s\n", policyFile);
            exit(1);
        }
    }

    char *image_url = NULL;
    if (image_manifest) {
        char t[BUFSIZE];
        snprintf(t, BUFSIZE, "http://%s%s/%s", walrus_hostport, WALRUS_ENDPOINT, image_manifest);
        image_url = strdup(t);
    }

    char *kernel_url = NULL;
    if (kernel_manifest) {
        char t[BUFSIZE];
        snprintf(t, BUFSIZE, "http://%s%s/%s", walrus_hostport, WALRUS_ENDPOINT, kernel_manifest);
        kernel_url = strdup(t);
    }

    char *ramdisk_url = NULL;
    if (ramdisk_manifest) {
        char t[BUFSIZE];
        snprintf(t, BUFSIZE, "http://%s%s/%s", walrus_hostport, WALRUS_ENDPOINT, ramdisk_manifest);
        ramdisk_url = strdup(t);
    }

    /***********************************************************/
    if (!strcmp(command, "runInstance")) {
        if (params.virtualBootRecordLen < 1) {
            CHECK_PARAM(image_id, "image ID and manifest path");
            CHECK_PARAM(kernel_id, "kernel ID and manifest path");
        }

        char *privMac, *pubMac, *privIp;
        char *platform = NULL;
        int vlan = 3;
        privMac = strdup(mac_addr);
        mac_addr[0] = 'b';
        mac_addr[1] = 'b';
        privIp = strdup("10.0.0.202");
        srand(time(NULL));

        /* generate random IDs if they weren't specified */
#define C rand()%26 + 97

        while (count--) {
            char *iid, *rid, *uuid;

            char ibuf[8];
            if (instance_id == NULL || count > 1) {
                snprintf(ibuf, 8, "i-%c%c%c%c%c", C, C, C, C, C);
                iid = ibuf;
            } else {
                iid = instance_id;
            }

            char rbuf[8];
            if (reservation_id == NULL || count > 1) {
                snprintf(rbuf, 8, "r-%c%c%c%c%c", C, C, C, C, C);
                rid = rbuf;
            } else {
                rid = reservation_id;
            }

            char ubuf[48];
            if (uu_id == NULL || count > 1) {
                snprintf(ubuf, 48, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C,
                         C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C);
                uuid = ubuf;
            } else {
                uuid = uu_id;
            }

            netConfig netparams;
            ncInstance *outInst;
            bzero(&netparams, sizeof(netparams));
            netparams.vlan = vlan;
            snprintf(netparams.privateIp, 24, "%s", privIp);
            snprintf(netparams.privateMac, 24, "%s", privMac);

            int rc = ncRunInstanceStub(stub, &meta,
                                       uuid, iid, rid,
                                       &params,
                                       image_id, image_url,
                                       kernel_id, kernel_url,
                                       ramdisk_id, ramdisk_url,
                                       "eucalyptusUser", "eucalyptusAccount",
                                       "",  /* key */
                                       &netparams,
                                       //                                       privMac, privIp, vlan, 
                                       user_data, launch_index, platform, 0, group_names, group_names_size, /* CC stuff */
                                       &outInst);
            if (rc != 0) {
                printf("ncRunInstance() failed: instanceId=%s error=%d\n", instance_id, rc);
                exit(1);
            }
            // count device mappings
            int i, count = 0;
            for (i = 0; i < EUCA_MAX_VBRS; i++) {
                if (strlen(outInst->params.virtualBootRecord[i].typeName) > 0)
                    count++;
            }
            printf("instanceId=%s stateCode=%d stateName=%s deviceMappings=%d/%d\n", outInst->instanceId, outInst->stateCode, outInst->stateName,
                   count, outInst->params.virtualBootRecordLen);
        }

        /***********************************************************/
    } else if (!strcmp(command, "bundleInstance")) {
        CHECK_PARAM(instance_id, "instance id");
        int rc =
            ncBundleInstanceStub(stub, &meta, instance_id, "bucket-foo", "prefix-foo", "s3-url-foo", "user-key-foo", "s3policy-foo", "s3policy-sig");
        printf("ncBundleInstanceStub = %d\n", rc);

    } else if (!strcmp(command, "bundleRestartInstance")) {
        CHECK_PARAM(instance_id, "instance id");
        int rc = ncBundleRestartInstanceStub(stub, &meta, instance_id);
        printf("ncBundleRestartInstanceStub = %d\n", rc);
    } else if (!strcmp(command, "powerDown")) {
        int rc = ncPowerDownStub(stub, &meta);
    } else if (!strcmp(command, "describeBundleTasks")) {
        char *instIds[4];
        int instIdsLen;
        instIds[0] = malloc(sizeof(char) * 32);
        instIds[1] = malloc(sizeof(char) * 32);
        instIds[2] = malloc(sizeof(char) * 32);
        instIds[3] = malloc(sizeof(char) * 32);
        snprintf(instIds[0], 32, "i-12345675");
        snprintf(instIds[1], 32, "i-12345674");
        snprintf(instIds[2], 32, "i-12345673");
        snprintf(instIds[3], 32, "i-12345672");
        instIdsLen = 4;
        bundleTask **outBundleTasks = NULL;
        int outBundleTasksLen = 0;
        rc = ncDescribeBundleTasksStub(stub, &meta, instIds, instIdsLen, &outBundleTasks, &outBundleTasksLen);
        for (int i = 0; i < outBundleTasksLen; i++) {
            printf("BUNDLE %d: %s %s\n", i, outBundleTasks[i]->instanceId, outBundleTasks[i]->state);
        }
    } else if (!strcmp(command, "assignAddress")) {
        int rc = ncAssignAddressStub(stub, &meta, instance_id, public_ip);
    } else if (!strcmp(command, "terminateInstance")) {
        CHECK_PARAM(instance_id, "instance ID");

        int shutdownState, previousState;
        int rc = ncTerminateInstanceStub(stub, &meta, instance_id, 0, &shutdownState, &previousState);
        if (rc != 0) {
            printf("ncTerminateInstance() failed: error=%d\n", rc);
            exit(1);
        }
        printf("shutdownState=%d, previousState=%d\n", shutdownState, previousState);

        /***********************************************************/
    } else if (!strcmp(command, "describeInstances")) {
        /* TODO: pull out of argv[] requested instanceIDs */
        ncInstance **outInsts;
        int outInstsLen, i;
        int rc = ncDescribeInstancesStub(stub, &meta, NULL, 0, &outInsts, &outInstsLen);
        if (rc != 0) {
            printf("ncDescribeInstances() failed: error=%d\n", rc);
            exit(1);
        }
        for (i = 0; i < outInstsLen; i++) {
            ncInstance *inst = outInsts[i];
            printf("instanceId=%s state=%s time=%d\n", inst->instanceId, inst->stateName, inst->launchTime);
            if (debug) {
                printf("              userData=%s launchIndex=%s groupNames=", inst->userData, inst->launchIndex);
                if (inst->groupNamesSize > 0) {
                    int j;
                    for (j = 0; j < inst->groupNamesSize; j++) {
                        if (j > 0)
                            printf(":");
                        printf("%s", inst->groupNames[j]);
                    }
                } else {
                    printf("(none)");
                }
                printf("\n");

                printf("              attached volumes: ");
                int vol_count = 0;
                for (int j = 0; j < EUCA_MAX_VOLUMES; j++) {
                    if (strlen(inst->volumes[j].volumeId) > 0) {
                        if (vol_count > 0)
                            printf("                                ");
                        printf("%s %s %s\n", inst->volumes[j].volumeId, inst->volumes[j].remoteDev, inst->volumes[j].localDev);
                    }
                }
                if (vol_count)
                    printf("(none)\n");

                free_instance(&(outInsts[i]));
            }
        }
        /* TODO: fix free(outInsts); */

    /***********************************************************/
    } else if (!strcmp(command, "describeResource")) {
        char *type = NULL;
        ncResource *outRes;

        int rc = ncDescribeResourceStub(stub, &meta, type, &outRes);
        if (rc != 0) {
            printf("ncDescribeResource() failed: error=%d\n", rc);
            exit(1);
        }
        printf("node status=[%s] memory=%d/%d disk=%d/%d cores=%d/%d subnets=[%s]\n",
               outRes->nodeStatus,
               outRes->memorySizeMax, outRes->memorySizeAvailable, outRes->diskSizeMax, outRes->diskSizeAvailable, outRes->numberOfCoresMax,
               outRes->numberOfCoresAvailable, outRes->publicSubnets);

    /***********************************************************/
    } else if (!strcmp(command, "attachVolume")) {
        CHECK_PARAM(instance_id, "instance ID");
        CHECK_PARAM(volume_id, "volume ID");
        CHECK_PARAM(remote_dev, "remote dev");
        CHECK_PARAM(local_dev, "local dev");

        int rc = ncAttachVolumeStub(stub, &meta, instance_id, volume_id, remote_dev, local_dev);
        if (rc != 0) {
            printf("ncAttachVolume() failed: error=%d\n", rc);
            exit(1);
        }

    /***********************************************************/
    } else if (!strcmp(command, "detachVolume")) {
        CHECK_PARAM(instance_id, "instance ID");
        CHECK_PARAM(volume_id, "volume ID");
        CHECK_PARAM(remote_dev, "remote dev");
        CHECK_PARAM(local_dev, "local dev");

        int rc = ncDetachVolumeStub(stub, &meta, instance_id, volume_id, remote_dev, local_dev, force);
        if (rc != 0) {
            printf("ncDetachVolume() failed: error=%d\n", rc);
            exit(1);
        }

    /***********************************************************/
    } else if (!strcmp(command, "describeSensors")) {

        sensorResource **res;
        int resSize;

        int rc = ncDescribeSensorsStub(stub, &meta, 20, 5000, NULL, 0, NULL, 0, &res, &resSize);
        if (rc != 0) {
            printf("ncDescribeSensors() failed: error=%d\n", rc);
            exit(1);
        }
        char buf[102400];
        sensor_res2str(buf, sizeof(buf), res, resSize);
        printf("resources: %d\n%s\n", resSize, buf);

    /***********************************************************/
    } else if (!strcmp(command, "_convertTimestamp")) {
        CHECK_PARAM(timestamp_str, "timestamp");

        axutil_date_time_t *dt = unixms_to_datetime(stub->env, 0123L);
        long long ts_l = datetime_to_unixms(dt, stub->env);
        printf("timestamp: %lld\n", ts_l);

    /***********************************************************/
    } else {
        fprintf(stderr, "ERROR: command %s unknown (try -h)\n", command);
        exit(1);
    }

    if (local) {
        pthread_exit(NULL);
    } else {
        _exit(0);
    }
}
Ejemplo n.º 2
0
int main(int argc, char **argv) {
	axutil_env_t * env = NULL;
	axis2_char_t * client_home = NULL;
	axis2_char_t endpoint_uri[256], *tmpstr;
	axis2_stub_t * stub = NULL;
	int rc, i, port, use_wssec;
	char *euca_home, configFile[1024], policyFile[1024];

	mymeta.userId = strdup("admin");
	mymeta.correlationId = strdup("1234abcd");
	mymeta.epoch = 3;
	mymeta.servicesLen = 16;
	snprintf(mymeta.services[15].name, 16, "eucalyptusname");
	snprintf(mymeta.services[15].type, 16, "eucalyptustype");
	snprintf(mymeta.services[15].partition, 16, "eucalyptuspart");
	mymeta.services[15].urisLen = 1;
	snprintf(mymeta.services[15].uris[0], 512, "http://192.168.254.3:8773/services/Eucalyptus");

	if (MODE == 0) {
		if (argc != 2 || strcmp(argv[1], "-9")) {
			printf("only runnable from inside euca\n");
			exit(1);
		}
	} else {
		if (argc < 3) {
			printf("USAGE: CCclient <host:port> <command> <opts>\n");
			exit(1);
		}
	}

	euca_home = getenv("EUCALYPTUS");
	if (!euca_home) {
		euca_home = "";
	}
	snprintf(configFile, 1024, EUCALYPTUS_CONF_LOCATION, euca_home);
	snprintf(policyFile, 1024, EUCALYPTUS_KEYS_DIR "/cc-client-policy.xml", euca_home);

	rc = get_conf_var(configFile, "CC_PORT", &tmpstr);
	if (rc != 1) {
		// error
		logprintf("ERROR: parsing config file (%s) for CC_PORT\n",configFile);
		exit(1);
	} else {
		port = atoi(tmpstr);
	}

	rc = get_conf_var(configFile, "ENABLE_WS_SECURITY", &tmpstr);
	if (rc != 1) {
		/* Default to enabled */
		use_wssec = 1;
	} else {
		if (!strcmp(tmpstr, "Y")) {
			use_wssec = 1;
		} else {
			use_wssec = 0;
		}
	}

	if (MODE == 0) {
		snprintf(endpoint_uri, 256,"http://localhost:%d/axis2/services/EucalyptusCC", port);
	} else {
		snprintf(endpoint_uri, 256,"http://%s/axis2/services/EucalyptusCC", argv[1]);
	}
	//env =  axutil_env_create_all(NULL, 0);
	env =  axutil_env_create_all("/tmp/fofo", AXIS2_LOG_LEVEL_TRACE);

	client_home = AXIS2_GETENV("AXIS2C_HOME");
	if (!client_home) {
		printf("must have AXIS2C_HOME set\n");
		exit(1);
	}
	stub = axis2_stub_create_EucalyptusCC(env, client_home, endpoint_uri);

	if (use_wssec) {
		rc = InitWSSEC(env, stub, policyFile);
		if (rc) {
			printf("cannot initialize WS-SEC policy (%s)\n",policyFile);
			exit(1);
		}
	}

	if (MODE == 0) {
		rc = cc_killallInstances(env, stub);
		if (rc != 0) {
			printf("cc_killallInstances() failed\n");
			exit(1);
		}
	} else {
		/*
		if (!strcmp(argv[2], "registerImage")) {
			rc = cc_registerImage(argv[3], env, stub);
			if (rc != 0) {
				printf("cc_registerImage() failed: in:%s out:%d\n", argv[3], rc);
				exit(1);
			}
		}
		*/
		if (!strcmp(argv[2], "runInstances")) {
			char *amiId=NULL, *amiURL=NULL, *kernelId=NULL, *kernelURL=NULL, *ramdiskId=NULL, *ramdiskURL=NULL;
			if (argv[3]) amiId = argv[3];
			if (argv[4]) amiURL = argv[4];
			if (argv[5]) kernelId = argv[5];
			if (argv[6]) kernelURL = argv[6];
			if (argv[10]) ramdiskId = argv[10];
			if (argv[11]) ramdiskURL = argv[11];

			virtualMachine params = { 64, 1, 64, "m1.small" };

			rc = cc_runInstances(amiId, amiURL, kernelId, kernelURL, ramdiskId, ramdiskURL, atoi(argv[7]), atoi(argv[8]), argv[9], &params, env, stub);
			if (rc != 0) {
				printf("cc_runInstances() failed: in:%s out:%d\n", argv[4], rc);
				exit(1);
			}
		} else if (!strcmp(argv[2], "describeInstances")) {
			rc = cc_describeInstances(NULL, 0, env, stub);
			if (rc != 0) {
				printf("cc_describeInstances() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "describeServices")) {
			rc = cc_describeServices(env, stub);
			if (rc != 0) {
				printf("cc_describeServices() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "startService")) {
			rc = cc_startService(env, stub);
			if (rc != 0) {
				printf("cc_startService() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "stopService")) {
			rc = cc_stopService(env, stub);
			if (rc != 0) {
				printf("cc_stopService() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "enableService")) {
			rc = cc_enableService(env, stub);
			if (rc != 0) {
				printf("cc_enableService() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "disableService")) {
			rc = cc_disableService(env, stub);
			if (rc != 0) {
				printf("cc_disableService() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "shutdownService")) {
			rc = cc_shutdownService(env, stub);
			if (rc != 0) {
				printf("cc_shutdownService() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "getConsoleOutput")) {
			rc = cc_getConsoleOutput(argv[3], env, stub);
			if (rc != 0) {
				printf("cc_getConsoleOutput() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "rebootInstances")) {
			char *instIds[256];
			if (argv[3] != NULL) {
				instIds[0] = strdup(argv[3]);
			}
			rc = cc_rebootInstances(instIds, 1, env, stub);
			if (rc != 0) {
				printf("cc_rebootInstances() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "terminateInstances")) {
			char *instIds[256];
			i=3;
			while (argv[i] != NULL) {
				instIds[i-3] = strdup(argv[i]);
				i++;
			}
			if ( (i-3) > 0) {
				rc = cc_terminateInstances(instIds, i-3, env, stub);
				if (rc != 0) {
					printf("cc_terminateInstances() failed\n");
					exit(1);
				}
			}
		} else if (!strcmp(argv[2], "describeResources")) {
			rc = cc_describeResources(env, stub);
			if (rc != 0) {
				printf("cc_describeResources() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "startNetwork")) {
			char **ccs;
			int ccsLen=0, i;
			ccs = malloc(sizeof(char *) * 32);
			for (i=0; i<32; i++) {
				if (argv[i+5]) {
					ccs[i] = strdup(argv[i+5]);
					ccsLen++;
				} else {
					i=33;
				}
			}
			rc = cc_startNetwork(atoi(argv[3]), argv[4], ccs, ccsLen, env, stub);
			if (rc != 0) {
				printf("cc_startNetwork() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "describeNetworks")) {
			char **ccs, *nameserver;
			int ccsLen=0, i;
			ccs = malloc(sizeof(char *) * 32);
			for (i=0; i<32; i++) {
				if (argv[i+3]) {
					ccs[i] = strdup(argv[i+3]);
					ccsLen++;
				} else {
					i=33;
				}
			}
			nameserver = strdup("1.2.3.4");

			rc = cc_describeNetworks(nameserver, ccs, ccsLen, env, stub);
			if (rc != 0) {
				printf("cc_describeNetworks() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "configureNetwork")) {
			rc = cc_configureNetwork(argv[3], argv[4], argv[5], atoi(argv[6]), atoi(argv[7]), argv[8], env, stub);
			if (rc != 0) {
				printf("cc_configureNetwork() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "stopNetwork")) {
			rc = cc_stopNetwork(atoi(argv[3]), argv[4], env, stub);
			if (rc != 0) {
				printf("cc_stopNetwork() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "assignAddress")) {
			rc = cc_assignAddress(argv[3], argv[4], env, stub);
			if (rc != 0) {
				printf("cc_assignNetwork() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "unassignAddress")) {
			rc = cc_unassignAddress(argv[3], argv[4], env, stub);
			if (rc != 0) {
				printf("cc_unassignNetwork() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "attachVolume")) {
			rc = cc_attachVolume(argv[3], argv[4], argv[5], argv[6], env, stub);
			if (rc != 0) {
				printf("cc_attachVolume() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "detachVolume")) {
			rc = cc_detachVolume(argv[3], argv[4], argv[5], argv[6], atoi(argv[7]), env, stub);
			if (rc != 0) {
				printf("cc_unassignNetwork() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "bundleInstance")) {
			rc = cc_bundleInstance(argv[3], argv[4], argv[5], argv[6], argv[7], env, stub);
			if (rc != 0) {
				printf("cc_bundleInstance() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "bundleRestartInstance")) {
			rc = cc_bundleRestartInstance(argv[3], env, stub);
			if (rc != 0) {
				printf("cc_bundleRestartInstance() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "createImage")) {
			rc = cc_createImage(argv[3], argv[4], argv[5], env, stub);
			if (rc != 0) {
				printf("cc_createImage() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "describePublicAddresses")) {
			rc = cc_describePublicAddresses(env, stub);
			if (rc != 0) {
				printf("cc_describePublicAddresses() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "killallInstances")) {
			rc = cc_killallInstances(env, stub);
			if (rc != 0) {
				printf("cc_killallInstances() failed\n");
				exit(1);
			}
		} else if (!strcmp(argv[2], "describeSensors")) {
			sensorResource ** res;
			int resSize;

			rc = cc_describeSensors(10, 5000, NULL, 0, NULL, 0, &res, &resSize, env, stub);
			if (rc != 0) {
				printf("cc_describeSensors() failed: error=%d\n", rc);
				exit(1);
			}
			char buf [40960];
			sensor_res2str (buf, sizeof(buf), res, resSize);
			printf ("resources: %d\n%s\n", resSize, buf);
		} else {
			printf("unrecognized operation '%s'\n", argv[2]);
			exit(1);
		}
	}

	exit(0);
}