Search in sources :

Example 26 with StoragePoolType

use of com.cloud.storage.Storage.StoragePoolType 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 27 with StoragePoolType

use of com.cloud.storage.Storage.StoragePoolType in project cloudstack by apache.

the class KVMStoragePoolManager method getStoragePoolByURI.

public KVMStoragePool getStoragePoolByURI(String uri) {
    URI storageUri = null;
    try {
        storageUri = new URI(uri);
    } catch (URISyntaxException e) {
        throw new CloudRuntimeException(e.toString());
    }
    String sourcePath = null;
    String uuid = null;
    String sourceHost = "";
    StoragePoolType protocol = null;
    if (storageUri.getScheme().equalsIgnoreCase("nfs") || storageUri.getScheme().equalsIgnoreCase("NetworkFilesystem")) {
        sourcePath = storageUri.getPath();
        sourcePath = sourcePath.replace("//", "/");
        sourceHost = storageUri.getHost();
        uuid = UUID.nameUUIDFromBytes(new String(sourceHost + sourcePath).getBytes()).toString();
        protocol = StoragePoolType.NetworkFilesystem;
    }
    // secondary storage registers itself through here
    return createStoragePool(uuid, sourceHost, 0, sourcePath, "", protocol, false);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

StoragePoolType (com.cloud.storage.Storage.StoragePoolType)27 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)13 Test (org.junit.Test)10 URISyntaxException (java.net.URISyntaxException)6 URI (java.net.URI)5 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)5 LibvirtException (org.libvirt.LibvirtException)5 StoragePool (org.libvirt.StoragePool)5 Map (java.util.Map)4 Connect (org.libvirt.Connect)4 HostVO (com.cloud.host.HostVO)3 HashSet (java.util.HashSet)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 LibvirtStoragePoolDef (com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 LinkedList (java.util.LinkedList)2 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)2 PrimaryDataStoreParameters (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreParameters)2 StrategyPriority (org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority)2 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)2