Skip to content

Commit

Permalink
webadmin: warn when cloning snapshot with memory
Browse files Browse the repository at this point in the history
When making a VM or a template from a snapshot with memory, the memory
is lost.  Moreover, the guest file system may be in an inconsistent
state without the memory.

This patch adds a confirmation dialog that is displayed
when user clicks Clone or Make Template buttons asking
if the user really wants to continue.

Bug-Url: https://bugzilla.redhat.com/1929376
  • Loading branch information
ljelinkova authored and smelamud committed Aug 11, 2022
1 parent a23b584 commit 2301a59
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public enum HelpTag {

clone_template_from_snapshot("clone_template_from_snapshot", HelpTagType.WEBADMIN, "VMs Tab > Snapshots Sub-Tab > Clone Template From Snapshot"), //$NON-NLS-1$ //$NON-NLS-2$

clone_snapshot_with_memory("clone_snapshot_with_memory", HelpTagType.WEBADMIN, "VMs Tab > Snapshots Sub-Tab > Clone VM/Template From Snapshot With Memory"), //$NON-NLS-1$ //$NON-NLS-2$

clusters("clusters", HelpTagType.UNKNOWN), //$NON-NLS-1$

configure("configure", HelpTagType.WEBADMIN, "Main > Configure"), //$NON-NLS-1$ //$NON-NLS-2$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider;
import org.ovirt.engine.ui.uicommonweb.help.HelpTag;
import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel;
import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModelChain;
import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModelChain.ConfirmationModelChainItem;
import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
import org.ovirt.engine.ui.uicommonweb.models.Model;
import org.ovirt.engine.ui.uicommonweb.models.SearchableListModel;
Expand Down Expand Up @@ -590,6 +592,12 @@ private void cancel() {
setWindow(null);
}

private void confirmClone(Runnable callback) {
ConfirmationModelChain chain = new ConfirmationModelChain();
chain.addConfirmation(createConfirmClone());
chain.execute(this, callback);
}

private void cloneTemplate() {
Snapshot snapshot = getSelectedItem();
if (snapshot == null) {
Expand Down Expand Up @@ -885,9 +893,9 @@ public void executeCommand(UICommand command) {
} else if (command == getRemoveCommand()) {
remove();
} else if (command == getCloneVmCommand()) {
cloneVM();
confirmClone(this::cloneVM);
} else if (command == getCloneTemplateCommand()) {
cloneTemplate();
confirmClone(this::cloneTemplate);
} else if ("OnNewTemplate".equals(command.getName())) { //$NON-NLS-1$
onCloneTemplate();
} else if ("OnRemove".equals(command.getName())) { //$NON-NLS-1$
Expand Down Expand Up @@ -915,4 +923,24 @@ protected boolean isSingleSelectionOnly() {
// Single selection model
return true;
}

private ConfirmationModelChainItem createConfirmClone() {
return new ConfirmationModelChainItem() {

@Override
public boolean isRequired() {
return getSelectedItem() != null && getSelectedItem().containsMemory();
}

@Override
public ConfirmationModel getConfirmation() {
ConfirmationModel confirmModel = new ConfirmationModel();
confirmModel.setTitle(ConstantsManager.getInstance().getConstants().cloneFromSnapshotWithMemoryConfirmationTitle());
confirmModel.setMessage(ConstantsManager.getInstance().getConstants().cloneFromSnapshotWithMemoryConfirmationText());
confirmModel.setHelpTag(HelpTag.clone_snapshot_with_memory);
confirmModel.setHashName("clone_snapshot_with_memory"); //$NON-NLS-1$
return confirmModel;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ public interface UIConstants extends Constants {

String cloneVmFromSnapshotTitle();

String cloneFromSnapshotWithMemoryConfirmationTitle();

String cloneFromSnapshotWithMemoryConfirmationText();

String youAreAboutChangeClusterCompatibilityVersionMsg();

String youAreAboutChangeClusterCompatibilityVersionNonResponsiveHostsMsg();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ cloneTitle=Clone
cloneVmFromSnapshotTitle=Clone VM from Snapshot
cloneVmLunsWontBeCloned=VM's LUN(s) will not be cloned.
cloneVmTitle=Clone Virtual Machine
cloneFromSnapshotWithMemoryConfirmationTitle=Snapshot contains memory
cloneFromSnapshotWithMemoryConfirmationText=The Snapshot contains memory that will not be preserved and the guest file system may end up in an inconsistent state.\nAre you sure you want to continue?
close=Close
cloudInitAttachmentTypeBase64=Base64
cloudInitAttachmentTypePlainText=Plain Text
Expand Down

0 comments on commit 2301a59

Please sign in to comment.