Search in sources :

Example 1 with Storage

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

the class LibvirtHandleConfigDriveCommandWrapper method execute.

@Override
public Answer execute(final HandleConfigDriveIsoCommand command, final LibvirtComputingResource libvirtComputingResource) {
    String mountPoint = null;
    try {
        if (command.isCreate()) {
            LOG.debug("Creating config drive: " + command.getIsoFile());
            NetworkElement.Location location = NetworkElement.Location.PRIMARY;
            if (command.isHostCachePreferred()) {
                LOG.debug("Using the KVM host for config drive");
                mountPoint = libvirtComputingResource.getConfigPath();
                location = NetworkElement.Location.HOST;
            } else {
                final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
                KVMStoragePool pool = null;
                String poolUuid = null;
                Storage.StoragePoolType poolType = null;
                DataStoreTO dataStoreTO = command.getDestStore();
                if (dataStoreTO != null) {
                    if (dataStoreTO instanceof PrimaryDataStoreTO) {
                        PrimaryDataStoreTO primaryDataStoreTO = (PrimaryDataStoreTO) dataStoreTO;
                        poolType = primaryDataStoreTO.getPoolType();
                    } else {
                        poolType = Storage.StoragePoolType.NetworkFilesystem;
                    }
                    poolUuid = command.getDestStore().getUuid();
                    pool = storagePoolMgr.getStoragePool(poolType, poolUuid);
                }
                if (pool == null || poolType == null) {
                    return new HandleConfigDriveIsoAnswer(command, "Unable to create config drive, Pool " + (poolUuid != null ? poolUuid : "") + " not found");
                }
                if (pool.supportsConfigDriveIso()) {
                    LOG.debug("Using the pool: " + poolUuid + " for config drive");
                    mountPoint = pool.getLocalPath();
                } else if (command.getUseHostCacheOnUnsupportedPool()) {
                    LOG.debug("Config drive for KVM is not supported for pool type: " + poolType.toString() + ", using the KVM host");
                    mountPoint = libvirtComputingResource.getConfigPath();
                    location = NetworkElement.Location.HOST;
                } else {
                    LOG.debug("Config drive for KVM is not supported for pool type: " + poolType.toString());
                    return new HandleConfigDriveIsoAnswer(command, "Config drive for KVM is not supported for pool type: " + poolType.toString());
                }
            }
            Path isoPath = Paths.get(mountPoint, command.getIsoFile());
            File isoFile = new File(mountPoint, command.getIsoFile());
            if (command.getIsoData() == null) {
                return new HandleConfigDriveIsoAnswer(command, "Invalid config drive ISO data received");
            }
            if (isoFile.exists()) {
                LOG.debug("An old config drive iso already exists");
            }
            Files.createDirectories(isoPath.getParent());
            ConfigDriveBuilder.base64StringToFile(command.getIsoData(), mountPoint, command.getIsoFile());
            return new HandleConfigDriveIsoAnswer(command, location);
        } else {
            LOG.debug("Deleting config drive: " + command.getIsoFile());
            Path configDrivePath = null;
            if (command.isHostCachePreferred()) {
                // Check and delete config drive in host storage if exists
                mountPoint = libvirtComputingResource.getConfigPath();
                configDrivePath = Paths.get(mountPoint, command.getIsoFile());
                Files.deleteIfExists(configDrivePath);
            } else {
                final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
                KVMStoragePool pool = null;
                DataStoreTO dataStoreTO = command.getDestStore();
                if (dataStoreTO != null) {
                    if (dataStoreTO instanceof PrimaryDataStoreTO) {
                        PrimaryDataStoreTO primaryDataStoreTO = (PrimaryDataStoreTO) dataStoreTO;
                        Storage.StoragePoolType poolType = primaryDataStoreTO.getPoolType();
                        pool = storagePoolMgr.getStoragePool(poolType, command.getDestStore().getUuid());
                    } else {
                        pool = storagePoolMgr.getStoragePool(Storage.StoragePoolType.NetworkFilesystem, command.getDestStore().getUuid());
                    }
                }
                if (pool != null && pool.supportsConfigDriveIso()) {
                    mountPoint = pool.getLocalPath();
                    configDrivePath = Paths.get(mountPoint, command.getIsoFile());
                    Files.deleteIfExists(configDrivePath);
                }
            }
            return new HandleConfigDriveIsoAnswer(command);
        }
    } catch (final IOException e) {
        LOG.debug("Failed to handle config drive due to " + e.getMessage(), e);
        return new HandleConfigDriveIsoAnswer(command, "Failed due to exception: " + e.getMessage());
    } catch (final CloudRuntimeException e) {
        LOG.debug("Failed to handle config drive due to " + e.getMessage(), e);
        return new HandleConfigDriveIsoAnswer(command, "Failed due to exception: " + e.toString());
    }
}
Also used : Path(java.nio.file.Path) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) HandleConfigDriveIsoAnswer(com.cloud.agent.api.HandleConfigDriveIsoAnswer) IOException(java.io.IOException) NetworkElement(com.cloud.network.element.NetworkElement) Storage(com.cloud.storage.Storage) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) File(java.io.File)

Example 2 with Storage

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

the class StorageSystemDataMotionStrategy method setVolumeMigrationOptions.

/**
 * Prepare hosts for KVM live storage migration depending on volume type by setting MigrationOptions on destination volume:
 * - Linked clones (backing file on disk): Decide if template (backing file) should be copied to destination storage prior disk creation
 * - Full clones (no backing file): Take snapshot of the VM prior disk creation
 * Return this information
 */
protected void setVolumeMigrationOptions(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, VirtualMachineTO vmTO, Host srcHost, StoragePoolVO destStoragePool) {
    if (!destStoragePool.isManaged()) {
        String srcVolumeBackingFile = getVolumeBackingFile(srcVolumeInfo);
        String srcPoolUuid = srcVolumeInfo.getDataStore().getUuid();
        StoragePoolVO srcPool = _storagePoolDao.findById(srcVolumeInfo.getPoolId());
        Storage.StoragePoolType srcPoolType = srcPool.getPoolType();
        MigrationOptions migrationOptions;
        if (StringUtils.isNotBlank(srcVolumeBackingFile)) {
            migrationOptions = createLinkedCloneMigrationOptions(srcVolumeInfo, destVolumeInfo, srcVolumeBackingFile, srcPoolUuid, srcPoolType);
        } else {
            migrationOptions = createFullCloneMigrationOptions(srcVolumeInfo, vmTO, srcHost, srcPoolUuid, srcPoolType);
        }
        migrationOptions.setTimeout(StorageManager.KvmStorageOnlineMigrationWait.value());
        destVolumeInfo.setMigrationOptions(migrationOptions);
    }
}
Also used : Storage(com.cloud.storage.Storage) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) MigrationOptions(com.cloud.storage.MigrationOptions)

Example 3 with Storage

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

the class LibvirtCheckStorageAvailabilityWrapper method execute.

@Override
public Answer execute(CheckStorageAvailabilityCommand command, LibvirtComputingResource resource) {
    KVMStoragePoolManager storagePoolMgr = resource.getStoragePoolMgr();
    Map<String, Storage.StoragePoolType> poolsMap = command.getPoolsMap();
    for (String poolUuid : poolsMap.keySet()) {
        Storage.StoragePoolType type = poolsMap.get(poolUuid);
        s_logger.debug("Checking if storage pool " + poolUuid + " (" + type + ") is mounted on this host");
        try {
            KVMStoragePool storagePool = storagePoolMgr.getStoragePool(type, poolUuid);
            if (storagePool == null) {
                s_logger.info("Storage pool " + poolUuid + " is not available");
                return new Answer(command, false, "Storage pool " + poolUuid + " not available");
            }
        } catch (CloudRuntimeException e) {
            s_logger.info("Storage pool " + poolUuid + " is not available");
            return new Answer(command, e);
        }
    }
    return new Answer(command);
}
Also used : Answer(com.cloud.agent.api.Answer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) Storage(com.cloud.storage.Storage) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

Storage (com.cloud.storage.Storage)3 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)2 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 Answer (com.cloud.agent.api.Answer)1 HandleConfigDriveIsoAnswer (com.cloud.agent.api.HandleConfigDriveIsoAnswer)1 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)1 NetworkElement (com.cloud.network.element.NetworkElement)1 MigrationOptions (com.cloud.storage.MigrationOptions)1 StoragePoolType (com.cloud.storage.Storage.StoragePoolType)1 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)1