fix(xo-web/jobs/vm.revert): use the snapshot's id instead of the vm's id (#2685)

Fixes #2498
This commit is contained in:
badrAZ 2018-02-28 14:33:05 +01:00 committed by Julien Fontanet
parent c62cab39f1
commit 60085798f2
8 changed files with 101 additions and 5 deletions

View File

@ -1058,12 +1058,12 @@ export function revert ({ snapshot, snapshotBefore }) {
} }
revert.params = { revert.params = {
id: { type: 'string' }, snapshot: { type: 'string' },
snapshotBefore: { type: 'boolean', optional: true }, snapshotBefore: { type: 'boolean', optional: true },
} }
revert.resolve = { revert.resolve = {
snapshot: ['id', 'VM-snapshot', 'administrate'], snapshot: ['snapshot', 'VM-snapshot', 'administrate'],
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------

View File

@ -207,6 +207,7 @@ const messages = {
selectSshKey: 'Select SSH key(s)…', selectSshKey: 'Select SSH key(s)…',
selectSrs: 'Select SR(s)…', selectSrs: 'Select SR(s)…',
selectVms: 'Select VM(s)…', selectVms: 'Select VM(s)…',
selectVmSnapshots: 'Select snapshot(s)…',
selectVmTemplates: 'Select VM template(s)…', selectVmTemplates: 'Select VM template(s)…',
selectTags: 'Select tag(s)…', selectTags: 'Select tag(s)…',
selectVdis: 'Select disk(s)…', selectVdis: 'Select disk(s)…',

View File

@ -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( export const SelectHostVm = makeStoreSelect(
() => { () => {
const getHosts = createGetObjectsOfType('host') const getHosts = createGetObjectsOfType('host')

View File

@ -5,9 +5,11 @@ import XoHostInput from './xo-host-input'
import XoPoolInput from './xo-pool-input' import XoPoolInput from './xo-pool-input'
import XoRemoteInput from './xo-remote-input' import XoRemoteInput from './xo-remote-input'
import XoRoleInput from './xo-role-input' import XoRoleInput from './xo-role-input'
import xoSnapshotInput from './xo-snapshot-input'
import XoSrInput from './xo-sr-input' import XoSrInput from './xo-sr-input'
import XoSubjectInput from './xo-subject-input' import XoSubjectInput from './xo-subject-input'
import XoTagInput from './xo-tag-input' import XoTagInput from './xo-tag-input'
import XoVdiInput from './xo-vdi-input'
import XoVmInput from './xo-vm-input' import XoVmInput from './xo-vm-input'
import { getType, getXoType } from '../json-schema-input/helpers' import { getType, getXoType } from '../json-schema-input/helpers'
@ -18,9 +20,11 @@ const XO_TYPE_TO_COMPONENT = {
pool: XoPoolInput, pool: XoPoolInput,
remote: XoRemoteInput, remote: XoRemoteInput,
role: XoRoleInput, role: XoRoleInput,
snapshot: xoSnapshotInput,
sr: XoSrInput, sr: XoSrInput,
subject: XoSubjectInput, subject: XoSubjectInput,
tag: XoTagInput, tag: XoTagInput,
vdi: XoVdiInput,
vm: XoVmInput, vm: XoVmInput,
xoobject: XoHighLevelObjectInput, xoobject: XoHighLevelObjectInput,
} }

View File

@ -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 (
<PrimitiveInputWrapper {...props}>
<SelectVmSnapshot
disabled={props.disabled}
hasSelectAll
multi={props.multi}
onChange={this._onChange}
ref='input'
required={props.required}
value={props.value}
/>
</PrimitiveInputWrapper>
)
}
}

View File

@ -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 (
<PrimitiveInputWrapper {...props}>
<SelectVdi
disabled={props.disabled}
hasSelectAll
multi={props.multi}
onChange={this._onChange}
ref='input'
required={props.required}
value={props.value}
/>
</PrimitiveInputWrapper>
)
}
}

View File

@ -1118,12 +1118,13 @@ export const importDeltaBackup = ({ remote, file, sr, mapVdisSrs }) =>
) )
import RevertSnapshotModalBody from './revert-snapshot-modal' // eslint-disable-line import/first import RevertSnapshotModalBody from './revert-snapshot-modal' // eslint-disable-line import/first
export const revertSnapshot = vm => export const revertSnapshot = snapshot =>
confirm({ confirm({
title: _('revertVmModalTitle'), title: _('revertVmModalTitle'),
body: <RevertSnapshotModalBody />, body: <RevertSnapshotModalBody />,
}).then( }).then(
snapshotBefore => _call('vm.revert', { id: resolveId(vm), snapshotBefore }), snapshotBefore =>
_call('vm.revert', { snapshot: resolveId(snapshot), snapshotBefore }),
noop noop
) )

View File

@ -186,9 +186,12 @@ export default class Jobs extends Component {
const titles = { const titles = {
Host: 'Host(s)', Host: 'Host(s)',
Pool: 'Pool(s)', Pool: 'Pool(s)',
Remote: 'Remote(s)',
Role: 'Role(s)', Role: 'Role(s)',
Snapshot: 'Snapshot(s)',
Sr: 'Storage(s)', Sr: 'Storage(s)',
Subject: 'Subject(s)', Subject: 'Subject(s)',
Vdi: 'Vdi(s)',
Vm: 'VM(s)', Vm: 'VM(s)',
XoObject: 'Object(s)', XoObject: 'Object(s)',
} }
@ -220,13 +223,25 @@ export default class Jobs extends Component {
modifyProperty(property, 'Sr') modifyProperty(property, 'Sr')
} else if ( } else if (
includes( includes(
['host', 'host_id', 'target_host_id', 'targetHost'], [
'affinityHost',
'host',
'host_id',
'target_host_id',
'targetHost',
],
key key
) )
) { ) {
modifyProperty(property, 'Host') modifyProperty(property, 'Host')
} else if (includes(['vm'], key)) { } else if (includes(['vm'], key)) {
modifyProperty(property, 'Vm') 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')
} }
} }
} }