Exemplo n.º 1
0
void pci_hostHlpThread::run()
{
    if ( NULL==ptr_ConnPtr || NULL==*ptr_ConnPtr ) {
        emit ptrIsNull();
        return;
    };
    if ( virConnectRef(*ptr_ConnPtr)<0 ) {
        sendConnErrors();
        return;
    };
    QStringList      devices;
    virNodeDevice  **nodeDevices = NULL;
    unsigned int flags =
            VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV;
    int ret = virConnectListAllNodeDevices(*ptr_ConnPtr, &nodeDevices, flags);
    if ( ret<0 ) {
        sendConnErrors();
    } else {
        // therefore correctly to use for() command, because networks[0] can not exist.
        for (int i = 0; i < ret; i++) {
            devices.append( QString("%1\n")
                            // flags: extra flags; not used yet,
                            // so callers should always pass 0
                            .arg(virNodeDeviceGetXMLDesc(nodeDevices[i], 0)));
            virNodeDeviceFree(nodeDevices[i]);
        };
        if (nodeDevices) free(nodeDevices);
    };
    //int devs = virNodeNumOfDevices(ptr_ConnPtr, NULL, 0);
    if ( virConnectClose(*ptr_ConnPtr)<0 )
        sendConnErrors();
    emit result(devices);
}
Result NetControlThread::undefineNetwork()
{
    Result result;
    QString name = task.object;
    bool deleted = false;
    if ( task.srcConnPtr==nullptr ) {
        result.result = false;
        result.err = "Connection pointer is NULL.";
        return result;
    };
    virNetworkPtr network = virNetworkLookupByName(
                *task.srcConnPtr, name.toUtf8().data());
    if ( network!=nullptr ) {
        deleted = (virNetworkUndefine(network)+1) ? true : false;
        if (!deleted)
            result.err = sendConnErrors();
        virNetworkFree(network);
    } else
        result.err = sendConnErrors();
    result.name = name;
    result.result = deleted;
    result.msg.append(QString("'<b>%1</b>' Network %2 Undefined.")
                      .arg(name).arg((deleted)?"":"don't"));
    return result;
}
Result NetControlThread::changeAutoStartNetwork()
{
    Result result;
    QString name = task.object;
    result.name = name;
    int autostart = task.args.sign;
    bool set = false;
    if ( task.srcConnPtr==nullptr ) {
        result.result = false;
        result.err = "Connection pointer is NULL.";
        return result;
    };
    virNetworkPtr network = virNetworkLookupByName(
                *task.srcConnPtr, name.toUtf8().data());
    if ( network!=nullptr ) {
        set = (virNetworkSetAutostart(network, autostart)+1) ? true : false;
        if (!set)
            result.err = sendConnErrors();
        virNetworkFree(network);
    } else
        result.err = sendConnErrors();
    result.result = set;
    result.msg.append(QString("'<b>%1</b>' Network autostart %2 Set.")
                      .arg(name).arg((set)?"":"don't"));
    return result;
}
Exemplo n.º 4
0
void spice_graphHlpThread::run()
{
    if ( NULL==ptr_ConnPtr || NULL==*ptr_ConnPtr ) {
        emit ptrIsNull();
        return;
    };
    if ( virConnectRef(*ptr_ConnPtr)<0 ) {
        sendConnErrors();
        return;
    };
    QStringList nets;
    virNetworkPtr *networks = NULL;
    unsigned int flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE |
                         VIR_CONNECT_LIST_NETWORKS_INACTIVE;
    int ret = virConnectListAllNetworks(*ptr_ConnPtr, &networks, flags);
    if ( ret<0 ) {
        sendConnErrors();
    } else {
        // therefore correctly to use for() command, because networks[0] can not exist.
        for (int i = 0; i < ret; i++) {
            nets.append( virNetworkGetName(networks[i]) );
            virNetworkFree(networks[i]);
        };
        if (networks) free(networks);
    };
    //int devs = virNodeNumOfDevices(ptr_ConnPtr, NULL, 0);
    if ( virConnectClose(*ptr_ConnPtr)<0 ) {
        sendConnErrors();
    };
    emit result(nets);
}
Result StoragePoolControlThread::getStoragePoolXMLDesc()
{
    Result result;
    QString name = task.object;
    bool read = false;
    char *Returns = NULL;
    virStoragePoolPtr storagePool = virStoragePoolLookupByName(
                *task.srcConnPtr, name.toUtf8().data());
    if ( storagePool!=NULL ) {
        Returns = (virStoragePoolGetXMLDesc(storagePool, VIR_STORAGE_XML_INACTIVE));
        if ( Returns==NULL )
            result.err = sendConnErrors();
        else read = true;
        virStoragePoolFree(storagePool);
    } else
        result.err = sendConnErrors();
    QTemporaryFile f;
    f.setAutoRemove(false);
    f.setFileTemplate(QString("%1%2XML_Desc-XXXXXX.xml")
                      .arg(QDir::tempPath()).arg(QDir::separator()));
    read = f.open();
    if (read) f.write(Returns);
    result.fileName.append(f.fileName());
    f.close();
    if ( Returns!=NULL ) free(Returns);
    result.msg.append(QString("'<b>%1</b>' StoragePool %2 XML'ed")
                  .arg(name).arg((read)?"":"don't"));
    result.name = name;
    result.result = read;
    return result;
}
Result StorageVolControlThread::deleteStorageVol()
{
    Result result;
    result.name = QString("%1_%2").arg(task.srcConName).arg(currPoolName);
    QString name = task.object;
    if (currStoragePool!=NULL) {
        virStoragePoolFree(currStoragePool);
        currStoragePool = NULL;
    };
    currStoragePool = virStoragePoolLookupByName(
                *task.srcConnPtr, currPoolName.toUtf8().data());

    // flags: extra flags; not used yet, so callers should always pass 0
    unsigned int flags = 0;
    bool deleted = false;
    virStorageVol *storageVol = virStorageVolLookupByName(
                currStoragePool, name.toUtf8().data());
    if ( storageVol!=NULL ) {
        deleted = (virStorageVolDelete(storageVol, flags)+1) ? true : false;
        if (!deleted)
            result.err = sendConnErrors();
        virStorageVolFree(storageVol);
    } else
        result.err = sendConnErrors();
    result.msg.append(QString("'<b>%1</b>' StorageVol %2 Deleted.")
                      .arg(name).arg((deleted)?"":"don't"));
    result.result = deleted;
    return result;
}
Result StorageVolControlThread::resizeStorageVol()
{
    Result result;
    result.name = QString("%1_%2").arg(task.srcConName).arg(currPoolName);
    QString name = task.object;
    if (currStoragePool!=NULL) {
        virStoragePoolFree(currStoragePool);
        currStoragePool = NULL;
    };
    currStoragePool = virStoragePoolLookupByName(
                *task.srcConnPtr, currPoolName.toUtf8().data());

    unsigned long long capacity = task.args.size;
    bool resized = false;
    virStorageVol *storageVol = virStorageVolLookupByName(
                currStoragePool, name.toUtf8().data());
    if ( storageVol!=NULL ) {
        int ret = virStorageVolResize(
                    storageVol, capacity,
                    VIR_STORAGE_VOL_RESIZE_ALLOCATE |
                    VIR_STORAGE_VOL_RESIZE_SHRINK);
        if ( ret<0 ) {
            result.err = sendConnErrors();
        } else
            resized = true;
        virStorageVolFree(storageVol);
    } else
        result.err = sendConnErrors();
    result.msg.append(
                QString("'<b>%1</b>' StorageVol %2 Resized to %3 (bytes).")
                .arg(name).arg((resized)?"":"don't").arg(capacity));
    result.result = resized;
    return result;
}
void ConnAliveThread::registerConnEvents()
{
    int ret = virConnectRegisterCloseCallback(
                *ptr_ConnPtr,
                connEventCallBack,
                this,
    // don't register freeData, because it remove this thread
                NULL);
    closeCallbackRegistered = !(ret<0);
    if (ret<0) sendConnErrors();
    domainsLifeCycleCallback = virConnectDomainEventRegisterAny(
                *ptr_ConnPtr,
                NULL,
    // set domainsLifeCycleCallback signature
                VIR_DOMAIN_EVENT_ID_LIFECYCLE,
                VIR_DOMAIN_EVENT_CALLBACK(domEventCallback),
                this,
    // don't register freeData, because it remove this thread
                NULL);
    if (ret<0) sendConnErrors();
    networkLifeCycleCallback = virConnectNetworkEventRegisterAny(
                *ptr_ConnPtr,
                NULL,
    // set networksLifeCycleCallback signature
                VIR_NETWORK_EVENT_ID_LIFECYCLE,
                VIR_NETWORK_EVENT_CALLBACK(netEventCallback),
                this,
    // don't register freeData, because it remove this thread
                NULL);
    if (ret<0) sendConnErrors();
}
Exemplo n.º 9
0
 //qDebug()<<URIs;
 foreach (QString uri, URIs) {
     virConnect *connPtr =
             virConnectOpenReadOnly(uri.toUtf8().data());
     if ( Q_NULLPTR!=connPtr ) {
         // don't work for VBox
         // int num = virConnectNumOfDefinedDomains(connPtr);
         virDomainPtr *domains;
         int ret = virConnectListAllDomains(
                     connPtr, &domains, 0);
         if ( ret+1 ) {
             for (int i = 0; i < ret; i++) {
                  if ( virDomainFree(domains[i]) <0 )
                      sendConnErrors();
             };
             if (domains) free(domains);
         } else {
             sendConnErrors();
         };
         virConnectClose(connPtr);
         if ( ret ) {
             emit localConnFound(uri);
         };
     } else {
         sendConnErrors();
     };
     //msleep(333);
 };
QStringList StoragePoolControlThread::changeAutoStartStoragePool()
{
    QStringList result;
    QString name = args.first();
    int autostart;
    if ( args.count()<2 || args.at(1).isEmpty() ) {
        result.append("Incorrect parameters.");
        return result;
    } else {
        bool converted;
        int res = args.at(1).toInt(&converted);
        if (converted) autostart = (res) ? 1 : 0;
        else {
            result.append("Incorrect parameters.");
            return result;
        };
    };
    /*
    virStoragePoolPtr *storagePool;
    unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
                         VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE;
    int ret = virConnectListAllStoragePools( currWorkConnect, &storagePool, flags);
    if ( ret<0 ) {
        sendConnErrors();
        free(storagePool);
        return result;
    };
    //qDebug()<<QString(virConnectGetURI(currWorkConnect));

    int i = 0;
    */
    bool set = false;
    /*
    while ( storagePool[i] != NULL ) {
        QString currNetName = QString( virStoragePoolGetName(storagePool[i]) );
        if ( !set && currNetName==name ) {
            set = (virStoragePoolSetAutostart(storagePool[i], autostart)+1) ? true : false;
            if (!set) sendGlobalErrors();
        };
        virStoragePoolFree(storagePool[i]);
        i++;
    };
    free(storagePool);
    */
    virStoragePoolPtr storagePool = virStoragePoolLookupByName(currWorkConnect, name.toUtf8().data());
    if ( storagePool!=NULL ) {
        set = (virStoragePoolSetAutostart(storagePool, autostart)+1) ? true : false;
        if (!set) sendConnErrors();
        virStoragePoolFree(storagePool);
    } else sendConnErrors();
    result.append(QString("'<b>%1</b>' StoragePool autostart %2 Set.").arg(name).arg((set)?"":"don't"));
    return result;
}
QStringList StoragePoolControlThread::getStoragePoolXMLDesc()
{
    QStringList result;
    QString name = args.first();
    /*
    virStoragePoolPtr *storagePool;
    unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
                         VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE;
    int ret = virConnectListAllStoragePools( currWorkConnect, &storagePool, flags);
    if ( ret<0 ) {
        sendConnErrors();
        free(storagePool);
        return result;
    };
    //qDebug()<<QString(virConnectGetURI(currWorkConnect));

    int i = 0;
    */
    bool read = false;
    char *Returns = NULL;
    /*
    while ( storagePool[i] != NULL ) {
        QString currNetName = QString( virStoragePoolGetName(storagePool[i]) );
        if ( !read && currNetName==name ) {
            Returns = (virStoragePoolGetXMLDesc(storagePool[i], VIR_STORAGE_XML_INACTIVE));
            if ( Returns==NULL ) sendGlobalErrors();
            else read = true;
        };
        virStoragePoolFree(storagePool[i]);
        i++;
    };
    free(storagePool);
    */
    virStoragePoolPtr storagePool = virStoragePoolLookupByName(currWorkConnect, name.toUtf8().data());
    if ( storagePool!=NULL ) {
        Returns = (virStoragePoolGetXMLDesc(storagePool, VIR_STORAGE_XML_INACTIVE));
        if ( Returns==NULL ) sendConnErrors();
        else read = true;
        virStoragePoolFree(storagePool);
    } else sendConnErrors();
    QTemporaryFile f;
    f.setAutoRemove(false);
    f.setFileTemplate(QString("%1%2XML_Desc-XXXXXX.xml").arg(QDir::tempPath()).arg(QDir::separator()));
    read = f.open();
    if (read) f.write(Returns);
    result.append(f.fileName());
    f.close();
    free(Returns);
    result.append(QString("'<b>%1</b>' StoragePool %2 XML'ed").arg(name).arg((read)?"":"don't"));
    return result;
}
Result NetControlThread::defineNetwork()
{
    Result result;
    QString path = task.args.path;
    QByteArray xmlData;
    if ( task.srcConnPtr==nullptr ) {
        result.result = false;
        result.err = "Connection pointer is NULL.";
        return result;
    };
    QFile f;
    f.setFileName(path);
    if ( !f.open(QIODevice::ReadOnly) ) {
        QString msg = QString("File \"%1\"\nnot opened.").arg(path);
        emit errorMsg( msg, number );
        result.err = msg;
        return result;
    };
    xmlData = f.readAll();
    f.close();
    virNetworkPtr network = virNetworkDefineXML(
                *task.srcConnPtr, xmlData.data());
    if ( network==nullptr ) {
        result.err = sendConnErrors();
        return result;
    };
    result.name = QString().fromUtf8( virNetworkGetName(network) );
    result.result = true;
    result.msg.append(QString("'<b>%1</b>' Network from\n\"%2\"\nis defined.")
                      .arg(result.name).arg(path));
    virNetworkFree(network);
    return result;
}
QStringList StoragePoolControlThread::getAllStoragePoolList()
{
    QStringList storagePoolList;
    if ( currWorkConnect!=NULL && keep_alive ) {
        virStoragePoolPtr *storagePool;
        unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
                             VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE;
        int ret = virConnectListAllStoragePools( currWorkConnect, &storagePool, flags);
        if ( ret<0 ) {
            sendConnErrors();
            free(storagePool);
            return storagePoolList;
        };

        int i = 0;
        while ( storagePool[i] != NULL ) {
            QStringList currentAttr;
            QString autostartStr;
            int is_autostart = 0;
            if (virStoragePoolGetAutostart(storagePool[i], &is_autostart) < 0) {
                autostartStr.append("no autostart");
            } else autostartStr.append( is_autostart ? "yes" : "no" );
            currentAttr<< QString().fromUtf8( virStoragePoolGetName(storagePool[i]) )
                       << QString( virStoragePoolIsActive(storagePool[i]) ? "active" : "inactive" )
                       << autostartStr
                       << QString( virStoragePoolIsPersistent(storagePool[i]) ? "yes" : "no" );
            storagePoolList.append(currentAttr.join(" "));
            //qDebug()<<currentAttr;
            virStoragePoolFree(storagePool[i]);
            i++;
        };
        free(storagePool);
    };
    return storagePoolList;
}
/* public slots */
void NetControlThread::execAction(uint _num, TASK _task)
{
    number = _num;
    task = _task;
    keep_alive = false;
    if ( nullptr!=task.srcConnPtr ) {
        // for new virConnect usage create the new virConnectRef[erence]
        int ret = virConnectRef(*task.srcConnPtr);
        if ( ret<0 ) {
            task.srcConnPtr = nullptr;
            sendConnErrors();
        } else
            keep_alive = true;
    };
    if ( keep_alive && !isRunning() ) {
        ptr_ConnPtr = task.srcConnPtr;
        start();
    } else {
        Result result;
        result.type   = "network";
        result.number = number;
        result.action = _EMPTY_ACTION;
        emit resultData(result);
    };
}
void SetDisksDataThread::run()
{
    if ( nullptr==ptr_ConnPtr || nullptr==*ptr_ConnPtr ) {
        emit ptrIsNull();
        return;
    };
    // NOTE: currConnName == domainName
    virDomainPtr domain = virDomainLookupByName(
                *ptr_ConnPtr, currConnName.toUtf8().data());
    if ( nullptr!=domain ) {
        char *xmlDesc = virDomainGetXMLDesc(domain, 0);
        virDomainFree(domain);
        if ( nullptr!=xmlDesc ) {
            QDomDocument doc;
            doc.setContent(QString(xmlDesc));
            free(xmlDesc);
            QDomElement _devices = doc
                    .firstChildElement("domain")
                    .firstChildElement("devices");
            QDomElement _disk = _devices
                    .firstChildElement("disk");
            while ( !_disk.isNull() ) {
                emit diskData(_disk);
                _disk = _disk.nextSiblingElement("disk");
            };
        };
    } else
        sendConnErrors();
}
Result StoragePoolControlThread::defineStoragePool()
{
    Result result;
    QString path = task.args.path;
    QByteArray xmlData;
    QFile f;
    f.setFileName(path);
    if ( !f.open(QIODevice::ReadOnly) ) {
        QString msg = QString("File \"%1\"\nnot opened.").arg(path);
        emit errorMsg( msg, number );
        result.result = false;
        result.err = msg;
        return result;
    };
    xmlData = f.readAll();
    f.close();
    // flags: extra flags; not used yet, so callers should always pass 0
    unsigned int flags = 0;
    virStoragePoolPtr storagePool = virStoragePoolDefineXML(
                *task.srcConnPtr, xmlData.data(), flags);
    if ( storagePool==NULL ) {
        result.err = sendConnErrors();
        result.result = false;
        return result;
    };
    result.name = QString().fromUtf8( virStoragePoolGetName(storagePool) );
    result.msg.append(
                QString("'<b>%1</b>' StoragePool from\n\"%2\"\nis Defined.")
                .arg(result.name).arg(path));
    virStoragePoolFree(storagePool);
    result.result = true;
    return result;
}
Exemplo n.º 17
0
void ConnAliveThread::closeConnection()
{
    //qDebug()<<"closeConnection0"<<*ptr_ConnPtr<<URI;
    if ( keep_alive ) {
        keep_alive = false;
        return;
    };
    //qDebug()<<"closeConnection1"<<*ptr_ConnPtr<<URI;
    CONN_STATE state;
    if ( *ptr_ConnPtr!=NULL ) {
        //qDebug()<<"closeConnection2"<<*ptr_ConnPtr<<URI;
        unregisterConnEvents();
        //qDebug()<<"closeConnection3"<<*ptr_ConnPtr<<URI;
        int ret = virConnectClose(*ptr_ConnPtr);
        //qDebug()<<"virConnectRef -1"<<"ConnAliveThread"<<URI<<(ret+1>0);
        if ( ret<0 ) {
            state = FAILED;
            sendConnErrors();
        } else {
            emit connMsg( QString("close exit code: %1").arg(ret) );
            state = CLOSED;
            emit connClosed(onView);
        };
        *ptr_ConnPtr = NULL;
    } else {
        emit connMsg( QString("connect is NULL") );
        state = FAILED;
    };
    emit changeConnState(state);
}
void StorageVolControlThread::execAction(uint _num, TASK _task)
{
    number = _num;
    task = _task;
    currPoolName = task.args.object;
    if ( NULL!=task.srcConnPtr ) {
        // for new virConnect usage create the new virConnectRef[erence]
        int ret = virConnectRef(*task.srcConnPtr);
        if ( ret<0 ) {
            task.srcConnPtr = NULL;
            sendConnErrors();
            keep_alive = false;
        } else
            keep_alive = true;
    };
    if ( keep_alive && !isRunning() ) {
        ptr_ConnPtr = task.srcConnPtr;
        start();
    } else {
        Result result;
        result.type   = "volume";
        result.number = number;
        result.action = _EMPTY_ACTION;
        emit resultData(result);
    };
}
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();
}
Exemplo n.º 20
0
/* private slots */
void USB_Host_Device::setAvailabledUSBDevices()
{
    int i = 0;
    QStringList      devices;
    virNodeDevice  **nodeDevices = NULL;
    if ( currWorkConnect!=NULL ) {
        unsigned int flags =
                VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV;
        int ret = virConnectListAllNodeDevices(currWorkConnect, &nodeDevices, flags);
        if ( ret<0 ) {
            sendConnErrors();
        } else {
            while ( nodeDevices[i] != NULL ) {
                devices.append( QString("%1\n")
                                // flags: extra flags; not used yet,
                                // so callers should always pass 0
                                .arg(virNodeDeviceGetXMLDesc(nodeDevices[i], 0)));
                virNodeDeviceFree(nodeDevices[i]);
                i++;
            };
        };
        free(nodeDevices);
    };
    //int devs = virNodeNumOfDevices(currWorkConnect, NULL, 0);
    //qDebug()<<"Devices("<<devs<<i<<"):\n"<<devices.join("\n");
    // set unique device description to devList
    foreach (QString _dev, devices) {
        //qDebug()<<_dev;
        QString devName, devIdentity;
        QDomElement capability, product, vendor;
        QDomDocument doc = QDomDocument();
        doc.setContent(_dev);
        // filter out **** Host Controllers
        if ( !doc.
             firstChildElement("device").
             firstChildElement("parent").
             firstChild().toText().data().
             startsWith("usb") ) continue;
        //
        capability = doc.firstChildElement("device").
                firstChildElement("capability");
        product = capability.firstChildElement("product");
        vendor = capability.firstChildElement("vendor");
        // devIdentity format: <vendor:product>
        devIdentity.append(vendor.attribute("id"));
        devIdentity.append(":");
        devIdentity.append(product.attribute("id"));
        // devName format: <vendor_product>
        devName.append(vendor.firstChild().toText().data());
        devName.append("\n");
        devName.append(product.firstChild().toText().data());
        if ( devList->findItems(devName,
                                Qt::MatchExactly |
                                Qt::MatchCaseSensitive)
             .isEmpty() ) {
            devList->insertItem(0, devName);
            devList->item(0)->setData(Qt::UserRole, devIdentity);
        };
    };
Result StoragePoolControlThread::undefineStoragePool()
{
    Result result;
    QString name = task.object;
    bool deleted = false;
    virStoragePoolPtr storagePool = virStoragePoolLookupByName(
                task.sourceConn, name.toUtf8().data());
    if ( storagePool!=NULL ) {
        deleted = (virStoragePoolUndefine(storagePool)+1) ? true : false;
        if (!deleted) sendConnErrors();
        virStoragePoolFree(storagePool);
    } else sendConnErrors();
    result.msg.append(QString("'<b>%1</b>' StoragePool %2 Undefined.")
                  .arg(name).arg((deleted)?"":"don't"));
    result.name = name;
    result.result = deleted;
    return result;
}
Result StoragePoolControlThread::changeAutoStartStoragePool()
{
    Result result;
    QString name = task.object;
    int autostart = task.args.sign;
    bool set = false;
    virStoragePoolPtr storagePool = virStoragePoolLookupByName(
                task.sourceConn, name.toUtf8().data());
    if ( storagePool!=NULL ) {
        set = (virStoragePoolSetAutostart(storagePool, autostart)+1) ? true : false;
        if (!set) sendConnErrors();
        virStoragePoolFree(storagePool);
    } else sendConnErrors();
    result.msg.append(QString("'<b>%1</b>' StoragePool autostart %2 Set.")
                  .arg(name).arg((set)?"":"don't"));
    result.name = name;
    result.result = set;
    return result;
}
QStringList StoragePoolControlThread::startStoragePool()
{
    QStringList result;
    QString name = args.first();
    unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
                         VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE;
    /*
    virStoragePoolPtr *storagePool;
    int ret = virConnectListAllStoragePools( currWorkConnect, &storagePool, flags);
    if ( ret<0 ) {
        sendConnErrors();
        free(storagePool);
        return result;
    };
    //qDebug()<<QString(virConnectGetURI(currWorkConnect));

    int i = 0;
    */
    bool started = false;
    // flags: extra flags; not used yet, so callers should always pass 0
    flags = 0;
    /*
    while ( storagePool[i] != NULL ) {
        QString currPoolName = QString( virStoragePoolGetName(storagePool[i]) );
        if ( !started && currPoolName==name ) {
            started = (virStoragePoolCreate(storagePool[i], flags)+1) ? true : false;
            if (!started) sendGlobalErrors();
        };
        virStoragePoolFree(storagePool[i]);
        i++;
    };
    free(storagePool);
    */
    virStoragePoolPtr storagePool = virStoragePoolLookupByName(currWorkConnect, name.toUtf8().data());
    if ( storagePool!=NULL ) {
        started = (virStoragePoolCreate(storagePool, flags)+1) ? true : false;
        if (!started) sendConnErrors();
        virStoragePoolFree(storagePool);
    } else sendConnErrors();
    result.append(QString("'<b>%1</b>' StoragePool %2 Started.").arg(name).arg((started)?"":"don't"));
    return result;
}
Result StoragePoolControlThread::deleteStoragePool()
{
    Result result;
    QString name = task.object;
    uint flags = (task.args.sign)? VIR_STORAGE_POOL_DELETE_ZEROED
                                 : VIR_STORAGE_POOL_DELETE_NORMAL;
    bool deleted = false;
    virStoragePoolPtr storagePool = virStoragePoolLookupByName(
                task.sourceConn, name.toUtf8().data());
    if ( storagePool!=NULL ) {
        deleted = (virStoragePoolDelete(storagePool, flags)+1) ? true : false;
        if (!deleted) sendConnErrors();
        virStoragePoolFree(storagePool);
    } else sendConnErrors();
    result.msg.append(QString("'<b>%1</b>' StoragePool %2 Deleted.")
                  .arg(name).arg((deleted)?"":"don't"));
    result.name = name;
    result.result = deleted;
    return result;
}
Result StoragePoolControlThread::destroyStoragePool()
{
    Result result;
    QString name = task.object;
    bool deleted = false;
    virStoragePoolPtr storagePool = virStoragePoolLookupByName(
                *task.srcConnPtr, name.toUtf8().data());
    if ( storagePool!=NULL ) {
        deleted = (virStoragePoolDestroy(storagePool)+1) ? true : false;
        if (!deleted)
            result.err = sendConnErrors();
        virStoragePoolFree(storagePool);
    } else
        result.err = sendConnErrors();
    result.msg.append(QString("'<b>%1</b>' StoragePool %2 Destroyed.")
                  .arg(name).arg((deleted)?"":"don't"));
    result.name = name;
    result.result = deleted;
    return result;
}
QStringList StoragePoolControlThread::undefineStoragePool()
{
    QStringList result;
    QString name = args.first();
    /*
    virStoragePoolPtr *storagePool;
    unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
                         VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE;
    int ret = virConnectListAllStoragePools( currWorkConnect, &storagePool, flags);
    if ( ret<0 ) {
        sendConnErrors();
        free(storagePool);
        return result;
    };
    //qDebug()<<QString(virConnectGetURI(currWorkConnect));

    int i = 0;
    */
    bool deleted = false;
    /*
    while ( storagePool[i] != NULL ) {
        QString currPoolName = QString( virStoragePoolGetName(storagePool[i]) );
        if ( !deleted && currPoolName==name ) {
            deleted = (virStoragePoolUndefine(storagePool[i])+1) ? true : false;
            if (!deleted) sendGlobalErrors();
        };
        qDebug()<<QVariant(deleted).toString()<<currPoolName<<name;
        virStoragePoolFree(storagePool[i]);
        i++;
    };
    free(storagePool);
    */
    virStoragePoolPtr storagePool = virStoragePoolLookupByName(currWorkConnect, name.toUtf8().data());
    if ( storagePool!=NULL ) {
        deleted = (virStoragePoolDestroy(storagePool)+1) ? true : false;
        if (!deleted) sendConnErrors();
        virStoragePoolFree(storagePool);
    } else sendConnErrors();
    result.append(QString("'<b>%1</b>' StoragePool %2 Undefined.").arg(name).arg((deleted)?"":"don't"));
    return result;
}
Result StoragePoolControlThread::getAllStoragePoolDataList()
{
    Result result;
    QStringList storagePoolDataList;
    if ( task.srcConnPtr!=NULL && keep_alive ) {
        virStoragePoolPtr *storagePool = NULL;
        unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
                             VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE;
        int ret = virConnectListAllStoragePools(
                    *task.srcConnPtr, &storagePool, flags);
        if ( ret<0 ) {
            result.err = sendConnErrors();
            result.result = false;
            result.msg = storagePoolDataList;
            return result;
        };

        // therefore correctly to use for() command, because storagePool[0] can not exist.
        for (int i = 0; i < ret; i++) {
            QStringList currentAttr;
            QString type, source, target;
            char *Returns = (virStoragePoolGetXMLDesc(storagePool[i], VIR_STORAGE_XML_INACTIVE));
            if ( Returns!=NULL ) {
                QDomDocument doc;
                QString s;
                QTextStream str;
                str.setString(&s);
                doc.setContent(QString(Returns));
                QDomElement _pool, _el;
                _pool= doc.firstChildElement("pool");
                type = _pool.attribute("type");
                _el = _pool.firstChildElement("source");
                _el.save(str, 4);
                source = str.readAll();
                _el = _pool.firstChildElement("target");
                _el.save(str, 4);
                target = str.readAll();
                free(Returns);
            };
            currentAttr<< QString::fromUtf8( virStoragePoolGetName(storagePool[i]) )
                       << type << source << target;
            storagePoolDataList.append(currentAttr.join(DFR));
            //qDebug()<<currentAttr;
            virStoragePoolFree(storagePool[i]);
        };
        free(storagePool);
        result.result = true;
    } else {
        result.result = false;
    };
    result.msg = storagePoolDataList;
    return result;
}
Result StorageVolControlThread::getStorageVolXMLDesc()
{
    Result result;
    result.name = QString("%1_%2").arg(task.srcConName).arg(currPoolName);
    QString name = task.object;
    if (currStoragePool!=NULL) {
        virStoragePoolFree(currStoragePool);
        currStoragePool = NULL;
    };
    currStoragePool = virStoragePoolLookupByName(
                *task.srcConnPtr, currPoolName.toUtf8().data());

    bool read = false;
    char *Returns = NULL;
    // flags: extra flags; not used yet, so callers should always pass 0
    unsigned int flags = 0;
    virStorageVol *storageVol = virStorageVolLookupByName(
                currStoragePool, name.toUtf8().data());
    if ( storageVol!=NULL ) {
        Returns = virStorageVolGetXMLDesc(storageVol, flags);
        if ( Returns==NULL )
            result.err = sendConnErrors();
        else read = true;
        virStorageVolFree(storageVol);
    } else
        result.err = sendConnErrors();
    QTemporaryFile f;
    f.setAutoRemove(false);
    f.setFileTemplate(QString("%1%2XML_Desc-XXXXXX.xml")
                      .arg(QDir::tempPath()).arg(QDir::separator()));
    read = f.open();
    if (read) f.write(Returns);
    result.fileName.append(f.fileName());
    f.close();
    if ( Returns!=NULL ) free(Returns);
    result.msg.append(QString("'<b>%1</b>' StorageVol %2 XML'ed")
                  .arg(name).arg((read)?"":"don't"));
    result.result = read;
    return result;
}
Result StoragePoolControlThread::startStoragePool()
{
    Result result;
    QString name = task.object;
    unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
                         VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE;
    bool started = false;
    // flags: extra flags; not used yet, so callers should always pass 0
    flags = 0;
    virStoragePoolPtr storagePool = virStoragePoolLookupByName(
                task.sourceConn, name.toUtf8().data());
    if ( storagePool!=NULL ) {
        started = (virStoragePoolCreate(storagePool, flags)+1) ? true : false;
        if (!started) sendConnErrors();
        virStoragePoolFree(storagePool);
    } else sendConnErrors();
    result.msg.append(QString("'<b>%1</b>' StoragePool %2 Started.")
                  .arg(name).arg((started)?"":"don't"));
    result.name = name;
    result.result = started;
    return result;
}
Result NetControlThread::getVirtNetXMLDesc()
{
    Result result;
    QString name = task.object;
    result.name = name;
    bool read = false;
    char *Returns = nullptr;
    if ( task.srcConnPtr==nullptr ) {
        result.result = false;
        result.err = "Connection pointer is NULL.";
        return result;
    };
    virNetworkPtr network = virNetworkLookupByName(
                *task.srcConnPtr, name.toUtf8().data());
    if ( network!=nullptr ) {
        Returns = virNetworkGetXMLDesc(
                    network, VIR_NETWORK_XML_INACTIVE);
        if ( Returns==nullptr )
            result.err = sendConnErrors();
        else read = true;
        virNetworkFree(network);
    } else
        result.err = sendConnErrors();
    QTemporaryFile f;
    f.setAutoRemove(false);
    f.setFileTemplate(
                QString("%1%2XML_Desc-XXXXXX.xml")
                .arg(QDir::tempPath()).arg(QDir::separator()));
    read = f.open();
    if (read) f.write(Returns);
    result.fileName.append(f.fileName());
    f.close();
    if ( Returns!=nullptr ) free(Returns);
    result.result = read;
    result.msg.append(QString("'<b>%1</b>' Network %2 XML'ed")
                      .arg(name).arg((read)?"":"don't"));
    return result;
}