Search in sources :

Example 21 with LibvirtException

use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.

the class CloudZonesComputingResource method execute.

protected Answer execute(StopCommand cmd) {
    final String vmName = cmd.getVmName();
    Long bytesReceived = new Long(0);
    Long bytesSent = new Long(0);
    State state = null;
    synchronized (_vms) {
        state = _vms.get(vmName);
        _vms.put(vmName, State.Stopping);
    }
    try {
        Connect conn = LibvirtConnection.getConnection();
        try {
            Domain dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName.getBytes()));
        } catch (LibvirtException e) {
            state = State.Stopped;
            return new StopAnswer(cmd, null, 0, bytesSent, bytesReceived);
        }
        String macAddress = null;
        if (vmName.startsWith("i-")) {
            List<InterfaceDef> nics = getInterfaces(conn, vmName);
            if (!nics.isEmpty()) {
                macAddress = nics.get(0).getMacAddress();
            }
        }
        destroy_network_rules_for_vm(conn, vmName);
        String result = stopVM(conn, vmName, defineOps.UNDEFINE_VM);
        try {
            cleanupVnet(conn, cmd.getVnet());
            _dhcpSnooper.cleanup(macAddress, vmName);
            _vmDataServer.handleVmStopped(cmd.getVmName());
        } catch (Exception e) {
        }
        state = State.Stopped;
        return new StopAnswer(cmd, result, 0, bytesSent, bytesReceived);
    } catch (LibvirtException e) {
        return new StopAnswer(cmd, e.getMessage());
    } finally {
        synchronized (_vms) {
            if (state != null) {
                _vms.put(vmName, state);
            } else {
                _vms.remove(vmName);
            }
        }
    }
}
Also used : InterfaceDef(com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef) LibvirtException(org.libvirt.LibvirtException) State(com.cloud.vm.VirtualMachine.State) Connect(org.libvirt.Connect) Domain(org.libvirt.Domain) StopAnswer(com.cloud.agent.api.StopAnswer) ConfigurationException(javax.naming.ConfigurationException) LibvirtException(org.libvirt.LibvirtException)

Example 22 with LibvirtException

use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.

the class LibvirtStorageAdaptor method listPhysicalDisks.

@Override
public List<KVMPhysicalDisk> listPhysicalDisks(String storagePoolUuid, KVMStoragePool pool) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    StoragePool virtPool = libvirtPool.getPool();
    List<KVMPhysicalDisk> disks = new ArrayList<KVMPhysicalDisk>();
    try {
        String[] vols = virtPool.listVolumes();
        for (String volName : vols) {
            KVMPhysicalDisk disk = this.getPhysicalDisk(volName, pool);
            disks.add(disk);
        }
        return disks;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList)

Example 23 with LibvirtException

use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.

the class LibvirtStorageAdaptor method deleteStoragePool.

@Override
public boolean deleteStoragePool(KVMStoragePool pool) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    StoragePool virtPool = libvirtPool.getPool();
    try {
        virtPool.destroy();
        virtPool.undefine();
        virtPool.free();
    } catch (LibvirtException e) {
        return false;
    }
    return true;
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException)

Example 24 with LibvirtException

use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.

the class LibvirtStorageAdaptor method getVolumeFromURI.

public StorageVol getVolumeFromURI(Connect conn, String volPath) throws LibvirtException, URISyntaxException {
    int index = volPath.lastIndexOf("/");
    URI volDir = null;
    StoragePool sp = null;
    StorageVol vol = null;
    try {
        volDir = new URI(volPath.substring(0, index));
        String volName = volPath.substring(index + 1);
        sp = getStoragePoolbyURI(conn, volDir);
        vol = sp.storageVolLookupByName(volName);
        return vol;
    } catch (LibvirtException e) {
        s_logger.debug("Faild to get vol path: " + e.toString());
        throw e;
    } finally {
        try {
            if (sp != null) {
                sp.free();
            }
        } catch (LibvirtException e) {
        }
    }
}
Also used : StoragePool(org.libvirt.StoragePool) StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) URI(java.net.URI)

Example 25 with LibvirtException

use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method stop.

@Override
public boolean stop() {
    try {
        Connect conn = LibvirtConnection.getConnection();
        conn.close();
    } catch (LibvirtException e) {
    }
    return true;
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect)

Aggregations

LibvirtException (org.libvirt.LibvirtException)176 Connect (org.libvirt.Connect)109 Answer (com.cloud.agent.api.Answer)63 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)58 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)55 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)55 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)55 Test (org.junit.Test)55 Domain (org.libvirt.Domain)53 InternalErrorException (com.cloud.exception.InternalErrorException)41 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)41 URISyntaxException (java.net.URISyntaxException)32 StoragePool (org.libvirt.StoragePool)27 NicTO (com.cloud.agent.api.to.NicTO)25 InterfaceDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef)23 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)22 ConfigurationException (javax.naming.ConfigurationException)22 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)21 FileNotFoundException (java.io.FileNotFoundException)17