Search in sources :

Example 31 with CinderDisk

use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.

the class CreateCinderSnapshotCommand method cloneDisk.

private CinderDisk cloneDisk() {
    boolean isStateless = isStatelessSnapshot();
    CinderDisk cinderDependentVolume = getDisk();
    initCinderDependentVolume(cinderDependentVolume);
    cinderDependentVolume.setActive(isStateless);
    String volumeId = isStateless ? getCinderBroker().cloneDisk(cinderDependentVolume) : getCinderBroker().createSnapshot(cinderDependentVolume, getParameters().getDescription());
    cinderDependentVolume.setVolumeClassification(isStateless ? VolumeClassification.Volume : VolumeClassification.Snapshot);
    Guid destinationImageId = Guid.createGuidFromString(volumeId);
    getParameters().setDestinationImageId(destinationImageId);
    cinderDependentVolume.setImageId(destinationImageId);
    return cinderDependentVolume;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk)

Example 32 with CinderDisk

use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.

the class CreateCinderSnapshotCommand method executeCommand.

@Override
protected void executeCommand() {
    final CinderDisk newCinderVolume;
    newCinderVolume = cloneDisk();
    if (!isStatelessSnapshot()) {
        getDiskImage().setVmSnapshotId(getParameters().getVmSnapshotId());
    }
    TransactionSupport.executeInNewTransaction(() -> {
        processOldImageFromDb();
        addDiskImageToDb(newCinderVolume, getCompensationContext(), isStatelessSnapshot());
        setActionReturnValue(newCinderVolume);
        setSucceeded(true);
        return null;
    });
    getReturnValue().setActionReturnValue(newCinderVolume.getImageId());
    persistCommand(getParameters().getParentCommand(), true);
    setSucceeded(true);
}
Also used : CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk)

Example 33 with CinderDisk

use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.

the class ExtendCinderDiskCommand method performDiskUpdate.

protected void performDiskUpdate() {
    CinderDisk cinderDisk = (CinderDisk) getNewDisk();
    imageDao.updateImageSize(cinderDisk.getImageId(), cinderDisk.getSize());
    performDiskUpdate(true);
}
Also used : CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk)

Example 34 with CinderDisk

use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.

the class LibvirtVmXmlBuilder method writeDiskSource.

private void writeDiskSource(Disk disk, String dev) {
    writer.writeStartElement("source");
    switch(disk.getDiskStorageType()) {
        case IMAGE:
            DiskImage diskImage = (DiskImage) disk;
            // Change parameters for the HE disk
            if (vm.isHostedEngine()) {
                // Hosted engine disk images have to have empty storage pool ID,
                // so they can be mounted even if storage pool is not connected.
                diskImage.setStoragePoolId(Guid.Empty);
                diskImage.setPropagateErrors(PropagateErrors.Off);
                // The disk requires a lease
                addVolumeLease(diskImage.getImageId(), diskImage.getStorageIds().get(0));
            }
            String diskType = this.vmInfoBuildUtils.getDiskType(this.vm, diskImage);
            switch(diskType) {
                case "block":
                    writer.writeAttributeString("dev", vmInfoBuildUtils.getPathToImage(diskImage));
                    break;
                case "network":
                    String[] volInfo = vmInfoBuildUtils.getGlusterVolInfo(disk);
                    // drop to the 'file' case as a fallback.
                    if (volInfo != null) {
                        writer.writeAttributeString("protocol", "gluster");
                        writer.writeAttributeString("name", String.format("%s/%s/images/%s/%s", volInfo[1], diskImage.getStorageIds().get(0), diskImage.getId(), diskImage.getImageId()));
                        writer.writeStartElement("host");
                        writer.writeAttributeString("name", volInfo[0]);
                        writer.writeAttributeString("port", "0");
                        writer.writeEndElement();
                        break;
                    }
                case "file":
                    writer.writeAttributeString("file", vmInfoBuildUtils.getPathToImage(diskImage));
                    break;
            }
            diskMetadata.put(dev, createDiskParams(diskImage));
            break;
        case LUN:
            LunDisk lunDisk = (LunDisk) disk;
            writer.writeAttributeString("dev", String.format("/dev/mapper/%s", lunDisk.getLun().getLUNId()));
            diskMetadata.put(dev, Collections.singletonMap("GUID", lunDisk.getLun().getLUNId()));
            break;
        case CINDER:
            // case RBD
            CinderDisk cinderDisk = (CinderDisk) disk;
            Map<String, Object> connectionInfoData = cinderDisk.getCinderConnectionInfo().getData();
            writer.writeAttributeString("protocol", cinderDisk.getCinderConnectionInfo().getDriverVolumeType());
            writer.writeAttributeString("name", connectionInfoData.get("name").toString());
            List<String> hostAddresses = (List<String>) connectionInfoData.get("hosts");
            List<String> hostPorts = (List<String>) connectionInfoData.get("ports");
            // (Cinder should ensure that the addresses and ports lists are synced in order).
            for (int i = 0; i < hostAddresses.size(); i++) {
                writer.writeStartElement("host");
                writer.writeAttributeString("name", hostAddresses.get(i));
                writer.writeAttributeString("port", hostPorts.get(i));
                // If no transport is specified, "tcp" is assumed.
                writer.writeEndElement();
            }
            break;
    }
    writer.writeEndElement();
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk)

Example 35 with CinderDisk

use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.

the class UpdateVmDiskCommand method performDiskUpdate.

protected void performDiskUpdate(final boolean unlockImage) {
    if (shouldPerformMetadataUpdate()) {
        updateMetaDataDescription((DiskImage) getNewDisk());
    }
    final Disk diskForUpdate = diskDao.get(getParameters().getDiskInfo().getId());
    final DiskVmElement diskVmElementForUpdate = diskVmElementDao.get(new VmDeviceId(getOldDisk().getId(), getVmId()));
    applyUserChanges(diskForUpdate, diskVmElementForUpdate);
    TransactionSupport.executeInNewTransaction(new TransactionMethod<Object>() {

        @Override
        public Object runInTransaction() {
            vmStaticDao.incrementDbGeneration(getVm().getId());
            updateDeviceProperties();
            baseDiskDao.update(diskForUpdate);
            diskVmElementDao.update(diskVmElementForUpdate);
            switch(diskForUpdate.getDiskStorageType()) {
                case IMAGE:
                    DiskImage diskImage = (DiskImage) diskForUpdate;
                    diskImage.setQuotaId(getQuotaId());
                    if (unlockImage && diskImage.getImageStatus() == ImageStatus.LOCKED) {
                        diskImage.setImageStatus(ImageStatus.OK);
                    }
                    imageDao.update(diskImage.getImage());
                    updateQuota(diskImage);
                    updateDiskProfile();
                    break;
                case CINDER:
                    CinderDisk cinderDisk = (CinderDisk) diskForUpdate;
                    cinderDisk.setQuotaId(getQuotaId());
                    setStorageDomainId(cinderDisk.getStorageIds().get(0));
                    getCinderBroker().updateDisk(cinderDisk);
                    if (unlockImage && cinderDisk.getImageStatus() == ImageStatus.LOCKED) {
                        cinderDisk.setImageStatus(ImageStatus.OK);
                    }
                    imageDao.update(cinderDisk.getImage());
                    updateQuota(cinderDisk);
                    break;
                case LUN:
                    // No specific update for LUN disk
                    break;
            }
            reloadDisks();
            setSucceeded(true);
            // If necessary set the new Storage QoS values on running VMs asynchronously
            liveUpdateDiskProfile();
            return null;
        }

        private void updateDeviceProperties() {
            if (updateReadOnlyRequested()) {
                vmDeviceForVm.setReadOnly(getDiskVmElement().isReadOnly());
                vmDeviceDao.update(vmDeviceForVm);
            }
            if ((getOldDiskVmElement().getDiskInterface() != getDiskVmElement().getDiskInterface()) || ((getOldDiskVmElement().isBoot() != getDiskVmElement().isBoot()) && (getDiskVmElement().getDiskInterface() == DiskInterface.IDE))) {
                vmDeviceForVm.setAddress("");
                vmDeviceDao.clearDeviceAddress(getOldDisk().getId());
            }
        }
    });
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Aggregations

CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)74 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)28 Guid (org.ovirt.engine.core.compat.Guid)19 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)15 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)14 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)13 ArrayList (java.util.ArrayList)12 ImagesContainterParametersBase (org.ovirt.engine.core.common.action.ImagesContainterParametersBase)9 ExecutionException (java.util.concurrent.ExecutionException)7 VM (org.ovirt.engine.core.common.businessentities.VM)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ImageStatus (org.ovirt.engine.core.common.businessentities.storage.ImageStatus)5 Map (java.util.Map)4 Test (org.junit.Test)4 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)4 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)4 EngineException (org.ovirt.engine.core.common.errors.EngineException)4 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3