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);
}
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);
}
}
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());
}
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());
}
}
}
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);
}
}
Aggregations