Search in sources :

Example 6 with Snapshot

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

the class VmSnapshotListModel method onCloneVM.

private void onCloneVM() {
    UnitVmModel model = (UnitVmModel) getWindow();
    CloneVmFromSnapshotModelBehavior behavior = (CloneVmFromSnapshotModelBehavior) model.getBehavior();
    Snapshot snapshot = getSelectedItem();
    if (snapshot == null) {
        cancel();
        return;
    }
    if (!model.validate()) {
        return;
    }
    VM vm = behavior.getVm();
    // Save changes.
    buildVmOnClone(model, vm);
    vm.setUseHostCpuFlags(model.getHostCpu().getEntity());
    vm.setDiskMap(behavior.getVm().getDiskMap());
    HashMap<Guid, DiskImage> imageToDestinationDomainMap = model.getDisksAllocationModel().getImageToDestinationDomainMap();
    AddVmFromSnapshotParameters parameters = new AddVmFromSnapshotParameters(vm.getStaticData(), snapshot.getId());
    parameters.setDiskInfoDestinationMap(imageToDestinationDomainMap);
    parameters.setConsoleEnabled(model.getIsConsoleDeviceEnabled().getEntity());
    parameters.setVirtioScsiEnabled(model.getIsVirtioScsiEnabled().getEntity());
    parameters.setBalloonEnabled(model.getMemoryBalloonDeviceEnabled().getEntity());
    BuilderExecutor.build(model, parameters, new UnitToGraphicsDeviceParamsBuilder());
    if (!StringHelper.isNullOrEmpty(model.getVmId().getEntity())) {
        parameters.setVmId(new Guid(model.getVmId().getEntity()));
    }
    model.startProgress();
    Frontend.getInstance().runAction(ActionType.AddVmFromSnapshot, parameters, result -> {
        VmSnapshotListModel vmSnapshotListModel = (VmSnapshotListModel) result.getState();
        vmSnapshotListModel.getWindow().stopProgress();
        ActionReturnValue returnValueBase = result.getReturnValue();
        if (returnValueBase != null && returnValueBase.getSucceeded()) {
            vmSnapshotListModel.cancel();
            vmSnapshotListModel.updateActionAvailability();
        }
    }, this);
}
Also used : UnitToGraphicsDeviceParamsBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.UnitToGraphicsDeviceParamsBuilder) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VM(org.ovirt.engine.core.common.businessentities.VM) Guid(org.ovirt.engine.core.compat.Guid) AddVmFromSnapshotParameters(org.ovirt.engine.core.common.action.AddVmFromSnapshotParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 7 with Snapshot

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

the class ImportVmCommand method removeVmSnapshots.

@Override
protected void removeVmSnapshots() {
    Guid vmId = getVmId();
    List<Snapshot> removedSnapshots = getSnapshotsManager().removeSnapshots(vmId);
    for (Snapshot snapshot : removedSnapshots) {
        removeMemoryVolumes(snapshot, vmId);
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) Guid(org.ovirt.engine.core.compat.Guid)

Example 8 with Snapshot

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

the class ImportVmCommand method addActiveSnapshot.

/**
 * Saves a new active snapshot for the VM
 *
 * @param snapshotId
 *            The ID to assign to the snapshot
 * @return The generated snapshot
 */
protected Snapshot addActiveSnapshot(Guid snapshotId) {
    Snapshot activeSnapshot = getActiveSnapshot();
    // We currently don't support using memory from a
    // snapshot that was taken for VM with different id
    boolean importMemory = activeSnapshot != null && activeSnapshot.containsMemory() && !getParameters().isImportAsNewEntity();
    return getSnapshotsManager().addActiveSnapshot(snapshotId, getVm(), SnapshotStatus.OK, importMemory ? getActiveSnapshot().getMemoryDiskId() : null, importMemory ? getActiveSnapshot().getMetadataDiskId() : null, getCompensationContext());
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot)

Example 9 with Snapshot

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

the class ImportVmCommand method copyAllMemoryImages.

private void copyAllMemoryImages(Guid containerId) {
    Set<Guid> handledMemoryDisks = new HashSet<>();
    for (Snapshot snapshot : getVm().getSnapshots()) {
        if (!snapshot.containsMemory()) {
            continue;
        }
        Guid memoryDiskId = snapshot.getMemoryDiskId();
        if (!handledMemoryDisks.contains(memoryDiskId)) {
            handledMemoryDisks.add(memoryDiskId);
            // copy the memory dump image
            ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, buildMoveOrCopyImageGroupParametersForMemoryDumpImage(containerId, memoryDiskDomainMap.get(memoryDiskId), memoryDiskId, getMemoryDiskImageId(memoryDiskId)));
            if (!vdcRetValue.getSucceeded()) {
                throw new EngineException(vdcRetValue.getFault().getError(), "Failed to copy memory image");
            }
            // TODO: Currently REST-API doesn't support coco for async commands, remove when bug 1199011 fixed
            getTaskIdList().addAll(vdcRetValue.getVdsmTaskIdList());
        }
        Guid confDiskId = snapshot.getMetadataDiskId();
        if (!handledMemoryDisks.contains(confDiskId)) {
            handledMemoryDisks.add(confDiskId);
            // copy the memory configuration (of the VM) image
            ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, buildMoveOrCopyImageGroupParametersForMemoryConfImage(containerId, memoryDiskDomainMap.get(confDiskId), confDiskId, getMemoryDiskImageId(confDiskId)));
            if (!vdcRetValue.getSucceeded()) {
                throw new EngineException(vdcRetValue.getFault().getError(), "Failed to copy metadata image");
            }
            // TODO: Currently REST-API doesn't support coco for async commands, remove when bug 1199011 fixed
            getTaskIdList().addAll(vdcRetValue.getVdsmTaskIdList());
        }
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) HashSet(java.util.HashSet)

Example 10 with Snapshot

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

the class ImportVmCommand method addVmImagesAndSnapshots.

protected void addVmImagesAndSnapshots() {
    Map<Guid, List<DiskImage>> images = ImagesHandler.getImagesLeaf(getImages());
    if (isCopyCollapseOrNoSnapshots()) {
        Guid snapshotId = Guid.newGuid();
        int aliasCounter = 0;
        for (List<DiskImage> diskList : images.values()) {
            DiskImage disk = getActiveVolumeDisk(diskList);
            disk.setParentId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
            disk.setImageTemplateId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
            disk.setVmSnapshotId(snapshotId);
            disk.setActive(true);
            if (getParameters().getVm().getDiskMap() != null && getParameters().getVm().getDiskMap().containsKey(disk.getId())) {
                DiskImageBase diskImageBase = (DiskImageBase) getParameters().getVm().getDiskMap().get(disk.getId());
                disk.setVolumeFormat(diskImageBase.getVolumeFormat());
                disk.setVolumeType(diskImageBase.getVolumeType());
            }
            setDiskStorageDomainInfo(disk);
            if (getParameters().isImportAsNewEntity()) {
                generateNewDiskId(diskList, disk);
                updateManagedDeviceMap(disk, getVm().getStaticData().getManagedDeviceMap());
            } else {
                newDiskIdForDisk.put(disk.getId(), disk);
            }
            disk.setCreationDate(new Date());
            saveImage(disk);
            ImagesHandler.setDiskAlias(disk, getVm(), ++aliasCounter);
            saveBaseDisk(disk);
            saveDiskVmElement(disk.getId(), getVmId(), disk.getDiskVmElementForVm(getParameters().getVmId()));
            saveDiskImageDynamic(disk);
        }
        Snapshot snapshot = addActiveSnapshot(snapshotId);
        getVm().setSnapshots(Arrays.asList(snapshot));
    } else {
        Guid snapshotId = null;
        for (DiskImage disk : getImages()) {
            disk.setActive(false);
            setDiskStorageDomainInfo(disk);
            saveImage(disk);
            snapshotId = disk.getVmSnapshotId();
            saveSnapshotIfNotExists(snapshotId, disk);
            saveDiskImageDynamic(disk);
        }
        int aliasCounter = 0;
        for (List<DiskImage> diskList : images.values()) {
            DiskImage disk = getActiveVolumeDisk(diskList);
            newDiskIdForDisk.put(disk.getId(), disk);
            snapshotId = disk.getVmSnapshotId();
            disk.setActive(true);
            ImagesHandler.setDiskAlias(disk, getVm(), ++aliasCounter);
            updateImage(disk);
            saveBaseDisk(disk);
            saveDiskVmElement(disk.getId(), getVmId(), disk.getDiskVmElementForVm(getParameters().getVmId()));
        }
        // Update active snapshot's data, since it was inserted as a regular snapshot.
        updateActiveSnapshot(snapshotId);
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) DiskImageBase(org.ovirt.engine.core.common.businessentities.storage.DiskImageBase) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Date(java.util.Date)

Aggregations

Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)96 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)33 VM (org.ovirt.engine.core.common.businessentities.VM)32 Guid (org.ovirt.engine.core.compat.Guid)30 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)15 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)12 List (java.util.List)11 SnapshotStatus (org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus)9 Collections (java.util.Collections)8 Date (java.util.Date)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 SnapshotType (org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType)8 EngineException (org.ovirt.engine.core.common.errors.EngineException)8 ActionType (org.ovirt.engine.core.common.action.ActionType)7 DiskStorageType (org.ovirt.engine.core.common.businessentities.storage.DiskStorageType)6 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5