static ncInstance * copy_instance_from_adb (adb_instanceType_t * instance, axutil_env_t * env) { int i; adb_virtualMachineType_t * vm_type = adb_instanceType_get_instanceType(instance, env); virtualMachine params; copy_vm_type_from_adb (¶ms, vm_type, env); netConfig ncnet; bzero(&ncnet, sizeof(netConfig)); adb_netConfigType_t * netconf = adb_instanceType_get_netParams(instance, env); if (netconf != NULL) { ncnet.vlan = adb_netConfigType_get_vlan(netconf, env); ncnet.networkIndex = adb_netConfigType_get_networkIndex(netconf, env); strncpy(ncnet.privateMac, adb_netConfigType_get_privateMacAddress(netconf, env), 24); strncpy(ncnet.privateIp, adb_netConfigType_get_privateIp(netconf, env), 24); strncpy(ncnet.publicIp, adb_netConfigType_get_publicIp(netconf, env), 24); } int groupNamesSize = adb_instanceType_sizeof_groupNames (instance, env); char * groupNames [EUCA_MAX_GROUPS]; for (i = 0; i<EUCA_MAX_GROUPS && i<groupNamesSize; i++) { groupNames[i] = adb_instanceType_get_groupNames_at (instance, env, i); } ncInstance * outInst = allocate_instance( (char *)adb_instanceType_get_instanceId(instance, env), (char *)adb_instanceType_get_reservationId(instance, env), ¶ms, (char *)adb_instanceType_get_imageId(instance, env), NULL, // URL is NULL (char *)adb_instanceType_get_kernelId(instance, env), NULL, // URL is NULL (char *)adb_instanceType_get_ramdiskId(instance, env), NULL, // URL is NULL (char *)adb_instanceType_get_stateName(instance, env), 0, (char *)adb_instanceType_get_userId(instance, env), &ncnet, (char *)adb_instanceType_get_keyName(instance, env), (char *)adb_instanceType_get_userData(instance, env), (char *)adb_instanceType_get_launchIndex(instance, env), groupNames, groupNamesSize ); axutil_date_time_t * dt = adb_instanceType_get_launchTime(instance, env); if (dt!=NULL) { outInst->launchTime = datetime_to_unix (dt, env); axutil_date_time_free(dt, env); } outInst->volumesSize = adb_instanceType_sizeof_volumes (instance, env); if (outInst->volumesSize > 0) { for (i=0; i<EUCA_MAX_VOLUMES && i<outInst->volumesSize; i++) { adb_volumeType_t * volume = adb_instanceType_get_volumes_at (instance, env, i); strncpy (outInst->volumes[i].volumeId, adb_volumeType_get_volumeId (volume, env), CHAR_BUFFER_SIZE); strncpy (outInst->volumes[i].remoteDev, adb_volumeType_get_remoteDev (volume, env), CHAR_BUFFER_SIZE); strncpy (outInst->volumes[i].localDev, adb_volumeType_get_localDev (volume, env), CHAR_BUFFER_SIZE); strncpy (outInst->volumes[i].stateName, adb_volumeType_get_state (volume, env), CHAR_BUFFER_SIZE); } } return outInst; }
adb_RunInstancesResponse_t *RunInstancesMarshal(adb_RunInstances_t *runInstances, const axutil_env_t *env) { // output vars adb_RunInstancesResponse_t *ret=NULL; adb_runInstancesResponseType_t *rirt=NULL; // input vars adb_runInstancesType_t *rit=NULL; // working vars adb_ccInstanceType_t *it=NULL; adb_virtualMachineType_t *vm=NULL; ccInstance *outInsts=NULL, *myInstance=NULL; int minCount, maxCount, rc, outInstsLen, i, vlan, instIdsLen, netNamesLen, macAddrsLen, *networkIndexList=NULL, networkIndexListLen, uuidsLen, expiryTime; axis2_bool_t status=AXIS2_TRUE; char statusMessage[256]; char *emiId=NULL, *keyName=NULL, **instIds=NULL, *reservationId=NULL, **netNames=NULL, **macAddrs=NULL, *kernelId=NULL, *ramdiskId=NULL, *emiURL=NULL, *kernelURL=NULL, *ramdiskURL=NULL, *vmName=NULL, *userData=NULL, *launchIndex=NULL, *platform=NULL, *tmp=NULL, **uuids=NULL, *accountId=NULL, *ownerId=NULL; ncMetadata ccMeta; virtualMachine ccvm; axutil_date_time_t *dt=NULL; rit = adb_RunInstances_get_RunInstances(runInstances, env); EUCA_MESSAGE_UNMARSHAL(runInstancesType, rit, (&ccMeta)); reservationId = adb_runInstancesType_get_reservationId(rit, env); maxCount = adb_runInstancesType_get_maxCount(rit, env); minCount = adb_runInstancesType_get_minCount(rit, env); keyName = adb_runInstancesType_get_keyName(rit, env); emiId = adb_runInstancesType_get_imageId(rit, env); kernelId = adb_runInstancesType_get_kernelId(rit, env); ramdiskId = adb_runInstancesType_get_ramdiskId(rit, env); emiURL = adb_runInstancesType_get_imageURL(rit, env); kernelURL = adb_runInstancesType_get_kernelURL(rit, env); ramdiskURL = adb_runInstancesType_get_ramdiskURL(rit, env); tmp = adb_runInstancesType_get_userData(rit, env); if (!tmp) { userData = strdup(""); } else { userData = strdup(tmp); } launchIndex = adb_runInstancesType_get_launchIndex(rit, env); platform = adb_runInstancesType_get_platform(rit, env); dt = adb_runInstancesType_get_expiryTime(rit, env); expiryTime = datetime_to_unix(dt, env); vm = adb_runInstancesType_get_instanceType(rit, env); copy_vm_type_from_adb (&ccvm, vm, env); vmName = adb_virtualMachineType_get_name(vm, env); snprintf(ccvm.name, 64, "%s", vmName); vlan = adb_runInstancesType_get_vlan(rit, env); instIdsLen = adb_runInstancesType_sizeof_instanceIds(rit, env); instIds = malloc(sizeof(char *) * instIdsLen); for (i=0; i<instIdsLen; i++) { instIds[i] = adb_runInstancesType_get_instanceIds_at(rit, env, i); } netNamesLen = adb_runInstancesType_sizeof_netNames(rit, env); netNames = malloc(sizeof(char *) * netNamesLen); if (netNamesLen > 1) { netNamesLen = 1; } for (i=0; i<netNamesLen; i++) { netNames[i] = adb_runInstancesType_get_netNames_at(rit, env, i); } macAddrsLen = adb_runInstancesType_sizeof_macAddresses(rit, env); macAddrs = malloc(sizeof(char *) * macAddrsLen); for (i=0; i<macAddrsLen; i++) { macAddrs[i] = adb_runInstancesType_get_macAddresses_at(rit, env, i); } uuidsLen = adb_runInstancesType_sizeof_uuids(rit, env); uuids = malloc(sizeof(char *) * uuidsLen); for (i=0; i<uuidsLen; i++) { uuids[i] = adb_runInstancesType_get_uuids_at(rit, env, i); } networkIndexList = NULL; networkIndexListLen = adb_runInstancesType_sizeof_networkIndexList(rit, env); if (networkIndexListLen) { networkIndexList = malloc(sizeof(int) * networkIndexListLen); for (i=0; i<networkIndexListLen; i++) { networkIndexList[i] = adb_runInstancesType_get_networkIndexList_at(rit, env, i); } } accountId = adb_runInstancesType_get_accountId(rit, env); if (!accountId) { accountId = ccMeta.userId; } ownerId = adb_runInstancesType_get_ownerId(rit, env); if (!ownerId) { ownerId = accountId; } rirt = adb_runInstancesResponseType_create(env); rc=1; if (!DONOTHING) { rc = doRunInstances(&ccMeta, emiId, kernelId, ramdiskId, emiURL, kernelURL,ramdiskURL, instIds, instIdsLen, netNames, netNamesLen, macAddrs, macAddrsLen, networkIndexList, networkIndexListLen, uuids, uuidsLen, minCount, maxCount, accountId, ownerId, reservationId, &ccvm, keyName, vlan, userData, launchIndex, platform, expiryTime, NULL, &outInsts, &outInstsLen); } if (rc) { logprintf("ERROR: doRunInstances() failed %d\n", rc); status=AXIS2_FALSE; snprintf(statusMessage, 255, "ERROR"); } else { for (i=0; i<outInstsLen; i++) { myInstance = &(outInsts[i]); it = adb_ccInstanceType_create(env); myInstance->ccvm.virtualBootRecordLen = 0; rc = ccInstanceUnmarshal(it, myInstance, env); adb_runInstancesResponseType_add_instances(rirt, env, it); } if (outInsts) free(outInsts); } adb_runInstancesResponseType_set_correlationId(rirt, env, ccMeta.correlationId); adb_runInstancesResponseType_set_userId(rirt, env, ccMeta.userId); adb_runInstancesResponseType_set_return(rirt, env, status); if (status == AXIS2_FALSE) { adb_runInstancesResponseType_set_statusMessage(rirt, env, statusMessage); } ret = adb_RunInstancesResponse_create(env); adb_RunInstancesResponse_set_RunInstancesResponse(ret, env, rirt); free(networkIndexList); free(macAddrs); free(netNames); free(instIds); free(userData); if(uuids != NULL) free(uuids); return(ret); }