Skip to content

Commit

Permalink
feat(xo-web/vm/disks): allow Self Service users to attach disks to th…
Browse files Browse the repository at this point in the history
…eir VMs (#8384)

See Zammad#30630
  • Loading branch information
pdonias authored Feb 27, 2025
1 parent 8063f43 commit db4d394
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

> Users must be able to say: “Nice enhancement, I'm eager to test it”
- [Self Service] Allow Self Service users to attach disks to their VMs (PR [#8384](https://github.com/vatesfr/xen-orchestra/pull/8384))

### Bug fixes

> Users must be able to say: “I had this issue, happy to know it's fixed”
Expand All @@ -31,4 +33,7 @@
<!--packages-start-->

- xo-server minor
- xo-web minor

<!--packages-end-->
8 changes: 8 additions & 0 deletions packages/xo-server/src/api/vbd.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

async function delete_({ vbd }) {
await this.getXapiObject(vbd).$destroy()

const vdi = this.getObject(vbd.VDI)
const vm = this.getObject(vbd.VM)

const { resourceSet } = vm
if (resourceSet != null) {
await this.releaseLimitsInResourceSet({ disk: vdi.size }, resourceSet)
}
}

delete_.params = {
Expand Down
11 changes: 9 additions & 2 deletions packages/xo-server/src/api/vm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,15 +1557,22 @@ importMultipleFromEsxi.params = {

// FIXME: if position is used, all other disks after this position
// should be shifted.
export async function attachDisk({ vm, vdi, position, mode, bootable }) {
export const attachDisk = defer(async function ($defer, { vm, vdi, position, mode, bootable }) {
const { resourceSet } = vm
if (resourceSet != null) {
await this.checkResourceSetConstraints(resourceSet, this.apiContext.user.id, [vdi.$SR])
await this.allocateLimitsInResourceSet({ disk: vdi.size }, resourceSet)
$defer.onFailure(() => this.releaseLimitsInResourceSet({ disk: vdi.size }, resourceSet))
}

await this.getXapi(vm).VBD_create({
bootable,
mode,
userdevice: position,
VDI: vdi._xapiRef,
VM: vm._xapiRef,
})
}
})

attachDisk.params = {
bootable: {
Expand Down
27 changes: 6 additions & 21 deletions packages/xo-web/src/xo-app/vm/tab-disks.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,19 +621,6 @@ export default class TabDisks extends Component {
}, noop)
}

_getIsVmAdmin = createSelector(
() => this.props.checkPermissions,
() => this.props.vm && this.props.vm.id,
(check, vmId) => check(vmId, 'administrate')
)

_getAttachDiskPredicate = createSelector(
() => this.props.isAdmin,
() => this.props.vm.resourceSet,
this._getIsVmAdmin,
(isAdmin, resourceSet, isVmAdmin) => isAdmin || (resourceSet == null && isVmAdmin)
)

_getRequiredHost = createSelector(
this._areSrsOnSameHost,
this._getVdiSrs,
Expand Down Expand Up @@ -744,14 +731,12 @@ export default class TabDisks extends Component {
icon='add'
labelId='vbdCreateDeviceButton'
/>
{this._getAttachDiskPredicate() && (
<TabButton
btnStyle={attachDisk ? 'info' : 'primary'}
handler={this._toggleAttachDisk}
icon='disk'
labelId='vdiAttachDevice'
/>
)}
<TabButton
btnStyle={attachDisk ? 'info' : 'primary'}
handler={this._toggleAttachDisk}
icon='disk'
labelId='vdiAttachDevice'
/>
</Col>
</Row>
<Row>
Expand Down

0 comments on commit db4d394

Please sign in to comment.