Search in sources :

Example 16 with LibvirtException

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

the class LibvirtComputingResource method stopVM.

protected String stopVM(Connect conn, String vmName, boolean force) {
    Domain dm = null;
    try {
        dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName.getBytes()));
        if (force) {
            if (dm.getInfo().state != DomainInfo.DomainState.VIR_DOMAIN_SHUTOFF) {
                dm.destroy();
            }
        } else {
            if (dm.getInfo().state == DomainInfo.DomainState.VIR_DOMAIN_SHUTOFF) {
                return null;
            }
            dm.shutdown();
            int retry = _stopTimeout / 2000;
            /* Wait for the domain gets into shutoff state */
            while ((dm.getInfo().state != DomainInfo.DomainState.VIR_DOMAIN_SHUTOFF) && (retry >= 0)) {
                Thread.sleep(2000);
                retry--;
            }
            if (retry < 0) {
                s_logger.warn("Timed out waiting for domain " + vmName + " to shutdown gracefully");
                return Script.ERR_TIMEOUT;
            }
        }
    } catch (LibvirtException e) {
        s_logger.debug("Failed to stop VM :" + vmName + " :", e);
        return e.getMessage();
    } catch (InterruptedException ie) {
        s_logger.debug("Interrupted sleep");
        return ie.getMessage();
    } catch (Exception e) {
        s_logger.debug("Failed to stop VM :" + vmName + " :", e);
        return e.getMessage();
    } finally {
        try {
            if (dm != null) {
                dm.free();
            }
        } catch (LibvirtException e) {
        }
    }
    return null;
}
Also used : LibvirtException(org.libvirt.LibvirtException) Domain(org.libvirt.Domain) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) LibvirtException(org.libvirt.LibvirtException) FileNotFoundException(java.io.FileNotFoundException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException)

Example 17 with LibvirtException

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

the class LibvirtComputingResource method execute.

private Answer execute(NetworkRulesSystemVmCommand cmd) {
    boolean success = false;
    Connect conn;
    try {
        conn = LibvirtConnection.getConnection();
        success = default_network_rules_for_systemvm(conn, cmd.getVmName());
    } catch (LibvirtException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return new Answer(cmd, success, "");
}
Also used : FenceAnswer(com.cloud.agent.api.FenceAnswer) ConsoleProxyLoadAnswer(com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer) DeleteSnapshotBackupAnswer(com.cloud.agent.api.DeleteSnapshotBackupAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect)

Example 18 with LibvirtException

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

the class LibvirtStorageAdaptor method createFileBasedStoragePool.

public StoragePool createFileBasedStoragePool(Connect conn, String localStoragePath, String uuid) {
    if (!(_storageLayer.exists(localStoragePath) && _storageLayer.isDirectory(localStoragePath))) {
        return null;
    }
    File path = new File(localStoragePath);
    if (!(path.canWrite() && path.canRead() && path.canExecute())) {
        return null;
    }
    StoragePool pool = null;
    try {
        pool = conn.storagePoolLookupByUUIDString(uuid);
    } catch (LibvirtException e) {
    }
    if (pool == null) {
        LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(poolType.DIR, uuid, uuid, null, null, localStoragePath);
        try {
            pool = conn.storagePoolDefineXML(spd.toString(), 0);
            pool.create(0);
        } catch (LibvirtException e) {
            if (pool != null) {
                try {
                    pool.destroy();
                    pool.undefine();
                } catch (LibvirtException e1) {
                }
                pool = null;
            }
            throw new CloudRuntimeException(e.toString());
        }
    }
    try {
        StoragePoolInfo spi = pool.getInfo();
        if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
            pool.create(0);
        }
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
    return pool;
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolInfo(org.libvirt.StoragePoolInfo) LibvirtStoragePoolDef(com.cloud.agent.resource.computing.LibvirtStoragePoolDef) File(java.io.File)

Example 19 with LibvirtException

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

the class LibvirtStorageAdaptor method getPhysicalDisk.

@Override
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    try {
        StorageVol vol = this.getVolume(libvirtPool.getPool(), volumeUuid);
        KVMPhysicalDisk disk;
        LibvirtStorageVolumeDef voldef = getStorageVolumeDef(libvirtPool.getPool().getConnect(), vol);
        disk = new KVMPhysicalDisk(vol.getPath(), vol.getName(), pool);
        disk.setSize(vol.getInfo().allocation);
        disk.setVirtualSize(vol.getInfo().capacity);
        if (voldef.getFormat() == null) {
            disk.setFormat(pool.getDefaultFormat());
        } else if (voldef.getFormat() == LibvirtStorageVolumeDef.volFormat.QCOW2) {
            disk.setFormat(KVMPhysicalDisk.PhysicalDiskFormat.QCOW2);
        } else if (voldef.getFormat() == LibvirtStorageVolumeDef.volFormat.RAW) {
            disk.setFormat(KVMPhysicalDisk.PhysicalDiskFormat.RAW);
        }
        return disk;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : StorageVol(org.libvirt.StorageVol) LibvirtStorageVolumeDef(com.cloud.agent.resource.computing.LibvirtStorageVolumeDef) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 20 with LibvirtException

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

the class LibvirtStorageAdaptor method deletePhysicalDisk.

@Override
public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    try {
        StorageVol vol = this.getVolume(libvirtPool.getPool(), uuid);
        vol.delete(0);
        vol.free();
        return true;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

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