コード例 #1
0
NetInterfaces::NetInterfaces(
        QWidget *parent,
        virConnectPtr conn) :
    _QWidget(parent, conn)
{
    typeLabel = new QLabel("Type:", this);
    type = new QComboBox(this);
    connType = QString(virConnectGetType(currWorkConnection)).toLower();
    if ( connType=="lxc" ) {
        type->addItems(LXC_NET_TYPES);
    } else if ( connType=="qemu" ) {
        type->addItems(QEMU_NET_TYPES);
    } else if ( connType=="xen" ) {
        type->addItems(XEN_NET_TYPES);
    };
    typeLayout = new QHBoxLayout(this);
    typeLayout->addWidget(typeLabel);
    typeLayout->addWidget(type);
    typeWdg = new QWidget(this);
    typeWdg->setLayout(typeLayout);

    info = new QStackedWidget(this);
    for (int i=0; i<type->count(); i++) {
        setWidgets(type->itemText(i).toLower());
    };

    commonLayout = new QVBoxLayout(this);
    commonLayout->addWidget(typeWdg);
    commonLayout->addWidget(info);
    commonLayout->addStretch(-1);
    setLayout(commonLayout);
    connect(type, SIGNAL(currentIndexChanged(int)),
            info, SLOT(setCurrentIndex(int)));
}
コード例 #2
0
HostDevice::HostDevice(QWidget *parent, virConnectPtr *connPtrPtr) :
    _QWidget(parent, connPtrPtr)
{
    type = new QComboBox(this);
    info = new QStackedWidget(this);
    QString connType = QString(virConnectGetType(*ptr_ConnPtr)).toLower();
    if ( connType=="qemu" ) {
        type->addItems(QEMU_DEV_LIST);
        info->addWidget(new USB_Host_Device(this, ptr_ConnPtr));
        info->addWidget(new PCI_Host_Device(this, ptr_ConnPtr));
        info->addWidget(new SCSI_Host_Device(this, ptr_ConnPtr));
    } else if ( connType=="lxc" ) {
        type->addItems(LXC_DEV_LIST);
        info->addWidget(new USB_Host_Device(this, ptr_ConnPtr));
        info->addWidget(new BCh_Host_Device(this, ptr_ConnPtr));
    };
    /*
    info->addWidget(new USB_Host_Device(this, ptr_ConnPtr));
    info->addWidget(new PCI_Host_Device(this, ptr_ConnPtr));
    info->addWidget(new SCSI_Host_Device(this, ptr_ConnPtr));
    info->addWidget(new BCh_Host_Device(this, ptr_ConnPtr));
    type->addItem("USB Host Device");
    type->addItem("PCI Host Device");
    type->addItem("SCSI Host Device");
    type->addItem("Block/Char Host Device");
    */
    commonLayout = new QVBoxLayout(this);
    commonLayout->addWidget(type);
    commonLayout->addWidget(info);
    commonLayout->addStretch(-1);
    setLayout(commonLayout);
    connect(type, SIGNAL(currentIndexChanged(int)),
            info, SLOT(setCurrentIndex(int)));
}
コード例 #3
0
ファイル: check_libvirtd.c プロジェクト: rjuju/monitoringplug
int main (int argc, char **argv) {
    /* Local Vars */
    virConnectPtr   conn;
    const char      *hvType;
    unsigned long libVer, libMajor, libMinor, libRelease;
    unsigned long hvVer, hvMajor, hvMinor, hvRelease;

    /* Set signal handling and alarm */
    if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR)
        critical("Setup SIGALRM trap failed!");

    /* Process check arguments */
    if (process_arguments(argc, argv) != OK)
        unknown("Parsing arguments failed!");

    /* Start plugin timeout */
    alarm(mp_timeout);

    // PLUGIN CODE
    conn = virt_connect();

    hvType = virConnectGetType(conn);
    if (hvType == NULL) {
        if (mp_verbose > 0) {
            virt_showError(conn);
        }
        critical("Failed to get hypervisor type.");
    }

    if (virConnectGetVersion(conn, &hvVer) != 0) {
        if (mp_verbose > 0) {
            virt_showError(conn);
        }
        critical("Failed to get hypervisor version.");
    }

    if (virConnectGetLibVersion(conn, &libVer) != 0) {
        if (mp_verbose > 0) {
            virt_showError(conn);
        }
        critical("Failed to get library version.");
    }

    virConnectClose(conn);

    hvMajor = hvVer / 1000000;
    hvVer %= 1000000;
    hvMinor = hvVer / 1000;
    hvRelease = hvVer % 1000;

    libMajor = libVer / 1000000;
    libVer %= 1000000;
    libMinor = libVer / 1000;
    libRelease = libVer % 1000;

    /* Output and return */
    ok("libvirtd: v.%lu.%lu.%lu Hypervisor: %s (v.%lu.%lu.%lu)", 
            libMajor, libMinor, libRelease,
            hvType, hvMajor, hvMinor, hvRelease);
}
コード例 #4
0
HostDevice_Edit::HostDevice_Edit(
        QWidget *parent, virConnectPtr *connPtrPtr) :
    HostDevice(parent, connPtrPtr)
{
    info->setVisible(false);
    infoEdit = new QStackedWidget(this);
    QString connType;
    if ( NULL!=ptr_ConnPtr && NULL!=*ptr_ConnPtr ) {
        connType = QString(virConnectGetType(*ptr_ConnPtr)).toLower();
    } else
        emit ptrIsNull();
    if ( connType=="qemu" ) {
        infoEdit->addWidget(new USB_Host_Device_Edit(this));
        infoEdit->addWidget(new PCI_Host_Device_Edit(this));
        infoEdit->addWidget(new SCSI_Host_Device_Edit(this, ptr_ConnPtr));
    } else if ( connType=="lxc" ) {
        infoEdit->addWidget(new USB_Host_Device_Edit(this));
        infoEdit->addWidget(new BCh_Host_Device_Edit(this));
    };
    commonLayout->insertWidget(2, infoEdit);
    connect(type, SIGNAL(currentIndexChanged(int)),
            infoEdit, SLOT(setCurrentIndex(int)));
    for (int i=0; i<infoEdit->count(); i++) {
        connect(infoEdit->widget(i), SIGNAL(dataChanged()),
                this, SLOT(stateChanged()));
    };
}
コード例 #5
0
void set_instances_class_name(CMPIInstance **list, 
                              virConnectPtr conn,
                              char *classname)
{
        int i;
        char *name;
        const char *type;
        char *prefix;

        type = virConnectGetType(conn);
        if (!type)
                prefix = "ERROR";
        else if (strstr(type, "Xen") == type)
                prefix = "Xen";
        else if (strstr(type, "qemu") == type) /* FIXME */
                prefix = "KVM";
        else
                prefix = "UNKNOWN";

        if (asprintf(&name, "%s_%s", prefix, classname) < 0)
                return;

        for (i = 0; list[i] != NULL; i++)
                set_instance_class_name(list[i], name);

        free(name);
}
コード例 #6
0
ファイル: node_device_driver.c プロジェクト: 6WIND/libvirt
virNodeDevicePtr
nodeDeviceCreateXML(virConnectPtr conn,
                    const char *xmlDesc,
                    unsigned int flags)
{
    virNodeDeviceDriverStatePtr driver = conn->nodeDevicePrivateData;
    virNodeDeviceDefPtr def = NULL;
    char *wwnn = NULL, *wwpn = NULL;
    int parent_host = -1;
    virNodeDevicePtr dev = NULL;
    const char *virt_type = NULL;

    virCheckFlags(0, NULL);
    virt_type  = virConnectGetType(conn);

    nodeDeviceLock(driver);

    def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt_type);
    if (def == NULL) {
        goto cleanup;
    }

    if (virNodeDeviceCreateXMLEnsureACL(conn, def) < 0)
        goto cleanup;

    if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) {
        goto cleanup;
    }

    if (virNodeDeviceGetParentHost(&driver->devs,
                                   def->name,
                                   def->parent,
                                   &parent_host) == -1) {
        goto cleanup;
    }

    if (virManageVport(parent_host,
                       wwpn,
                       wwnn,
                       VPORT_CREATE) == -1) {
        goto cleanup;
    }

    dev = find_new_device(conn, wwnn, wwpn);
    /* We don't check the return value, because one way or another,
     * we're returning what we get... */

    if (dev == NULL) {
        virReportError(VIR_ERR_NO_NODE_DEVICE, NULL);
    }

 cleanup:
    nodeDeviceUnlock(driver);
    virNodeDeviceDefFree(def);
    VIR_FREE(wwnn);
    VIR_FREE(wwpn);
    return dev;
}
コード例 #7
0
ファイル: vmrunner.c プロジェクト: MigNov/pvr
char *libvirtGetHypervisorType(char *uri)
{
	if (cp == NULL) {
		cp = libvirtConnect(uri);
		if (cp == NULL) {
			DPRINTF("Connection to %s failed\n", uri);
			return NULL;
		}
	}

	return (char *)virConnectGetType(cp);
}
コード例 #8
0
ファイル: node_device_driver.c プロジェクト: aruiz/libvirt
virNodeDevicePtr
nodeDeviceCreateXML(virConnectPtr conn,
                    const char *xmlDesc,
                    unsigned int flags)
{
    virNodeDeviceDefPtr def = NULL;
    char *wwnn = NULL, *wwpn = NULL;
    int parent_host = -1;
    virNodeDevicePtr dev = NULL;
    const char *virt_type = NULL;

    virCheckFlags(0, NULL);
    virt_type  = virConnectGetType(conn);

    nodeDeviceLock();

    if (!(def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt_type)))
        goto cleanup;

    if (virNodeDeviceCreateXMLEnsureACL(conn, def) < 0)
        goto cleanup;

    if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1)
        goto cleanup;

    if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def,
                                                     CREATE_DEVICE)) < 0)
        goto cleanup;

    if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0)
        goto cleanup;

    dev = nodeDeviceFindNewDevice(conn, wwnn, wwpn);
    /* We don't check the return value, because one way or another,
     * we're returning what we get... */

    if (dev == NULL)
        virReportError(VIR_ERR_NO_NODE_DEVICE,
                       _("no node device for '%s' with matching "
                         "wwnn '%s' and wwpn '%s'"),
                       def->name, wwnn, wwpn);
 cleanup:
    nodeDeviceUnlock();
    virNodeDeviceDefFree(def);
    VIR_FREE(wwnn);
    VIR_FREE(wwpn);
    return dev;
}
コード例 #9
0
void qwdHelpThread::run()
{
    if ( nullptr==ptr_ConnPtr || nullptr==*ptr_ConnPtr ) {
        emit ptrIsNull();
        return;
    };
    if ( virConnectRef(*ptr_ConnPtr)<0 ) {
        sendConnErrors();
        return;
    };
    connType = QString::fromUtf8(
                virConnectGetType(*ptr_ConnPtr))
            .toLower();
    if ( virConnectClose(*ptr_ConnPtr)<0 )
        sendConnErrors();
}
コード例 #10
0
ファイル: hellolibvirt.c プロジェクト: avdv/libvirt
static int
showHypervisorInfo(virConnectPtr conn)
{
    int ret = 0;
    unsigned long hvVer, major, minor, release;
    const char *hvType;

    /* virConnectGetType returns a pointer to a static string, so no
     * allocation or freeing is necessary; it is possible for the call
     * to fail if, for example, there is no connection to a
     * hypervisor, so check what it returns. */
    hvType = virConnectGetType(conn);
    if (!hvType) {
        ret = 1;
        printf("Failed to get hypervisor type\n");
        showError(conn);
        goto out;
    }

    if (0 != virConnectGetVersion(conn, &hvVer)) {
        ret = 1;
        printf("Failed to get hypervisor version\n");
        showError(conn);
        goto out;
    }

    major = hvVer / 1000000;
    hvVer %= 1000000;
    minor = hvVer / 1000;
    release = hvVer % 1000;

    printf("Hypervisor: \"%s\" version: %lu.%lu.%lu\n",
           hvType,
           major,
           minor,
           release);

out:
    return ret;
}
コード例 #11
0
ファイル: domain.c プロジェクト: woerwin/LuoYunCloud
int libvirt_hypervisor(void)
{
    if (g_conn == NULL)
        return -1;

    const char *type;
    type = virConnectGetType(g_conn);
    if (NULL == type) {
        logerror(_("error in %s(%d)\n"), __func__, __LINE__);
        return -1;
    }

    if (!strcasecmp("QEMU", type))
        return HYPERVISOR_IS_KVM;
    else if (!strcasecmp("XEN", type))
        return HYPERVISOR_IS_XEN;
    else
        return HYPERVISOR_IS_UNKNOWN;

    /* no need to free */
    /* free(type); */
}
コード例 #12
0
ファイル: verify_environments.c プロジェクト: atsaloli/core
static PromiseResult CreateVirtDom(EvalContext *ctx, virConnectPtr vc, Attributes a, const Promise *pp)
{
    int alloc_file = false;
    char *xml_file;
    const char *name;
    char defaultxml[CF_MAXVARSIZE];
    virDomainPtr dom;
    int i;

    snprintf(defaultxml, CF_MAXVARSIZE - 1,
             "<domain type='test'>"
             "  <name>%s</name>"
             "  <memory>8388608</memory>"
             "  <currentMemory>2097152</currentMemory>"
             "  <vcpu>2</vcpu>" "  <os>" "    <type>hvm</type>" "  </os>" "</domain>", pp->promiser);

    for (i = 0; i < CF_MAX_CONCURRENT_ENVIRONMENTS; i++)
    {
        if (CF_RUNNING[i] > 0)
        {
            dom = virDomainLookupByID(vc, CF_RUNNING[i]);
            name = virDomainGetName(dom);

            if (name && strcmp(name, pp->promiser) == 0)
            {
                cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, a, "Found a running environment called '%s' - promise kept",
                     name);
                return PROMISE_RESULT_NOOP;
            }

            virDomainFree(dom);
        }
    }

    for (i = 0; CF_SUSPENDED[i] != NULL; i++)
    {
        if (strcmp(CF_SUSPENDED[i], pp->promiser) == 0)
        {
            Log(LOG_LEVEL_INFO, "Found an existing, but suspended, environment id = %s, called '%s'",
                  CF_SUSPENDED[i], CF_SUSPENDED[i]);
        }
    }

    if(a.env.spec)
    {
        xml_file = xstrdup(a.env.spec);
        alloc_file = true;
    }
    else
    {
        Log(LOG_LEVEL_VERBOSE, "No spec file is promised, so reverting to default settings");
        xml_file = defaultxml;
    }

    PromiseResult result = PROMISE_RESULT_NOOP;
    if ((dom = virDomainCreateXML(vc, xml_file, 0)))
    {
        cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_CHANGE, pp, a, "Created a virtual domain '%s'", pp->promiser);
        result = PromiseResultUpdate(result, PROMISE_RESULT_CHANGE);

        if (a.env.cpus != CF_NOINT)
        {
            int maxcpus;

            if ((maxcpus = virConnectGetMaxVcpus(vc, virConnectGetType(vc))) == -1)
            {
                Log(LOG_LEVEL_VERBOSE, "Can't determine the available CPU resources");
            }
            else
            {
                if (a.env.cpus > maxcpus)
                {
                    Log(LOG_LEVEL_INFO,
                          "The promise to allocate %d CPUs in domain '%s' cannot be kept - only %d exist on the host",
                          a.env.cpus, pp->promiser, maxcpus);
                }
                else if (virDomainSetVcpus(dom, (unsigned int) a.env.cpus) == -1)
                {
                    Log(LOG_LEVEL_INFO, "Unable to adjust CPU count to %d", a.env.cpus);
                }
                else
                {
                    Log(LOG_LEVEL_INFO, "Verified that environment CPU count is now %d", a.env.cpus);
                }
            }
        }

        if (a.env.memory != CF_NOINT)
        {
            unsigned long maxmem;

            if ((maxmem = virDomainGetMaxMemory(dom)) == -1)
            {
                Log(LOG_LEVEL_VERBOSE, "Can't determine the available CPU resources");
            }
            else
            {
                if (virDomainSetMaxMemory(dom, (unsigned long) a.env.memory) == -1)
                {
                    Log(LOG_LEVEL_INFO, " Unable to set the memory limit to %d", a.env.memory);
                }
                else
                {
                    Log(LOG_LEVEL_INFO, "Setting the memory limit to %d", a.env.memory);
                }

                if (virDomainSetMemory(dom, (unsigned long) a.env.memory) == -1)
                {
                    Log(LOG_LEVEL_INFO, " Unable to set the current memory to %d", a.env.memory);
                }
            }
        }

        if (a.env.disk != CF_NOINT)
        {
            Log(LOG_LEVEL_VERBOSE, "Info: env_disk parameter is not currently supported on this platform");
        }

        virDomainFree(dom);
    }
    else
    {
        virErrorPtr vp;

        vp = virGetLastError();

        cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a,
             "Failed to create a virtual domain '%s' - check spec for errors: '%s'", pp->promiser, vp->message);
        result = PromiseResultUpdate(result, PROMISE_RESULT_FAIL);

        Log(LOG_LEVEL_VERBOSE, "Quoted spec file: %s", xml_file);
    }

    if (alloc_file)
    {
        free(xml_file);
    }

    return result;
}
コード例 #13
0
int main(int argvc, char *argv[]){
    static virConnectPtr conn = NULL;
    static virDomainPtr dom = NULL;
    char * Sysinfo;
    char* Capabilities;
    char* Hostname;
    int Vcpunum ;
    const  char* ConnectType;
    unsigned long * hvVer;
    int IsAlive;


    conn = virConnectOpen("xen:///");
    if(conn == NULL){
        fprintf(stderr,"Failed to open connection to xen");
        return -1;
    }
    dom = virDomainLookupByID(conn,1);
    if(dom == NULL){
        fprintf(stderr,"Failed to create a dom");
        return -1;
    }
    
  
    Capabilities = virConnectGetCapabilities(conn);//get capabilities
     if(Capabilities == NULL){
        fprintf(stdout,"failed to GetCapabilities");
        return -1;
     } 
    fprintf(stdout,"ConnectCapabilities %s\n",Capabilities);
    free(Capabilities);


    Sysinfo = virConnectGetSysinfo(conn,0);//Get Sysinfo
     if(Sysinfo ==NULL){
        fprintf(stdout,"failed to getinfo");
        return -1;
     }
    fprintf(stdout,"Sysinfo:%s\n",Sysinfo);
    free(Sysinfo);    


    Hostname = virConnectGetHostname(conn);//get hostname
    if(Hostname == NULL){
        fprintf(stderr,"failed to get hostname");
        return -1;
    }
    fprintf(stdout,"Hostname:%s\n",Hostname);
    free(Hostname);

  
    Vcpunum = virConnectGetMaxVcpus(conn,"xen");//Get Vcpunum
    if(Vcpunum <0){
        fprintf(stdout,"failed to GetCpunum");
        return -1;
    }
    fprintf(stdout,"Vcpunum: %d\n",Vcpunum);
   

    ConnectType = virConnectGetType(conn);//Connect Type
    if(ConnectType ==NULL){
        fprintf(stdout,"failed to GetConnectType");
        return -1;
    }    
    fprintf(stdout,"ConnectType is that :%s\n",ConnectType);    

    
    if(virConnectGetVersion(conn,hvVer)<0){
        fprintf(stderr,"Failed to Get Version");
        return -1;
    }
    fprintf(stdout,"ConnectVersion: %lu\n",*hvVer);

    
    IsAlive = virConnectIsAlive(conn);
    if(IsAlive == 1 ){
        fprintf(stdout,"alive\n");
    }
    else
        if(IsAlive == 0){
            fprintf(stdout,"dead\n");
        }
        else
            fprintf(stdout,"Failed to get Connect Status\n");


    free(dom);
    virConnectClose(conn);
    return 0;
}
コード例 #14
0
ファイル: NodeWrap.cpp プロジェクト: libvirt/libvirt-qpid
NodeWrap::NodeWrap(ManagementAgent* _agent, string _name) : name(_name), agent(_agent)
{
    virNodeInfo info;
    char *hostname;
    char libvirt_version[256] = "Unknown";
    char api_version[256] = "Unknown";
    char hv_version[256] = "Unknown";
    char *uri;
    const char *hv_type;
    unsigned long api_v;
    unsigned long libvirt_v;
    unsigned long hv_v;
    int ret;
    unsigned int major;
    unsigned int minor;
    unsigned int rel;

    conn = virConnectOpen(NULL);
    if (!conn) {
        REPORT_ERR(conn, "virConnectOpen");
        throw -1;
    }

    hostname = virConnectGetHostname(conn);
    if (hostname == NULL) {
        REPORT_ERR(conn, "virConnectGetHostname");
        throw -1;
    }

    hv_type = virConnectGetType(conn);
    if (hv_type == NULL) {
        REPORT_ERR(conn, "virConnectGetType");
        throw -1;
    }

    uri = virConnectGetURI(conn);
    if (uri == NULL) {
        REPORT_ERR(conn, "virConnectGetURI");
        throw -1;
    }

    ret = virGetVersion(&libvirt_v, hv_type, &api_v);
    if (ret < 0) {
        REPORT_ERR(conn, "virGetVersion");
    } else {
        major = libvirt_v / 1000000;
        libvirt_v %= 1000000;
        minor = libvirt_v / 1000;
        rel = libvirt_v % 1000;
        snprintf(libvirt_version, sizeof(libvirt_version), "%d.%d.%d", major, minor, rel);

        major = api_v / 1000000;
        api_v %= 1000000;
        minor = api_v / 1000;
        rel = api_v % 1000;
        snprintf(api_version, sizeof(api_version), "%d.%d.%d", major, minor, rel);
    }

    ret = virConnectGetVersion(conn, &hv_v);
    if (ret < 0) {
        REPORT_ERR(conn, "virConnectGetVersion");
    } else {
        major = hv_v / 1000000;
        hv_v %= 1000000;
        minor = hv_v / 1000;
        rel = hv_v % 1000;
        snprintf(hv_version, sizeof(hv_version), "%d.%d.%d", major, minor, rel);
    }

    ret = virNodeGetInfo(conn, &info);
    if (ret < 0) {
        REPORT_ERR(conn, "virNodeGetInfo");
        memset((void *) &info, sizeof(info), 1);
    }

    mgmtObject = new _qmf::Node(agent, this, hostname, uri, libvirt_version, api_version, hv_version, hv_type,
                                info.model, info.memory, info.cpus, info.mhz, info.nodes, info.sockets,
                                info.cores, info.threads);
    agent->addObject(mgmtObject);
}
コード例 #15
0
static int CreateVirtDom(virConnectPtr vc, char *uri, Attributes a, Promise *pp)
{
    int alloc_file = false;
    char *xml_file;
    const char *name;
    char defaultxml[CF_MAXVARSIZE];
    virDomainPtr dom;
    int i;

    snprintf(defaultxml, CF_MAXVARSIZE - 1,
             "<domain type='test'>"
             "  <name>%s</name>"
             "  <memory>8388608</memory>"
             "  <currentMemory>2097152</currentMemory>"
             "  <vcpu>2</vcpu>" "  <os>" "    <type>hvm</type>" "  </os>" "</domain>", pp->promiser);

    for (i = 0; i < CF_MAX_CONCURRENT_ENVIRONMENTS; i++)
    {
        if (CF_RUNNING[i] > 0)
        {
            dom = virDomainLookupByID(vc, CF_RUNNING[i]);
            name = virDomainGetName(dom);

            if (name && strcmp(name, pp->promiser) == 0)
            {
                cfPS(cf_verbose, CF_NOP, "", pp, a, " -> Found a running environment called \"%s\" - promise kept\n",
                     name);
                return true;
            }

            virDomainFree(dom);
        }
    }

    for (i = 0; CF_SUSPENDED[i] != NULL; i++)
    {
        if (strcmp(CF_SUSPENDED[i], pp->promiser) == 0)
        {
            CfOut(cf_inform, "", " -> Found an existing, but suspended, environment id = %s, called \"%s\"\n",
                  CF_SUSPENDED[i], CF_SUSPENDED[i]);
        }
    }

    if(a.env.spec)
    {
        xml_file = xstrdup(a.env.spec);
        alloc_file = true;
    }
    else
    {
        CfOut(cf_verbose, "", "No spec file is promised, so reverting to default settings");
        xml_file = defaultxml;
    }

    if ((dom = virDomainCreateXML(vc, xml_file, 0)))
    {
        cfPS(cf_verbose, CF_CHG, "", pp, a, " -> Created a virtual domain \"%s\"\n", pp->promiser);

        if (a.env.cpus != CF_NOINT)
        {
            int maxcpus;

            if ((maxcpus = virConnectGetMaxVcpus(vc, virConnectGetType(vc))) == -1)
            {
                CfOut(cf_verbose, "", " !! Can't determine the available CPU resources");
            }
            else
            {
                if (a.env.cpus > maxcpus)
                {
                    CfOut(cf_inform, "",
                          " !! The promise to allocate %d CPUs in domain \"%s\" cannot be kept - only %d exist on the host",
                          a.env.cpus, pp->promiser, maxcpus);
                }
                else if (virDomainSetVcpus(dom, (unsigned int) a.env.cpus) == -1)
                {
                    CfOut(cf_inform, "", " -> Unable to adjust CPU count to %d", a.env.cpus);
                }
                else
                {
                    CfOut(cf_inform, "", " -> Verified that environment CPU count is now %d", a.env.cpus);
                }
            }
        }

        if (a.env.memory != CF_NOINT)
        {
            unsigned long maxmem;

            if ((maxmem = virDomainGetMaxMemory(dom)) == -1)
            {
                CfOut(cf_verbose, "", " !! Can't determine the available CPU resources");
            }
            else
            {
                if (virDomainSetMaxMemory(dom, (unsigned long) a.env.memory) == -1)
                {
                    CfOut(cf_inform, "", " !!! Unable to set the memory limit to %d", a.env.memory);
                }
                else
                {
                    CfOut(cf_inform, "", " -> Setting the memory limit to %d", a.env.memory);
                }

                if (virDomainSetMemory(dom, (unsigned long) a.env.memory) == -1)
                {
                    CfOut(cf_inform, "", " !!! Unable to set the current memory to %d", a.env.memory);
                }
            }
        }

        if (a.env.disk != CF_NOINT)
        {
            CfOut(cf_verbose, "", " -> Info: env_disk parameter is not currently supported on this platform");
        }

        virDomainFree(dom);
    }
    else
    {
        virErrorPtr vp;

        vp = virGetLastError();

        cfPS(cf_verbose, CF_FAIL, "", pp, a,
             " !! Failed to create a virtual domain \"%s\" - check spec for errors: %s", pp->promiser, vp->message);

        CfOut(cf_verbose, "", "Quoted spec file: %s", xml_file);
    }

    if (alloc_file)
    {
        free(xml_file);
    }

    return true;
}
コード例 #16
0
DeviceStack::DeviceStack(
        QWidget *parent, virConnectPtr *conn) :
    QDialog(parent), ptr_ConnPtr(conn)
{
    infoLayout = new QVBoxLayout(this);
    infoWidget = new QScrollArea(this);
    scrolled = new QWidget(this);
    scrolled->setLayout(infoLayout);
    infoWidget->setWidget(scrolled);
    infoWidget->setWidgetResizable(true);
    QString connType = QString(virConnectGetType(*ptr_ConnPtr)).toLower();
    QStringList devSet, devList, devType;
    devList = DEV_LIST;
    devType = DEV_TYPE;
    if ( connType=="qemu" ) {
        devSet = QEMU_DEVICE_LIST;
    } else if ( connType=="lxc" ) {
        devSet = LXC_DEVICE_LIST;
    } else if ( connType=="xen" ) {
        devSet = XEN_DEVICE_LIST;
    } else if ( connType=="vbox" ) {
        devSet = VBOX_DEVICE_LIST;
    } else if ( connType=="vbox" ) {
        devSet = VMWARE_DEVICE_LIST;
    } else if ( connType=="vbox" ) {
        devSet = OPENVZ_DEVICE_LIST;
    };
    deviceList = new QListWidget(this);
    deviceList->setSortingEnabled(false);
    /* set icons & user data */
    for (int i=0; i<devList.count();i++) {
        if ( devSet.contains(devType.at(i)) ) {
            deviceList->addItem(devList.at(i));
            QListWidgetItem *item = deviceList->item(deviceList->count()-1);
            /*
            item->setIcon(
                  QIcon::fromTheme(
                         item->text()
                         .split(" ")
                         .first()
                         .toLower()));
             */
            item->setData(Qt::UserRole, QVariant(devType.at(i)));
            //qDebug()<<item->text();
        };
    };

    // double event for selection item
    //connect(deviceList, SIGNAL(itemClicked(QListWidgetItem*)),
    //        this, SLOT(showDevice(QListWidgetItem*)));
    connect(deviceList, SIGNAL(itemSelectionChanged()),
            this, SLOT(showDevice()));
    listLayout = new QHBoxLayout(this);
    listLayout->addWidget(deviceList, 3);
    listLayout->addWidget(infoWidget, 8);
    listWidget = new QWidget(this);
    listWidget->setLayout(listLayout);

    addDevice = new QPushButton(QIcon::fromTheme("dialog-ok"), "Add Device", this);
    cancel = new QPushButton(QIcon::fromTheme("dialog-cancel"), "Cancel", this);
    connect(addDevice, SIGNAL(clicked()), this, SLOT(set_Result()));
    connect(cancel, SIGNAL(clicked()), this, SLOT(set_Result()));
    buttonlayout = new QHBoxLayout(this);
    buttonlayout->addWidget(addDevice);
    buttonlayout->addWidget(cancel);
    buttons = new QWidget(this);
    buttons->setLayout(buttonlayout);

    commonLayout = new QVBoxLayout(this);
    commonLayout->addWidget(listWidget);
    commonLayout->addWidget(buttons);
    setLayout(commonLayout);
}
コード例 #17
0
ファイル: listwf.c プロジェクト: fangf1/private-cloud-src
int main()
{
    int idCount;
    int i;
    int id;
    //int ids[MAXID];
	int *ids;
    //timeInfoNode timeInfos[MAXID];

    printf("--------------------------------------------------------\n");
    printf("             XEN Domain Monitor \n");
    printf("--------------------------------------------------------\n");

    /* NULL means connect to local Xen hypervisor */
    conn = virConnectOpenReadOnly(NULL);
    if (conn == NULL)
    {
        fprintf(stderr, "Failed to connect to hypervisor\n");
        closeConn();
        return 0;
    }

	/*char* caps;
	caps = virConnectGetCapabilities(conn);
	printf("Capabilities:\n%s\n",caps);
	free(caps);*/
	char *host;
	host = virConnectGetHostname(conn);
	fprintf(stdout, "Hostname:%s\n",host);
	free(host);
	int vcpus;
	vcpus = virConnectGetMaxVcpus(conn,NULL);
	fprintf(stdout, "Maxmum support vcpus:%d\n",vcpus);
	unsigned long long node_free_memory;
	node_free_memory = virNodeGetFreeMemory(conn);
	fprintf(stdout, "free memory:%lld\n",node_free_memory);
	virNodeInfo nodeinfo;
	virNodeGetInfo(conn,&nodeinfo);
	fprintf(stdout, "Model: %s\n", nodeinfo.model);
    fprintf(stdout, "Memory size: %lukb\n", nodeinfo.memory);
    fprintf(stdout, "Number of CPUs: %u\n", nodeinfo.cpus);
    fprintf(stdout, "MHz of CPUs: %u\n", nodeinfo.mhz);
    fprintf(stdout, "Number of NUMA nodes: %u\n", nodeinfo.nodes);
    fprintf(stdout, "Number of CPU sockets: %u\n", nodeinfo.sockets);
    fprintf(stdout, "Number of CPU cores per socket: %u\n", nodeinfo.cores);
    fprintf(stdout, "Number of CPU threads per core: %u\n", nodeinfo.threads);	
    fprintf(stdout, "Virtualization type: %s\n", virConnectGetType(conn));
	unsigned long ver;
	virConnectGetVersion(conn, &ver);
	fprintf(stdout, "Version: %lu\n", ver);
	/*unsigned long Libver;
	virConnectGetLibVersion(conn, &Libver);
	fprintf(stdout, "Libvirt Version: %lu\n", Libver);*/
	char *uri;
	uri = virConnectGetURI(conn);
	fprintf(stdout, "Canonical URI: %s\n", uri);
	free(uri);
	/* get the count of IDs and save these ID into ids[] */
    idCount = virConnectNumOfDomains(conn);
	ids = malloc(sizeof(int) *idCount);
	idCount = virConnectListDomains(conn,ids,idCount);
	//idCount = virConnectListDomains(conn, &ids[0], MAXID);
    if (idCount < 0)
    {
        fprintf(stderr, "Failed to list the domains\n");
        closeConn();
        return 0;
    }

    timeInfoNode timeInfos[idCount];
	printf("Domain Totals: %d\n", idCount);
    printf("ID\tCPU\tMEM\tMaxMEM\tVCPUs\tState\tNAME\n");

    /* loop get the CPUtime info by IDs */
    for (i = 0; i < idCount; i++)
    {
        id = ids[i];
        getTimeInfo(id, &(timeInfos[i]));
    }

    sleep(1);

    /* loop print the domain info and calculate the usage of cpus*/
    for (i = 0; i < idCount; i++)
    {
        id = ids[i];
        getDomainInfo(id, timeInfos[i]);
    }

    free(ids);
	printf("--------------------------------------------------------\n");
    closeConn();
    return 0;
}