Skip to content

Commit

Permalink
snapshots: Refresh VM after creating/reverting/deleting snapshots
Browse files Browse the repository at this point in the history
Managing external snapshots will change the source of the disks of the
VM.

Cherry-picked from main commit 5fb016a
  • Loading branch information
mvollmer authored and martinpitt committed May 1, 2024
1 parent 0fe1062 commit 77ddc73
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/components/vm/snapshots/vmSnapshotsCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { CheckIcon, InfoAltIcon } from '@patternfly/react-icons';
import { DeleteResourceButton } from '../../common/deleteResource.jsx';
import { RevertSnapshotModal } from './vmSnapshotsRevertModal.jsx';
import { snapshotDelete, snapshotGetAll } from '../../../libvirtApi/snapshot.js';
import { domainGet } from '../../../libvirtApi/domain.js';

import './vmSnapshotsCard.scss';

Expand Down Expand Up @@ -181,7 +182,12 @@ export class VmSnapshotsCard extends React.Component {
actionDescription: cockpit.format(_("Snapshot $0 will be deleted from $1. All of its captured content will be lost."), snap.name, vm.name),
deleteHandler: () => {
return snapshotDelete({ connectionName: vm.connectionName, domainPath: vm.id, snapshotName: snap.name })
.then(() => snapshotGetAll({ connectionName: vm.connectionName, domainPath: vm.id }));
.then(() => {
// Deleting an external snapshot might change the disk
// configuration of a VM without event.
domainGet({ connectionName: vm.connectionName, id: vm.id });
snapshotGetAll({ connectionName: vm.connectionName, domainPath: vm.id });
});
},
};

Expand Down
4 changes: 4 additions & 0 deletions src/components/vm/snapshots/vmSnapshotsCreateModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ModalError } from "cockpit-components-inline-notification.jsx";
import { FileAutoComplete } from "cockpit-components-file-autocomplete.jsx";
import { snapshotCreate, snapshotGetAll } from "../../../libvirtApi/snapshot.js";
import { getSortedBootOrderDevices, LIBVIRT_SYSTEM_CONNECTION } from "../../../helpers.js";
import { domainGet } from '../../../libvirtApi/domain.js';

const _ = cockpit.gettext;

Expand Down Expand Up @@ -166,6 +167,9 @@ export class CreateSnapshotModal extends React.Component {
.then(() => {
// VM Snapshots do not trigger any events so we have to refresh them manually
snapshotGetAll({ connectionName: vm.connectionName, domainPath: vm.id });
// Creating an external snapshot might change
// the disk configuration of a VM without event.
domainGet({ connectionName: vm.connectionName, id: vm.id });
Dialogs.close();
})
.catch(exc => {
Expand Down
22 changes: 15 additions & 7 deletions src/components/vm/snapshots/vmSnapshotsRevertModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import cockpit from 'cockpit';
import { DialogsContext } from 'dialogs.jsx';
import { ModalError } from 'cockpit-components-inline-notification.jsx';
import { snapshotRevert } from '../../../libvirtApi/snapshot.js';
import { domainGet } from '../../../libvirtApi/domain.js';

const _ = cockpit.gettext;

Expand Down Expand Up @@ -62,14 +63,21 @@ export class RevertSnapshotModal extends React.Component {
snapshotName: snap.name,
force: this.state.defaultRevertFailed
})
.then(Dialogs.close, exc => {
this.setState({
defaultRevertFailed: true,
inProgress: false,
inProgressForce: false
.then(
() => {
// Reverting an external snapshot might change the disk
// configuration of a VM without event.
domainGet({ connectionName: vm.connectionName, id: vm.id });
Dialogs.close();
},
exc => {
this.setState({
defaultRevertFailed: true,
inProgress: false,
inProgressForce: false
});
this.dialogErrorSet(_("Could not revert to snapshot"), exc.message);
});
this.dialogErrorSet(_("Could not revert to snapshot"), exc.message);
});
}

dialogErrorSet(text, detail) {
Expand Down

0 comments on commit 77ddc73

Please sign in to comment.