fix(xo-web/vtpm): fix various an error has occured (#7122)
Introduced by8834af65f7
Introduced by1a1dd0531d
Fix `an error has occurred` in the VM advanced tab and on the VM creation form if the user does not have pool permission.
This commit is contained in:
parent
680f1e2f07
commit
77d9798319
@ -1667,14 +1667,22 @@ export const migrateVms = vms =>
|
|||||||
)
|
)
|
||||||
}, noop)
|
}, noop)
|
||||||
|
|
||||||
export const createVm = args => _call('vm.create', args)
|
export const createVm = async args => {
|
||||||
|
try {
|
||||||
|
return await _call('vm.create', args)
|
||||||
|
} catch (err) {
|
||||||
|
handlePoolDoesNotSupportVtpmError(err)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const createVms = (args, nameLabels, cloudConfigs) =>
|
export const createVms = async (args, nameLabels, cloudConfigs) => {
|
||||||
confirm({
|
await confirm({
|
||||||
title: _('newVmCreateVms'),
|
title: _('newVmCreateVms'),
|
||||||
body: _('newVmCreateVmsConfirm', { nbVms: nameLabels.length }),
|
body: _('newVmCreateVmsConfirm', { nbVms: nameLabels.length }),
|
||||||
}).then(() =>
|
})
|
||||||
Promise.all(
|
try {
|
||||||
|
return await Promise.all(
|
||||||
map(
|
map(
|
||||||
nameLabels,
|
nameLabels,
|
||||||
(
|
(
|
||||||
@ -1688,7 +1696,11 @@ export const createVms = (args, nameLabels, cloudConfigs) =>
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
} catch (error) {
|
||||||
|
handlePoolDoesNotSupportVtpmError(error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const getCloudInitConfig = template => _call('vm.getCloudInitConfig', { template })
|
export const getCloudInitConfig = template => _call('vm.getCloudInitConfig', { template })
|
||||||
|
|
||||||
@ -2156,8 +2168,26 @@ export const deleteAclRule = ({ protocol = undefined, port = undefined, ipRange
|
|||||||
})
|
})
|
||||||
|
|
||||||
// VTPM -----------------------------------------------------------
|
// VTPM -----------------------------------------------------------
|
||||||
|
const handlePoolDoesNotSupportVtpmError = err => {
|
||||||
|
if (
|
||||||
|
incorrectState.is(err, {
|
||||||
|
property: 'restrictions.restrict_vtpm',
|
||||||
|
expected: 'false',
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
console.error(err)
|
||||||
|
throw new Error('This pool does not support VTPM')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const createVtpm = vm => _call('vtpm.create', { id: resolveId(vm) })
|
export const createVtpm = async vm => {
|
||||||
|
try {
|
||||||
|
return await _call('vtpm.create', { id: resolveId(vm) })
|
||||||
|
} catch (err) {
|
||||||
|
handlePoolDoesNotSupportVtpmError(err)
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
export const deleteVtpm = vtpm => _call('vtpm.destroy', { id: resolveId(vtpm) })
|
export const deleteVtpm = vtpm => _call('vtpm.destroy', { id: resolveId(vtpm) })
|
||||||
|
|
||||||
// Network -----------------------------------------------------------
|
// Network -----------------------------------------------------------
|
||||||
|
@ -1576,7 +1576,7 @@ export default class NewVm extends BaseComponent {
|
|||||||
</label>
|
</label>
|
||||||
) : null
|
) : null
|
||||||
|
|
||||||
const isVtpmSupported = pool.vtpmSupported
|
const isVtpmSupported = pool?.vtpmSupported ?? true
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section icon='new-vm-advanced' title='newVmAdvancedPanel' done={this._isAdvancedDone()}>
|
<Section icon='new-vm-advanced' title='newVmAdvancedPanel' done={this._isAdvancedDone()}>
|
||||||
|
@ -457,7 +457,7 @@ export default class TabAdvanced extends Component {
|
|||||||
() => this.props.vm,
|
() => this.props.vm,
|
||||||
() => this.props.pool,
|
() => this.props.pool,
|
||||||
(vm, pool) => {
|
(vm, pool) => {
|
||||||
if (!pool.vtpmSupported) {
|
if (pool?.vtpmSupported === false) {
|
||||||
return _('vtpmNotSupported')
|
return _('vtpmNotSupported')
|
||||||
}
|
}
|
||||||
if (vm.boot.firmware !== 'uefi') {
|
if (vm.boot.firmware !== 'uefi') {
|
||||||
|
Loading…
Reference in New Issue
Block a user