コード例 #1
0
//!
//! Initialize the NC state structure for the KVM hypervisor.
//!
//! @param[in] nc a pointer to the NC state structure to initialize
//!
//! @return Always return EUCA_OK
//!
static int doInitialize(struct nc_state_t *nc)
{
#define GET_VALUE(_name, _var)                                                                         \
{                                                                                                      \
	if (get_value (s, (_name), &(_var))) {                                                             \
		logprintfl (EUCAFATAL, "did not find %s in output from %s\n", (_name), nc->get_info_cmd_path); \
		EUCA_FREE(s);                                                                                  \
		return (EUCA_FATAL_ERROR);                                                                     \
	}                                                                                                  \
}

    char *s = NULL;

    // set up paths of Eucalyptus commands NC relies on
    snprintf(nc->get_info_cmd_path, MAX_PATH, EUCALYPTUS_GET_KVM_INFO, nc->home, nc->home);
    strcpy(nc->uri, HYPERVISOR_URI);
    nc->convert_to_disk = 1;
    nc->capability = HYPERVISOR_HARDWARE;   //! @todo indicate virtio support?

    s = system_output(nc->get_info_cmd_path);

    GET_VALUE("nr_cores", nc->cores_max);
    GET_VALUE("total_memory", nc->mem_max);
    EUCA_FREE(s);

    // we leave 256M to the host
    nc->mem_max -= 256;
    return (EUCA_OK);
}
コード例 #2
0
ファイル: handlers_kvm.c プロジェクト: donhall/shijiemori-dev
static int doInitialize (struct nc_state_t *nc) 
{
	char *s = NULL;
        
	// set up paths of Eucalyptus commands NC relies on
	snprintf (nc->get_info_cmd_path, MAX_PATH, EUCALYPTUS_GET_KVM_INFO,  nc->home, nc->home);
	strcpy(nc->uri, HYPERVISOR_URI);
	nc->convert_to_disk = 1;
    nc->capability = HYPERVISOR_HARDWARE; // TODO: indicate virtio support?

	s = system_output (nc->get_info_cmd_path);
#define GET_VALUE(name,var) \
	if (get_value (s, name, &var)) { \
		logprintfl (EUCAFATAL, "error: did not find %s in output from %s\n", name, nc->get_info_cmd_path); \
		if (s) free (s); \
		return ERROR_FATAL; \
	}

	GET_VALUE("nr_cores", nc->cores_max);
	GET_VALUE("total_memory", nc->mem_max);
	if (s) free(s);

	// we leave 256M to the host
	nc->mem_max -= 256;

	return OK;
}
コード例 #3
0
ファイル: handlers.c プロジェクト: 1ukash/eucalyptus-fork-2.0
int
get_instance_xml(	const char *gen_libvirt_cmd_path,
			char *userId,
			char *instanceId,
			char *ramdiskId,
			char *kernelId,
			char *disk_path,
			virtualMachine *params,
			char *privMac,
			//			char *privIp,
			char *brname,
			int use_virtio_net,
			int use_virtio_root,
			char **xml)
{
    char buf [MAX_PATH];

    snprintf(buf, MAX_PATH, "%s", gen_libvirt_cmd_path);

// We should pass instance path parameter to perl script to determine file system type.
// It will help to make right suggestion about used OS and generate libvirt for it.
    strncat(buf, " --instance-path ", MAX_PATH);
    strncat(buf, disk_path, MAX_PATH);


    if (strnlen(ramdiskId, CHAR_BUFFER_SIZE)) {
        strncat(buf, " --ramdisk", MAX_PATH - strlen(buf) - 1);
    }
    if (use_virtio_net) {
        strncat(buf, " --virtionet", MAX_PATH - strlen(buf) - 1);
    }
    if (use_virtio_root) {
        strncat(buf, " --virtioroot", MAX_PATH - strlen(buf) - 1);
    }
    
    if (params->disk > 0) { /* TODO: get this info from scMakeImage */
        strncat (buf, " --ephemeral", MAX_PATH - strlen(buf) - 1);
    }
    * xml = system_output (buf);
    if ( ( * xml ) == NULL ) {
        logprintfl (EUCAFATAL, "%s: %s\n", gen_libvirt_cmd_path, strerror (errno));
        return ERROR;
    }
    
    /* the tags better be not substring of other tags: BA will substitute
     * ABABABAB */
    replace_string (xml, "BASEPATH", disk_path);
    replace_string (xml, "SWAPPATH", disk_path);
    replace_string (xml, "NAME", instanceId);
    replace_string (xml, "PRIVMACADDR", privMac);
    //    replace_string (xml, "PUBMACADDR", pubMac);
    replace_string (xml, "BRIDGEDEV", brname);
    snprintf(buf, CHAR_BUFFER_SIZE, "%d", params->mem * 1024); /* because libvirt wants memory in Kb, while we use Mb */
    replace_string (xml, "MEMORY", buf);
    snprintf(buf, CHAR_BUFFER_SIZE, "%d", params->cores);
    replace_string (xml, "VCPUS", buf);
    
    return 0;
}
コード例 #4
0
static int doInitialize (struct nc_state_t *nc) 
{
	char *s = NULL;
	virNodeInfo ni;
	long long dom0_min_mem;

	logprintfl(EUCADEBUG, "doInitialized() invoked\n");

	/* set up paths of Eucalyptus commands NC relies on */
	snprintf (nc->gen_libvirt_cmd_path, MAX_PATH, EUCALYPTUS_GEN_LIBVIRT_XML, nc->home, nc->home);
	snprintf (nc->get_info_cmd_path, MAX_PATH, EUCALYPTUS_GET_XEN_INFO, nc->home, nc->home);
	snprintf (nc->virsh_cmd_path, MAX_PATH, EUCALYPTUS_VIRSH, nc->home);
	snprintf (nc->xm_cmd_path, MAX_PATH, EUCALYPTUS_XM);
	snprintf (nc->detach_cmd_path, MAX_PATH, EUCALYPTUS_DETACH, nc->home, nc->home);
    snprintf (nc->connect_storage_cmd_path, MAX_PATH, EUCALYPTUS_CONNECT_ISCSI, nc->home, nc->home);
    snprintf (nc->disconnect_storage_cmd_path, MAX_PATH, EUCALYPTUS_DISCONNECT_ISCSI, nc->home, nc->home);
    snprintf (nc->get_storage_cmd_path, MAX_PATH, EUCALYPTUS_GET_ISCSI, nc->home, nc->home);
	strcpy(nc->uri, HYPERVISOR_URI);
	nc->convert_to_disk = 0;

        /* check connection is fresh */
        if (!check_hypervisor_conn()) {
          return ERROR_FATAL;
	}

	/* get resources */
	if (virNodeGetInfo(nc->conn, &ni)) {
		logprintfl (EUCAFATAL, "error: failed to discover resources\n");
		return ERROR_FATAL;
	}

	/* dom0-min-mem has to come from xend config file */
	s = system_output (nc->get_info_cmd_path);
	if (get_value (s, "dom0-min-mem", &dom0_min_mem)) {
		logprintfl (EUCAFATAL, "error: did not find dom0-min-mem in output from %s\n", nc->get_info_cmd_path);
		free (s);
		return ERROR_FATAL;
	}
	free (s);

	/* calculate the available memory */
	nc->mem_max = ni.memory/1024 - 32 - dom0_min_mem;

	/* calculate the available cores */
	nc->cores_max = ni.cpus;

	/* let's adjust the values based on the config values */
	if (nc->config_max_mem && nc->config_max_mem < nc->mem_max)
		nc->mem_max = nc->config_max_mem;
	if (nc->config_max_cores)
		nc->cores_max = nc->config_max_cores;

	logprintfl(EUCAINFO, "Using %lld cores\n", nc->cores_max);
	logprintfl(EUCAINFO, "Using %lld memory\n", nc->mem_max);

	return OK;
}
コード例 #5
0
ファイル: handlers.c プロジェクト: Shebella/HIPPO
char* get_iscsi_target(const char *storage_cmd_path, char *dev_string) {
    char buf [MAX_PATH];
    char *retval;
    
    snprintf (buf, MAX_PATH, "%s %s", storage_cmd_path, dev_string);
    logprintfl (EUCAINFO, "get_iscsi_target invoked (dev_string=%s)\n", dev_string);
    if ((retval = system_output(buf)) == NULL) {
	logprintfl (EUCAERROR, "ERROR: get_iscsi_target failed\n");
    } else {
	logprintfl (EUCAINFO, "Device: %s\n", retval);
    } 
    return retval;
}
コード例 #6
0
ファイル: test.c プロジェクト: gcloudpaulwang/eucalyptus
void test_command (char * command)
{
    char * result = system_output(command);
    int max = 160;

    if (result && strlen(result)>max) {
        result[max-4] = '.';
        result[max-3] = '.';
        result[max-2] = '.';
        result[max-1] = 0;
    }
    printf("--->%s executed\noutput=[%s]\n\n", command, result);
    free (result);
}
コード例 #7
0
ファイル: handlers_xen.c プロジェクト: appliedcode/eucalyptus
static int doInitialize (struct nc_state_t *nc) 
{
	char *s = NULL;
	virNodeInfo ni;
	long long dom0_min_mem;

	// set up paths of Eucalyptus commands NC relies on
	snprintf (nc->get_info_cmd_path, MAX_PATH, EUCALYPTUS_GET_XEN_INFO, nc->home, nc->home);
	snprintf (nc->virsh_cmd_path, MAX_PATH, EUCALYPTUS_VIRSH, nc->home);
	snprintf (nc->xm_cmd_path, MAX_PATH, EUCALYPTUS_XM);
	snprintf (nc->detach_cmd_path, MAX_PATH, EUCALYPTUS_DETACH, nc->home, nc->home);
	strcpy(nc->uri, HYPERVISOR_URI);
	nc->convert_to_disk = 0;
    nc->capability = HYPERVISOR_XEN_AND_HARDWARE; // TODO: set to XEN_PARAVIRTUALIZED if on older Xen kernel
    
    // check connection is fresh
    if (!check_hypervisor_conn()) {
        return ERROR_FATAL;
	}
    
	// get resources
	if (virNodeGetInfo(nc->conn, &ni)) {
		logprintfl (EUCAFATAL, "failed to discover resources\n");
		return ERROR_FATAL;
	}

	// dom0-min-mem has to come from xend config file
	s = system_output (nc->get_info_cmd_path);
	if (get_value (s, "dom0-min-mem", &dom0_min_mem)) {
		logprintfl (EUCAFATAL, "did not find dom0-min-mem in output from %s\n", nc->get_info_cmd_path);
		free (s);
		return ERROR_FATAL;
	}
	free (s);

	// calculate the available memory
	nc->mem_max = ni.memory/1024 - 32 - dom0_min_mem;

	// calculate the available cores
	nc->cores_max = ni.cpus;

	// let's adjust the values based on the config values
	if (nc->config_max_mem && nc->config_max_mem < nc->mem_max)
		nc->mem_max = nc->config_max_mem;
	if (nc->config_max_cores)
		nc->cores_max = nc->config_max_cores;

	return OK;
}
コード例 #8
0
void testCommand(const std::string& arguments,
                 int expectedReturnCode,
                 const T& expectedOutput) {
    CommandOutput out = system_output(COMMAND + " " + arguments);

    checkCommandOutput(arguments, out.output, expectedOutput);

    const bool returnCodeIsCorrect = (out.returncode == expectedReturnCode);
    if (!returnCodeIsCorrect) {
        std::string msg = "When testing arguments '" + arguments +
            "' got return code '" + std::to_string(out.returncode) +
            "' but expected '" + std::to_string(expectedReturnCode) + "'.";
        throw std::runtime_error(msg);
    }
}
コード例 #9
0
char *find_local_iqn(void){
    char *ptr = NULL, *iqn = NULL, *tmp = NULL;
    ptr = system_output("cat /etc/iscsi/initiatorname.iscsi");
    if (ptr) {
        iqn = strstr(ptr, "InitiatorName=");
        if (iqn) {
            iqn += strlen("InitiatorName=");
            tmp = strstr(iqn, "\n");
            if (tmp)
                *tmp = '\0';
        }
        ptr = NULL;
    }

    return iqn;
}
コード例 #10
0
ファイル: iscsi.c プロジェクト: EucalyptusSystems/eucalyptus
char * get_iscsi_target (const char *dev_string) 
{
    char buf [MAX_PATH];
    char *retval=NULL;
    int pid, status, rc, len, rbytes, filedes[2];
    assert (strlen (home));
    
    snprintf (buf, MAX_PATH, "%s %s,%s", get_storage_cmd_path, home, dev_string);
    logprintfl (EUCAINFO, "get_iscsi_target invoked (dev_string=%s)\n", dev_string);
    
    rc = pipe(filedes);
    if (rc) {
        logprintfl(EUCAERROR, "get_iscsi_target: cannot create pipe\n");
        return(NULL);
    }
    
    sem_p (iscsi_sem);
    pid = fork();
    if (!pid) {
        close(filedes[0]);

        if (strlen(buf)) logprintfl(EUCADEBUG, "get_iscsi_target(): running command: %s\n", buf);

        if ((retval = system_output(buf)) == NULL) {
            logprintfl (EUCAERROR, "ERROR: get_iscsi_target failed\n");
            len = 0;
        } else {
            logprintfl (EUCAINFO, "Device: %s\n", retval);
            len = strlen(retval);
        } 
        rc = write(filedes[1], &len, sizeof(int));
        if (retval) {
            rc = write(filedes[1], retval, sizeof(char) * len);
        }
        close(filedes[1]);

        if (rc == len) {
            exit(0);
        }
        exit(1);
        
    } else {
        close(filedes[1]);
        
        rbytes = timeread(filedes[0], &len, sizeof(int), 90);
        if (rbytes <= 0) {
            kill(pid, SIGKILL);
        } else {
            retval = malloc(sizeof(char) * (len+1));
            bzero(retval, len+1);
            rbytes = timeread(filedes[0], retval, len, 90);
            if (rbytes <= 0) {
                kill(pid, SIGKILL);
            }
        }
        close(filedes[0]);

        rc = timewait(pid, &status, 90);
        if (rc) {
            rc = WEXITSTATUS(status);
        } else {
            kill(pid, SIGKILL);
        }
    }
    sem_v (iscsi_sem);

    return retval;
}