コード例 #1
0
//!
//! Handles the client describe instance request.
//!
//! @param[in]  pStub a pointer to the node controller (NC) stub structure
//! @param[in]  pMeta a pointer to the node controller (NC) metadata structure
//! @param[in]  instIds a pointer the list of instance identifiers to retrieve data for
//! @param[in]  instIdsLen the number of instance identifiers in the instIds list
//! @param[out] outInsts a pointer the list of instances for which we have data
//! @param[out] outInstsLen the number of instances in the outInsts list.
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure.
//!
int ncDescribeInstancesStub(ncStub * pStub, ncMetadata * pMeta, char **instIds, int instIdsLen, ncInstance *** outInsts, int *outInstsLen)
{
    int i = 0;
    int numinsts = 0;
    ncInstance *newinst = NULL;

    LOGDEBUG("fakeNC: describeInstances(): params: instIdsLen=%d\n", instIdsLen);

    if (instIdsLen < 0) {
        LOGERROR("fakeNC: describeInstances(): bad input params\n");
        return (EUCA_ERROR);
    }

    loadNcStuff();

    //  *outInstsLen = myconfig->instanceidx+1;
    *outInsts = EUCA_ZALLOC(MAX_FAKE_INSTANCES, sizeof(ncInstance *));
    for (i = 0; i < MAX_FAKE_INSTANCES; i++) {
        if (strlen(myconfig->global_instances[i].instanceId)) {
            newinst = EUCA_ZALLOC(1, sizeof(ncInstance));
            if (!strcmp(myconfig->global_instances[i].stateName, "Pending")) {
                snprintf(myconfig->global_instances[i].stateName, 8, "Extant");
            }

            memcpy(newinst, &(myconfig->global_instances[i]), sizeof(ncInstance));
            (*outInsts)[numinsts] = newinst;
            LOGDEBUG("fakeNC: describeInstances(): idx=%d numinsts=%d instanceId=%s stateName=%s\n", i, numinsts, newinst->instanceId, newinst->stateName);
            numinsts++;
        }
    }
    *outInstsLen = numinsts;

    saveNcStuff();
    return (EUCA_OK);
}
コード例 #2
0
//!
//! Handle the client describe resource request
//!
//! @param[in]  pStub a pointer to the node controller (NC) stub structure
//! @param[in]  pMeta a pointer to the node controller (NC) metadata structure
//! @param[in]  resourceType UNUSED
//! @param[out] outRes a list of resources we retrieved data for
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure.
//!
int ncDescribeResourceStub(ncStub * pStub, ncMetadata * pMeta, char *resourceType, ncResource ** outRes)
{
    int ret = EUCA_OK;
    ncResource *res = NULL;

    loadNcStuff();

    if (myconfig->res.memorySizeMax <= 0) {
        // not initialized?
        res = allocate_resource("OK", "iqn.1993-08.org.debian:01:736a4e92c588", 1024000, 1024000, 30000000, 30000000, 4096, 4096, "none");
        if (!res) {
            LOGERROR("fakeNC: describeResource(): failed to allocate fake resource\n");
            ret = EUCA_ERROR;
        } else {
            memcpy(&(myconfig->res), res, sizeof(ncResource));
            EUCA_FREE(res);
        }
    }

    if (!ret) {
        res = EUCA_ALLOC(1, sizeof(ncResource));
        memcpy(res, &(myconfig->res), sizeof(ncResource));
        *outRes = res;
    } else {
        *outRes = NULL;
    }

    saveNcStuff();
    return (ret);
}
コード例 #3
0
int ncDetachVolumeStub (ncStub *stub, ncMetadata *meta, char *instanceId, char *volumeId, char *remoteDev, char *localDev, int force)
{
  int i, j, done=0, vdone=0, foundidx=-1;

  logprintfl(EUCADEBUG, "fakeNC:  detachVolume(): params: instanceId=%s volumeId=%s remoteDev=%s localDev=%s\n", SP(instanceId), SP(volumeId), SP(remoteDev), SP(localDev));
  if (!instanceId || !volumeId || !remoteDev || !localDev) {
    logprintfl(EUCADEBUG, "fakeNC:  detachVolume(): bad input params\n");
    return(0);
  }

  loadNcStuff();

  for (i=0; i<MAX_FAKE_INSTANCES && !done; i++) {
    if (!strcmp(myconfig->global_instances[i].instanceId, instanceId)) {
      logprintfl(EUCADEBUG, "fakeNC: \tsetting volume info at idx %d\n", i);
      vdone=0;
      for (j=0; j<EUCA_MAX_VOLUMES; j++) {
	if (!strcmp(myconfig->global_instances[i].volumes[j].volumeId, volumeId)) {
	  foundidx=j;
	}
      }
      if (foundidx >= 0) {
	logprintfl(EUCADEBUG, "fakeNC: \tfake detaching volume at idx %d\n", foundidx);
	snprintf(myconfig->global_instances[i].volumes[foundidx].stateName, CHAR_BUFFER_SIZE, "%s", "detached");
      }
      done++;
    }
  }

  saveNcStuff();
  return (0);
}
コード例 #4
0
//!
//! Handles the Terminate instance request
//!
//! @param[in]  pStub a pointer to the node controller (NC) stub structure
//! @param[in]  pMeta a pointer to the node controller (NC) metadata structure
//! @param[in]  instanceId the instance identifier string (i-XXXXXXXX)
//! @param[in]  force if set to 1 will force the termination of the instance
//! @param[out] shutdownState the instance state code after the call to find_and_terminate_instance() if successful
//! @param[out] previousState the instance state code after the call to find_and_terminate_instance() if successful
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure.
//!
int ncTerminateInstanceStub(ncStub * pStub, ncMetadata * pMeta, char *instanceId, int force, int *shutdownState, int *previousState)
{
    int i = 0;
    int done = 0;

    LOGDEBUG("fakeNC: terminateInstance(): params: instanceId=%s force=%d\n", SP(instanceId), force);

    if (!instanceId) {
        LOGERROR("fakeNC: termianteInstance(): bad input params\n");
        return (EUCA_ERROR);
    }

    loadNcStuff();

    for (i = 0; i < MAX_FAKE_INSTANCES && !done; i++) {
        if (!strcmp(myconfig->global_instances[i].instanceId, instanceId)) {
            LOGDEBUG("fakeNC: terminateInstance():\tsetting stateName for instance %s at idx %d\n", instanceId, i);
            snprintf(myconfig->global_instances[i].stateName, 10, "Teardown");
            myconfig->res.memorySizeAvailable += myconfig->global_instances[i].params.mem;
            myconfig->res.numberOfCoresAvailable += myconfig->global_instances[i].params.cores;
            myconfig->res.diskSizeAvailable += myconfig->global_instances[i].params.disk;
            done++;
        }
    }

    if (shutdownState && previousState) {
        *shutdownState = *previousState = 0;
    }

    saveNcStuff();
    return (EUCA_OK);
}
コード例 #5
0
int ncDescribeResourceStub (ncStub *st, ncMetadata *meta, char *resourceType, ncResource **outRes)
{
  int ret=0;
  ncResource *res;

  loadNcStuff();
  
  if (myconfig->res.memorySizeMax <= 0) {
    // not initialized?
    res = allocate_resource ("OK", "iqn.1993-08.org.debian:01:736a4e92c588", 1024000, 1024000, 30000000, 30000000, 4096, 4096, "none");
    if (!res) {
      logprintfl(EUCAERROR, "fakeNC: describeResource(): failed to allocate fake resource\n");
      ret=1;
    } else {
      memcpy(&(myconfig->res), res, sizeof(ncResource));
      free(res);
    }
  }
  
  if (!ret) {
    res = malloc(sizeof(ncResource));
    memcpy(res, &(myconfig->res), sizeof(ncResource));
    *outRes = res;
  } else {
    *outRes = NULL;
  }
  
  saveNcStuff();
  return(ret);
}
コード例 #6
0
int ncDescribeInstancesStub (ncStub *st, ncMetadata *meta, char **instIds, int instIdsLen, ncInstance ***outInsts, int *outInstsLen)
{
  int i, numinsts=0;
  logprintfl(EUCADEBUG, "fakeNC: describeInstances(): params: instIdsLen=%d\n", instIdsLen);
  
  if (instIdsLen < 0) {
    logprintfl(EUCAERROR, "fakeNC: describeInstances(): bad input params\n");
    return(0);
  }
  
  loadNcStuff();

  //  *outInstsLen = myconfig->instanceidx+1;
  *outInsts = malloc (sizeof(ncInstance *) * MAX_FAKE_INSTANCES);
  for (i=0; i<MAX_FAKE_INSTANCES; i++) {
    if (strlen(myconfig->global_instances[i].instanceId)) {
      ncInstance *newinst;
      newinst = malloc(sizeof(ncInstance));
      if (!strcmp(myconfig->global_instances[i].stateName, "Pending")) {
	snprintf(myconfig->global_instances[i].stateName, 8, "Extant");
      }
      memcpy(newinst, &(myconfig->global_instances[i]), sizeof(ncInstance));
      (* outInsts)[numinsts] = newinst;
      logprintfl(EUCADEBUG, "fakeNC: describeInstances(): idx=%d numinsts=%d instanceId=%s stateName=%s\n", i, numinsts, newinst->instanceId, newinst->stateName);
      numinsts++;
    }
  }
  *outInstsLen = numinsts;
  
  saveNcStuff();
  return(0);
}
コード例 #7
0
int ncRunInstanceStub (ncStub *st, ncMetadata *meta, char *uuid, char *instanceId, char *reservationId, virtualMachine *params, char *imageId, char *imageURL, char *kernelId, char *kernelURL, char *ramdiskId, char *ramdiskURL, char *ownerId, char *accountId, char *keyName, netConfig *netparams, char *userData, char *launchIndex, char *platform, int expiryTime, char **groupNames, int groupNamesSize, ncInstance **outInstPtr)
{
  ncInstance *instance;
  int i, j, foundidx=-1;

  logprintfl(EUCADEBUG, "fakeNC: runInstance(): params: uuid=%s instanceId=%s reservationId=%s ownerId=%s accountId=%s platform=%s\n", SP(uuid), SP(instanceId), SP(reservationId), SP(ownerId), SP(accountId), SP(platform));

  if (!uuid || !instanceId || !reservationId || !ownerId || !accountId || !platform || !meta || !netparams) {
    logprintfl(EUCAERROR, "fakeNC: runInstance(): bad input params\n");
    return(0);
  }

  loadNcStuff();

  instance = allocate_instance (uuid,
				instanceId, 
				reservationId,
				params, 
				instance_state_names[PENDING], 
				PENDING, 
				meta->userId, 
				ownerId, accountId,
				netparams, keyName,
				userData, launchIndex, platform, expiryTime, groupNames, groupNamesSize);
  if (instance) {
    instance->launchTime = time (NULL);
    foundidx=-1;
    for (i=0; i<MAX_FAKE_INSTANCES && (foundidx < 0); i++) {
      if (!strlen(myconfig->global_instances[i].instanceId)) {
	foundidx = i;
      }
    }
    memcpy( &(myconfig->global_instances[foundidx]),instance, sizeof(ncInstance));
    logprintfl(EUCADEBUG, "fakeNC: runInstance(): decrementing resource by %d/%d/%d\n", params->cores, params->mem, params->disk);
    myconfig->res.memorySizeAvailable -= params->mem;
    myconfig->res.numberOfCoresAvailable -= params->cores;
    myconfig->res.diskSizeAvailable -= params->disk;
    
    *outInstPtr = instance;
    logprintfl(EUCADEBUG, "fakeNC: runInstance(): allocated and stored instance\n");
  } else {
    logprintfl(EUCAERROR, "fakeNC: runInstance(): failed to allocate instance\n");
  }
  
  saveNcStuff();
  return(0);
}
コード例 #8
0
//!
//! Handles the client attach volume request.
//!
//! @param[in] pStub a pointer to the node controller (NC) stub structure
//! @param[in] pMeta a pointer to the node controller (NC) metadata structure
//! @param[in] instanceId the instance identifier string (i-XXXXXXXX)
//! @param[in] volumeId the volume identifier string (vol-XXXXXXXX)
//! @param[in] remoteDev the target device name
//! @param[in] localDev the local device name
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure.
//!
int ncAttachVolumeStub(ncStub * pStub, ncMetadata * pMeta, char *instanceId, char *volumeId, char *remoteDev, char *localDev)
{
    int i = 0;
    int j = 0;
    int done = 0;
    int vdone = 0;
    int foundidx = -1;

    LOGDEBUG("fakeNC:  attachVolume(): params: instanceId=%s volumeId=%s remoteDev=%s localDev=%s\n", SP(instanceId), SP(volumeId), SP(remoteDev), SP(localDev));
    if (!instanceId || !volumeId || !remoteDev || !localDev) {
        LOGDEBUG("fakeNC:  attachVolume(): bad input params\n");
        return (EUCA_ERROR);
    }

    loadNcStuff();

    for (i = 0; i < MAX_FAKE_INSTANCES && !done; i++) {
        if (!strcmp(myconfig->global_instances[i].instanceId, instanceId)) {
            LOGDEBUG("fakeNC: \tsetting volume info at idx %d\n", i);
            vdone = 0;
            for (j = 0; j < EUCA_MAX_VOLUMES; j++) {
                if (!strlen(myconfig->global_instances[i].volumes[j].volumeId)) {
                    if (foundidx < 0) {
                        foundidx = j;
                    }
                } else if (!strcmp(myconfig->global_instances[i].volumes[j].volumeId, volumeId)) {
                    vdone++;
                }
            }
            if (!vdone && foundidx >= 0) {
                LOGDEBUG("fakeNC: \tfake attaching volume at idx %d\n", foundidx);
                snprintf(myconfig->global_instances[i].volumes[foundidx].volumeId, CHAR_BUFFER_SIZE, "%s", volumeId);
                snprintf(myconfig->global_instances[i].volumes[foundidx].remoteDev, CHAR_BUFFER_SIZE, "%s", remoteDev);
                snprintf(myconfig->global_instances[i].volumes[foundidx].localDev, CHAR_BUFFER_SIZE, "%s", localDev);
                snprintf(myconfig->global_instances[i].volumes[foundidx].localDevReal, CHAR_BUFFER_SIZE, "%s", localDev);
                snprintf(myconfig->global_instances[i].volumes[foundidx].stateName, CHAR_BUFFER_SIZE, "%s", "attached");
            }
            done++;
        }
    }

    saveNcStuff();
    return (EUCA_OK);
}
コード例 #9
0
int ncAssignAddressStub (ncStub *st, ncMetadata *meta, char *instanceId, char *publicIp){
  int i, done=0;

  logprintfl(EUCADEBUG, "fakeNC: assignAddress(): params: instanceId=%s publicIp=%s\n", SP(instanceId), SP(publicIp));
  if (!instanceId || !publicIp) {
    logprintfl(EUCADEBUG, "fakeNC: assignAddress(): bad input params\n");
    return(0);
  }

  loadNcStuff();

  for (i=0; i<MAX_FAKE_INSTANCES && !done; i++) {
    if (!strcmp(myconfig->global_instances[i].instanceId, instanceId)) {
      logprintfl(EUCADEBUG, "fakeNC: assignAddress()\tsetting publicIp at idx %d\n", i);
      snprintf(myconfig->global_instances[i].ncnet.publicIp, 24, "%s", publicIp);
      done++;
    }
  }
  
  saveNcStuff();
  return(0);
}
コード例 #10
0
//!
//! Handles the client assign address request.
//!
//! @param[in] pStub a pointer to the node controller (NC) stub structure
//! @param[in] pMeta a pointer to the node controller (NC) metadata structure
//! @param[in] instanceId the instance identifier string (i-XXXXXXXX)
//! @param[in] publicIp a string representation of the public IP to assign to the instance
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure.
//!
int ncAssignAddressStub(ncStub * pStub, ncMetadata * pMeta, char *instanceId, char *publicIp)
{
    int i = 0;
    int done = 0;

    LOGDEBUG("fakeNC: assignAddress(): params: instanceId=%s publicIp=%s\n", SP(instanceId), SP(publicIp));
    if (!instanceId || !publicIp) {
        LOGDEBUG("fakeNC: assignAddress(): bad input params\n");
        return (EUCA_ERROR);
    }

    loadNcStuff();

    for (i = 0; i < MAX_FAKE_INSTANCES && !done; i++) {
        if (!strcmp(myconfig->global_instances[i].instanceId, instanceId)) {
            LOGDEBUG("fakeNC: assignAddress()\tsetting publicIp at idx %d\n", i);
            snprintf(myconfig->global_instances[i].ncnet.publicIp, IP_BUFFER_SIZE, "%s", publicIp);
            done++;
        }
    }

    saveNcStuff();
    return (EUCA_OK);
}