use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class VmSnapshotListModel method updateActionAvailability.
public void updateActionAvailability() {
if (getItems() == null) {
// no need to update action availability
return;
}
VM vm = getEntity();
Snapshot snapshot = getSelectedItem();
List<VM> vmList = vm != null ? Collections.singletonList(vm) : Collections.emptyList();
boolean isVmDown = vm != null && vm.getStatus() == VMStatus.Down;
boolean isVmImageLocked = vm != null && vm.getStatus() == VMStatus.ImageLocked;
boolean isVmQualifiedForSnapshotMerge = vm != null && vm.getStatus().isQualifiedForSnapshotMerge();
boolean isPreviewing = getItems().stream().anyMatch(s -> s.getStatus() == SnapshotStatus.IN_PREVIEW);
boolean isLocked = getItems().stream().anyMatch(s -> s.getStatus() == SnapshotStatus.LOCKED);
boolean isSelected = snapshot != null && snapshot.getType() != SnapshotType.ACTIVE;
boolean isStateless = getItems().stream().anyMatch(s -> s.getType() == SnapshotType.STATELESS);
boolean isVmConfigurationBroken = snapshot != null && snapshot.isVmConfigurationBroken();
getCanSelectSnapshot().setEntity(!isPreviewing && !isLocked && !isStateless && ActionUtils.canExecute(vmList, VM.class, ActionType.CreateSnapshotForVm));
getNewCommand().setIsExecutionAllowed(!isPreviewing && !isLocked && !isVmImageLocked && !isStateless);
getPreviewCommand().setIsExecutionAllowed(isSelected && !isLocked && !isPreviewing && isVmDown && !isStateless);
getCustomPreviewCommand().setIsExecutionAllowed(getPreviewCommand().getIsExecutionAllowed());
getCommitCommand().setIsExecutionAllowed(isPreviewing && isVmDown && !isStateless);
getUndoCommand().setIsExecutionAllowed(isPreviewing && isVmDown && !isStateless);
getRemoveCommand().setIsExecutionAllowed(isSelected && !isLocked && !isPreviewing && !isStateless && isVmQualifiedForSnapshotMerge);
getCloneVmCommand().setIsExecutionAllowed(isSelected && !isLocked && !isPreviewing && !isVmImageLocked && !isStateless && !isVmConfigurationBroken);
getCloneTemplateCommand().setIsExecutionAllowed(isSelected && !isLocked && !isPreviewing && !isVmImageLocked && !isStateless && !isVmConfigurationBroken);
}
use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class VmSnapshotListModel method onPreview.
private void onPreview() {
Snapshot snapshot = getSelectedItem();
if (snapshot == null) {
cancel();
return;
}
VM vm = getEntity();
SnapshotModel snapshotModel = (SnapshotModel) getWindow();
boolean memory = false;
List<DiskImage> disks = null;
if (snapshotModel.isShowPartialSnapshotWarning()) {
switch(snapshotModel.getPartialPreviewSnapshotOptions().getSelectedItem()) {
case preserveActiveDisks:
// get snapshot disks
disks = snapshotModel.getDisks();
// add active disks missed from snapshot
disks.addAll(imagesSubtract(getVmDisks(), disks));
break;
case excludeActiveDisks:
// nothing to do - default behaviour
break;
case openCustomPreviewDialog:
setWindow(null);
getCustomPreviewCommand().execute();
return;
}
}
if (snapshotModel.isShowMemorySnapshotWarning()) {
memory = snapshotModel.getMemory().getEntity();
}
runTryBackToAllSnapshotsOfVm(snapshotModel, vm, snapshot, memory, disks, true, null);
}
use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class VmSnapshotListModel method customPreview.
private void customPreview() {
VM vm = getEntity();
if (vm == null) {
return;
}
PreviewSnapshotModel model = new PreviewSnapshotModel(vm, getSelectedItem().getId());
model.setVmId(vm.getId());
model.initialize();
// Update according to the selected snapshot
Snapshot selectedSnapshot = getSelectedItem();
if (selectedSnapshot != null) {
model.setSnapshotModel(getSnapshotsMap().get(selectedSnapshot.getId()));
}
setWindow(model);
model.setTitle(ConstantsManager.getInstance().getConstants().customPreviewSnapshotTitle());
model.setHelpTag(HelpTag.custom_preview_snapshot);
// $NON-NLS-1$
model.setHashName("custom_preview_snapshot");
// $NON-NLS-1$
addCommands(model, "OnCustomPreview");
}
use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class VmSnapshotListModel method cloneTemplate.
private void cloneTemplate() {
Snapshot snapshot = getSelectedItem();
if (snapshot == null) {
return;
}
if (getWindow() != null) {
return;
}
final UnitVmModel model = new UnitVmModel(createNewTemplateBehavior(), this);
setWindow(model);
model.startProgress();
AsyncDataProvider.getInstance().getVmConfigurationBySnapshot(new AsyncQuery<>(vm -> {
NewTemplateVmModelBehavior behavior = (NewTemplateVmModelBehavior) model.getBehavior();
behavior.setVm(vm);
model.setTitle(ConstantsManager.getInstance().getConstants().newTemplateTitle());
model.setHelpTag(HelpTag.clone_template_from_snapshot);
// $NON-NLS-1$
model.setHashName("clone_template_from_snapshot");
model.setIsNew(true);
model.setCustomPropertiesKeysList(AsyncDataProvider.getInstance().getCustomPropertiesList());
model.initialize();
model.getVmType().setSelectedItem(vm.getVmType());
model.getIsHighlyAvailable().setEntity(vm.getStaticData().isAutoStartup());
model.getCommands().add(// $NON-NLS-1$
new UICommand("OnNewTemplate", VmSnapshotListModel.this).setTitle(ConstantsManager.getInstance().getConstants().ok()).setIsDefault(true));
// $NON-NLS-1$
model.getCommands().add(UICommand.createCancelUiCommand("Cancel", VmSnapshotListModel.this));
model.stopProgress();
}), snapshot.getId());
}
use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class VmSnapshotListModel method cloneVM.
private void cloneVM() {
Snapshot snapshot = getSelectedItem();
if (snapshot == null) {
return;
}
if (getWindow() != null) {
return;
}
VM selectedVm = getEntity();
UnitVmModel model = new UnitVmModel(new CloneVmFromSnapshotModelBehavior(), this);
model.getVmType().setSelectedItem(selectedVm.getVmType());
// $NON-NLS-1$
model.setIsAdvancedModeLocalStorageKey("wa_snapshot_dialog");
setWindow(model);
model.startProgress();
AsyncDataProvider.getInstance().getVmConfigurationBySnapshot(new AsyncQuery<>(vm -> {
UnitVmModel unitVmModel = (UnitVmModel) getWindow();
CloneVmFromSnapshotModelBehavior behavior = (CloneVmFromSnapshotModelBehavior) unitVmModel.getBehavior();
behavior.setVm(vm);
unitVmModel.setTitle(ConstantsManager.getInstance().getConstants().cloneVmFromSnapshotTitle());
unitVmModel.setHelpTag(HelpTag.clone_vm_from_snapshot);
// $NON-NLS-1$
unitVmModel.setHashName("clone_vm_from_snapshot");
unitVmModel.setCustomPropertiesKeysList(AsyncDataProvider.getInstance().getCustomPropertiesList());
unitVmModel.initialize();
VmBasedWidgetSwitchModeCommand switchModeCommand = new VmBasedWidgetSwitchModeCommand();
switchModeCommand.init(unitVmModel);
unitVmModel.getCommands().add(switchModeCommand);
// $NON-NLS-1$
UICommand tempVar = UICommand.createDefaultOkUiCommand("OnCloneVM", VmSnapshotListModel.this);
unitVmModel.getCommands().add(tempVar);
// $NON-NLS-1$
UICommand tempVar2 = UICommand.createCancelUiCommand("Cancel", VmSnapshotListModel.this);
unitVmModel.getCommands().add(tempVar2);
stopProgress();
}), snapshot.getId());
}
Aggregations