Search in sources :

Example 6 with PhysicalDiskFormat

use of org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat in project cloudstack by apache.

the class QemuImgFileTest method testFileNameAndFormatAtContructor.

@Test
public void testFileNameAndFormatAtContructor() {
    PhysicalDiskFormat format = PhysicalDiskFormat.RAW;
    String filename = "/tmp/test-image.qcow2";
    QemuImgFile file = new QemuImgFile(filename, format);
    assertEquals(file.getFileName(), filename);
    assertEquals(file.getFormat(), format);
}
Also used : PhysicalDiskFormat(org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat) Test(org.junit.Test)

Example 7 with PhysicalDiskFormat

use of org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat in project cloudstack by apache.

the class KVMStorageProcessor method createVolume.

@Override
public Answer createVolume(final CreateObjectCommand cmd) {
    final VolumeObjectTO volume = (VolumeObjectTO) cmd.getData();
    final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
    KVMStoragePool primaryPool = null;
    KVMPhysicalDisk vol = null;
    long disksize;
    try {
        primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
        disksize = volume.getSize();
        PhysicalDiskFormat format;
        if (volume.getFormat() == null || StoragePoolType.RBD.equals(primaryStore.getPoolType())) {
            format = primaryPool.getDefaultFormat();
        } else {
            format = PhysicalDiskFormat.valueOf(volume.getFormat().toString().toUpperCase());
        }
        MigrationOptions migrationOptions = volume.getMigrationOptions();
        if (migrationOptions != null) {
            String srcStoreUuid = migrationOptions.getSrcPoolUuid();
            StoragePoolType srcPoolType = migrationOptions.getSrcPoolType();
            KVMStoragePool srcPool = storagePoolMgr.getStoragePool(srcPoolType, srcStoreUuid);
            int timeout = migrationOptions.getTimeout();
            if (migrationOptions.getType() == MigrationOptions.Type.LinkedClone) {
                vol = createLinkedCloneVolume(migrationOptions, srcPool, primaryPool, volume, format, timeout);
            } else if (migrationOptions.getType() == MigrationOptions.Type.FullClone) {
                vol = createFullCloneVolume(migrationOptions, volume, primaryPool, format);
            }
        } else {
            vol = primaryPool.createPhysicalDisk(volume.getUuid(), format, volume.getProvisioningType(), disksize);
        }
        final VolumeObjectTO newVol = new VolumeObjectTO();
        if (vol != null) {
            newVol.setPath(vol.getName());
        }
        newVol.setSize(volume.getSize());
        newVol.setFormat(ImageFormat.valueOf(format.toString().toUpperCase()));
        return new CreateObjectAnswer(newVol);
    } catch (final Exception e) {
        s_logger.debug("Failed to create volume: ", e);
        return new CreateObjectAnswer(e.toString());
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) RbdException(com.ceph.rbd.RbdException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LibvirtException(org.libvirt.LibvirtException) QemuImgException(org.apache.cloudstack.utils.qemu.QemuImgException) FileNotFoundException(java.io.FileNotFoundException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) RadosException(com.ceph.rados.exceptions.RadosException) PhysicalDiskFormat(org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat) MigrationOptions(com.cloud.storage.MigrationOptions)

Example 8 with PhysicalDiskFormat

use of org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat in project cloudstack by apache.

the class LibvirtStorageAdaptor method createDiskFromTemplateBacking.

@Override
public KVMPhysicalDisk createDiskFromTemplateBacking(KVMPhysicalDisk template, String name, PhysicalDiskFormat format, long size, KVMStoragePool destPool, int timeout) {
    String volumeDesc = String.format("volume [%s], with template backing [%s], in pool [%s] (%s), with size [%s]", name, template.getName(), destPool.getUuid(), destPool.getType(), size);
    if (!poolTypesThatEnableCreateDiskFromTemplateBacking.contains(destPool.getType())) {
        s_logger.info(String.format("Skipping creation of %s due to pool type is none of the following types %s.", volumeDesc, poolTypesThatEnableCreateDiskFromTemplateBacking.stream().map(type -> type.toString()).collect(Collectors.joining(", "))));
        return null;
    }
    if (format != PhysicalDiskFormat.QCOW2) {
        s_logger.info(String.format("Skipping creation of %s due to format [%s] is not [%s].", volumeDesc, format, PhysicalDiskFormat.QCOW2));
        return null;
    }
    s_logger.info(String.format("Creating %s.", volumeDesc));
    String destPoolLocalPath = destPool.getLocalPath();
    String destPath = String.format("%s%s%s", destPoolLocalPath, destPoolLocalPath.endsWith("/") ? "" : "/", name);
    try {
        QemuImgFile destFile = new QemuImgFile(destPath, format);
        destFile.setSize(size);
        QemuImgFile backingFile = new QemuImgFile(template.getPath(), template.getFormat());
        new QemuImg(timeout).create(destFile, backingFile);
    } catch (QemuImgException e) {
        s_logger.error(String.format("Failed to create %s in [%s] due to [%s].", volumeDesc, destPath, e.getMessage()), e);
    }
    return null;
}
Also used : Arrays(java.util.Arrays) LibvirtConnection(com.cloud.hypervisor.kvm.resource.LibvirtConnection) QemuImgFile(org.apache.cloudstack.utils.qemu.QemuImgFile) Base64(org.apache.commons.codec.binary.Base64) RbdSnapInfo(com.ceph.rbd.jna.RbdSnapInfo) LibvirtException(org.libvirt.LibvirtException) StoragePool(org.libvirt.StoragePool) Logger(org.apache.log4j.Logger) Map(java.util.Map) Storage(com.cloud.storage.Storage) RbdException(com.ceph.rbd.RbdException) QemuImgException(org.apache.cloudstack.utils.qemu.QemuImgException) Rbd(com.ceph.rbd.Rbd) RbdImageInfo(com.ceph.rbd.jna.RbdImageInfo) Set(java.util.Set) UUID(java.util.UUID) IoCTX(com.ceph.rados.IoCTX) Collectors(java.util.stream.Collectors) Script(com.cloud.utils.script.Script) RbdImage(com.ceph.rbd.RbdImage) List(java.util.List) PhysicalDiskFormat(org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat) ErrorCode(com.ceph.rados.exceptions.ErrorCode) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) Rados(com.ceph.rados.Rados) StorageVol(org.libvirt.StorageVol) AuthenticationType(com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef.AuthenticationType) InternalErrorException(com.cloud.exception.InternalErrorException) HashMap(java.util.HashMap) LibvirtStoragePoolXMLParser(com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolXMLParser) LibvirtStoragePoolDef(com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef) ArrayList(java.util.ArrayList) QemuImg(org.apache.cloudstack.utils.qemu.QemuImg) HashSet(java.util.HashSet) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connect(org.libvirt.Connect) Secret(org.libvirt.Secret) Charset(java.nio.charset.Charset) RadosException(com.ceph.rados.exceptions.RadosException) VolumeFormat(com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef.VolumeFormat) LibvirtStorageVolumeDef(com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef) Usage(com.cloud.hypervisor.kvm.resource.LibvirtSecretDef.Usage) LibvirtStorageVolumeXMLParser(com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeXMLParser) PoolType(com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef.PoolType) File(java.io.File) NumbersUtil.toHumanReadableSize(com.cloud.utils.NumbersUtil.toHumanReadableSize) LibvirtSecretDef(com.cloud.hypervisor.kvm.resource.LibvirtSecretDef) StoragePoolState(org.libvirt.StoragePoolInfo.StoragePoolState) StorageLayer(com.cloud.storage.StorageLayer) QemuImgFile(org.apache.cloudstack.utils.qemu.QemuImgFile) QemuImgException(org.apache.cloudstack.utils.qemu.QemuImgException) QemuImg(org.apache.cloudstack.utils.qemu.QemuImg)

Aggregations

PhysicalDiskFormat (org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 QemuImgException (org.apache.cloudstack.utils.qemu.QemuImgException)4 LibvirtException (org.libvirt.LibvirtException)4 RadosException (com.ceph.rados.exceptions.RadosException)3 RbdException (com.ceph.rbd.RbdException)3 StoragePoolType (com.cloud.storage.Storage.StoragePoolType)3 IoCTX (com.ceph.rados.IoCTX)2 Rados (com.ceph.rados.Rados)2 Rbd (com.ceph.rbd.Rbd)2 RbdImage (com.ceph.rbd.RbdImage)2 RbdImageInfo (com.ceph.rbd.jna.RbdImageInfo)2 InternalErrorException (com.cloud.exception.InternalErrorException)2 File (java.io.File)2 QemuImg (org.apache.cloudstack.utils.qemu.QemuImg)2 QemuImgFile (org.apache.cloudstack.utils.qemu.QemuImgFile)2 Test (org.junit.Test)2 ErrorCode (com.ceph.rados.exceptions.ErrorCode)1 RbdSnapInfo (com.ceph.rbd.jna.RbdSnapInfo)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1