fix(xo-server/disk.create): handle resource set not found (#3530)

Fixes #2814
This commit is contained in:
Pierre Donias
2018-10-16 16:58:13 +02:00
committed by Julien Fontanet
parent 4d18ab1ae0
commit 6d20ef5d51
3 changed files with 26 additions and 11 deletions

View File

@@ -19,6 +19,7 @@
- [Remotes] Fix removal of broken remotes [#3327](https://github.com/vatesfr/xen-orchestra/issues/3327) (PR [#3521](https://github.com/vatesfr/xen-orchestra/pull/3521))
- [Backups] Fix stuck backups due to broken NFS remotes [#3467](https://github.com/vatesfr/xen-orchestra/issues/3467) (PR [#3534](https://github.com/vatesfr/xen-orchestra/pull/3534))
- [New VM] Fix missing cloud config when creating multiple VMs at once in some cases [#3532](https://github.com/vatesfr/xen-orchestra/issues/3532) (PR [#3535](https://github.com/vatesfr/xen-orchestra/pull/3535))
- [VM] Fix an error when an admin tried to add a disk on a Self VM whose resource set had been deleted [#2814](https://github.com/vatesfr/xen-orchestra/issues/2814)
### Released packages

View File

@@ -1,6 +1,6 @@
import pump from 'pump'
import { format } from 'json-rpc-peer'
import { unauthorized } from 'xo-common/api-errors'
import { noSuchObject, unauthorized } from 'xo-common/api-errors'
import { parseSize } from '../utils'
@@ -9,15 +9,29 @@ import { parseSize } from '../utils'
export async function create ({ name, size, sr, vm, bootable, position, mode }) {
const attach = vm !== undefined
let resourceSet
if (attach && (resourceSet = vm.resourceSet) != null) {
await this.checkResourceSetConstraints(resourceSet, this.user.id, [sr.id])
await this.allocateLimitsInResourceSet({ disk: size }, resourceSet)
} else if (
!(await this.hasPermissions(this.user.id, [[sr.id, 'administrate']]))
) {
throw unauthorized()
}
do {
let resourceSet
if (attach && (resourceSet = vm.resourceSet) != null) {
try {
await this.checkResourceSetConstraints(resourceSet, this.user.id, [
sr.id,
])
await this.allocateLimitsInResourceSet({ disk: size }, resourceSet)
break
} catch (error) {
if (!noSuchObject.is(error, { data: { id: resourceSet } })) {
throw error
}
}
// the resource set does not exist, falls back to normal check
}
if (!(await this.hasPermissions(this.user.id, [[sr.id, 'administrate']]))) {
throw unauthorized()
}
} while (false)
const xapi = this.getXapi(sr)
const vdi = await xapi.createVdi({

View File

@@ -327,7 +327,7 @@ class NewDisk extends Component {
icon='add'
btnStyle='primary'
handler={this._createDisk}
disabled={diskLimit < size}
disabled={!isAdmin && diskLimit < size}
>
{_('vbdCreate')}
</ActionButton>