From 60085798f28e05f6510ef72f736ce614481564b0 Mon Sep 17 00:00:00 2001 From: badrAZ Date: Wed, 28 Feb 2018 14:33:05 +0100 Subject: [PATCH] fix(xo-web/jobs/vm.revert): use the snapshot's id instead of the vm's id (#2685) Fixes #2498 --- packages/xo-server/src/api/vm.js | 4 +-- packages/xo-web/src/common/intl/messages.js | 1 + packages/xo-web/src/common/select-objects.js | 21 +++++++++++++++ .../src/common/xo-json-schema-input/index.js | 4 +++ .../xo-json-schema-input/xo-snapshot-input.js | 27 +++++++++++++++++++ .../xo-json-schema-input/xo-vdi-input.js | 27 +++++++++++++++++++ packages/xo-web/src/common/xo/index.js | 5 ++-- packages/xo-web/src/xo-app/jobs/new/index.js | 17 +++++++++++- 8 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 packages/xo-web/src/common/xo-json-schema-input/xo-snapshot-input.js create mode 100644 packages/xo-web/src/common/xo-json-schema-input/xo-vdi-input.js diff --git a/packages/xo-server/src/api/vm.js b/packages/xo-server/src/api/vm.js index 2622e3205..c91718c54 100644 --- a/packages/xo-server/src/api/vm.js +++ b/packages/xo-server/src/api/vm.js @@ -1058,12 +1058,12 @@ export function revert ({ snapshot, snapshotBefore }) { } revert.params = { - id: { type: 'string' }, + snapshot: { type: 'string' }, snapshotBefore: { type: 'boolean', optional: true }, } revert.resolve = { - snapshot: ['id', 'VM-snapshot', 'administrate'], + snapshot: ['snapshot', 'VM-snapshot', 'administrate'], } // ------------------------------------------------------------------- diff --git a/packages/xo-web/src/common/intl/messages.js b/packages/xo-web/src/common/intl/messages.js index e6a7d7384..819829102 100644 --- a/packages/xo-web/src/common/intl/messages.js +++ b/packages/xo-web/src/common/intl/messages.js @@ -207,6 +207,7 @@ const messages = { selectSshKey: 'Select SSH key(s)…', selectSrs: 'Select SR(s)…', selectVms: 'Select VM(s)…', + selectVmSnapshots: 'Select snapshot(s)…', selectVmTemplates: 'Select VM template(s)…', selectTags: 'Select tag(s)…', selectVdis: 'Select disk(s)…', diff --git a/packages/xo-web/src/common/select-objects.js b/packages/xo-web/src/common/select-objects.js index 4922c8256..69c20c32c 100644 --- a/packages/xo-web/src/common/select-objects.js +++ b/packages/xo-web/src/common/select-objects.js @@ -420,6 +420,27 @@ export const SelectVm = makeStoreSelect( // =================================================================== +export const SelectVmSnapshot = makeStoreSelect( + () => { + const getSnapshotsByVms = createGetObjectsOfType('VM-snapshot') + .filter(getPredicate) + .sort() + .groupBy('$snapshot_of') + + const getVms = createGetObjectsOfType('VM') + .pick(createSelector(getSnapshotsByVms, keys)) + .sort() + + return { + xoObjects: getSnapshotsByVms, + xoContainers: getVms, + } + }, + { placeholder: _('selectVmSnapshots') } +) + +// =================================================================== + export const SelectHostVm = makeStoreSelect( () => { const getHosts = createGetObjectsOfType('host') diff --git a/packages/xo-web/src/common/xo-json-schema-input/index.js b/packages/xo-web/src/common/xo-json-schema-input/index.js index a8beaea02..688a4aefe 100644 --- a/packages/xo-web/src/common/xo-json-schema-input/index.js +++ b/packages/xo-web/src/common/xo-json-schema-input/index.js @@ -5,9 +5,11 @@ import XoHostInput from './xo-host-input' import XoPoolInput from './xo-pool-input' import XoRemoteInput from './xo-remote-input' import XoRoleInput from './xo-role-input' +import xoSnapshotInput from './xo-snapshot-input' import XoSrInput from './xo-sr-input' import XoSubjectInput from './xo-subject-input' import XoTagInput from './xo-tag-input' +import XoVdiInput from './xo-vdi-input' import XoVmInput from './xo-vm-input' import { getType, getXoType } from '../json-schema-input/helpers' @@ -18,9 +20,11 @@ const XO_TYPE_TO_COMPONENT = { pool: XoPoolInput, remote: XoRemoteInput, role: XoRoleInput, + snapshot: xoSnapshotInput, sr: XoSrInput, subject: XoSubjectInput, tag: XoTagInput, + vdi: XoVdiInput, vm: XoVmInput, xoobject: XoHighLevelObjectInput, } diff --git a/packages/xo-web/src/common/xo-json-schema-input/xo-snapshot-input.js b/packages/xo-web/src/common/xo-json-schema-input/xo-snapshot-input.js new file mode 100644 index 000000000..977155942 --- /dev/null +++ b/packages/xo-web/src/common/xo-json-schema-input/xo-snapshot-input.js @@ -0,0 +1,27 @@ +import React from 'react' + +import XoAbstractInput from './xo-abstract-input' +import { PrimitiveInputWrapper } from '../json-schema-input/helpers' +import { SelectVmSnapshot } from '../select-objects' + +// =================================================================== + +export default class snapshotInput extends XoAbstractInput { + render () { + const { props } = this + + return ( + + + + ) + } +} diff --git a/packages/xo-web/src/common/xo-json-schema-input/xo-vdi-input.js b/packages/xo-web/src/common/xo-json-schema-input/xo-vdi-input.js new file mode 100644 index 000000000..2806ece73 --- /dev/null +++ b/packages/xo-web/src/common/xo-json-schema-input/xo-vdi-input.js @@ -0,0 +1,27 @@ +import React from 'react' +import { SelectVdi } from 'select-objects' + +import XoAbstractInput from './xo-abstract-input' +import { PrimitiveInputWrapper } from '../json-schema-input/helpers' + +// =================================================================== + +export default class VdiInput extends XoAbstractInput { + render () { + const { props } = this + + return ( + + + + ) + } +} diff --git a/packages/xo-web/src/common/xo/index.js b/packages/xo-web/src/common/xo/index.js index 41a8122d6..312959566 100644 --- a/packages/xo-web/src/common/xo/index.js +++ b/packages/xo-web/src/common/xo/index.js @@ -1118,12 +1118,13 @@ export const importDeltaBackup = ({ remote, file, sr, mapVdisSrs }) => ) import RevertSnapshotModalBody from './revert-snapshot-modal' // eslint-disable-line import/first -export const revertSnapshot = vm => +export const revertSnapshot = snapshot => confirm({ title: _('revertVmModalTitle'), body: , }).then( - snapshotBefore => _call('vm.revert', { id: resolveId(vm), snapshotBefore }), + snapshotBefore => + _call('vm.revert', { snapshot: resolveId(snapshot), snapshotBefore }), noop ) diff --git a/packages/xo-web/src/xo-app/jobs/new/index.js b/packages/xo-web/src/xo-app/jobs/new/index.js index 344e0a5ca..c81c5fc2b 100644 --- a/packages/xo-web/src/xo-app/jobs/new/index.js +++ b/packages/xo-web/src/xo-app/jobs/new/index.js @@ -186,9 +186,12 @@ export default class Jobs extends Component { const titles = { Host: 'Host(s)', Pool: 'Pool(s)', + Remote: 'Remote(s)', Role: 'Role(s)', + Snapshot: 'Snapshot(s)', Sr: 'Storage(s)', Subject: 'Subject(s)', + Vdi: 'Vdi(s)', Vm: 'VM(s)', XoObject: 'Object(s)', } @@ -220,13 +223,25 @@ export default class Jobs extends Component { modifyProperty(property, 'Sr') } else if ( includes( - ['host', 'host_id', 'target_host_id', 'targetHost'], + [ + 'affinityHost', + 'host', + 'host_id', + 'target_host_id', + 'targetHost', + ], key ) ) { modifyProperty(property, 'Host') } else if (includes(['vm'], key)) { modifyProperty(property, 'Vm') + } else if (includes(['snapshot'], key)) { + modifyProperty(property, 'Snapshot') + } else if (includes(['remote', 'remoteId'], key)) { + modifyProperty(property, 'Remote') + } else if (includes(['vdi'], key)) { + modifyProperty(property, 'Vdi') } } }