Skip to content

Commit

Permalink
feat(xo-web/tab-advanced): allow to update VM creator (#7276)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pizzosaure committed Jan 19, 2024
1 parent a624330 commit f024238
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [Sign in] Support _Remember me_ feature with external providers (PR [#7298](https://github.com/vatesfr/xen-orchestra/pull/7298))
- [Pool/Host] Add a warning if hosts do not have the same version within a pool [#7059](https://github.com/vatesfr/xen-orchestra/issues/7059) (PR [#7280](https://github.com/vatesfr/xen-orchestra/pull/7280))
- [Plugins] Loading, or unloading, will respectively enable, or disable, _Auto-load at server start_, this should lead to least surprising behaviors (PR [#7317](https://github.com/vatesfr/xen-orchestra/pull/7317))
- [VM/Advanced] Admin can change VM creator [Forum#7313](https://xcp-ng.org/forum/topic/7313/change-created-by-and-date-information) (PR [#7276](https://github.com/vatesfr/xen-orchestra/pull/7276))

### Bug fixes

Expand Down
15 changes: 15 additions & 0 deletions packages/xo-server/src/api/vm.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as multiparty from 'multiparty'
import * as xoData from '@xen-orchestra/xapi/xoData.mjs'
import assignWith from 'lodash/assignWith.js'
import { asyncEach } from '@vates/async-each'
import asyncMapSettled from '@xen-orchestra/async-map/legacy.js'
Expand Down Expand Up @@ -655,6 +656,12 @@ export const set = defer(async function ($defer, params) {
await this.getXapiObject(VM).update_xenstore_data(mapKeys(xenStoreData, (v, k) => autoPrefix('vm-data/', k)))
}

const creation = extract(params, 'creation')
if (creation !== undefined) {
const xapiVm = await this.getXapiObject(VM)
await xoData.set(xapiVm, { creation: { ...VM.creation, ...creation } })
}

return xapi.editVm(vmId, params, async (limits, vm) => {
const resourceSet = xapi.xo.getData(vm, 'resourceSet')

Expand Down Expand Up @@ -755,6 +762,14 @@ set.params = {

blockedOperations: { type: 'object', optional: true, properties: { '*': { type: ['boolean', 'null', 'string'] } } },

creation: {
type: 'object',
optional: true,
properties: {
user: { type: 'string', optional: true },
},
},

suspendSr: { type: ['string', 'null'], optional: true },

xenStoreData: {
Expand Down
2 changes: 2 additions & 0 deletions packages/xo-web/src/common/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,7 @@ const messages = {
vmLimitsLabel: 'VM limits',
resourceSet: 'Resource set',
resourceSetNone: 'None',
selectUser: 'Select user',
suspendSr: 'Suspend SR',
viridian: 'Viridian',
vmCpuLimitsLabel: 'CPU limits',
Expand Down Expand Up @@ -1454,6 +1455,7 @@ const messages = {
removeAcl: 'Delete',
moreAcls: '{nAcls, number} more…',
vmBootFirmware: 'Boot firmware',
vmCreator: 'VM creator',
vmDefaultBootFirmwareLabel: 'default (bios)',
vmBootFirmwareWarningMessage:
"You're about to change your boot firmware. This is still experimental in CH/XCP-ng 8.0. Are you sure you want to continue?",
Expand Down
13 changes: 13 additions & 0 deletions packages/xo-web/src/common/select-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,19 @@ export const SelectSubject = makeSubscriptionSelect(
{ placeholder: _('selectSubjects') }
)

export const SelectUser = makeSubscriptionSelect(
subscriber => {
const unsubscribeUsers = subscribeUsers(users => {
subscriber({
xoObjects: users,
})
})

return unsubscribeUsers
},
{ placeholder: _('selectUser') }
)

// ===================================================================

export const SelectRole = makeSubscriptionSelect(
Expand Down
10 changes: 9 additions & 1 deletion packages/xo-web/src/xo-app/vm/tab-advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { CustomFields } from 'custom-fields'
import { injectState, provideState } from 'reaclette'
import { Number, Select as EditableSelect, Size, Text, XoSelect } from 'editable'
import { Select, Toggle } from 'form'
import { SelectResourceSet, SelectRole, SelectSubject, SelectVgpuType } from 'select-objects'
import { SelectResourceSet, SelectRole, SelectSubject, SelectUser, SelectVgpuType } from 'select-objects'
import { addSubscriptions, connectStore, formatSize, getVirtualizationModeLabel, osFamily } from 'utils'
import { every, filter, find, isEmpty, keyBy, map, times, some, uniq } from 'lodash'
import {
Expand Down Expand Up @@ -487,6 +487,8 @@ export default class TabAdvanced extends Component {
return deleteVtpm(vtpm)
}

_updateUser = user => editVm(this.props.vm, { creation: { user: user.id } })

render() {
const { container, isAdmin, vgpus, vm, vmPool } = this.props
const isWarmMigrationAvailable = getXoaPlan().value >= PREMIUM.value
Expand Down Expand Up @@ -1023,6 +1025,12 @@ export default class TabAdvanced extends Component {
</td>
</tr>
)}
<tr>
<th>{_('vmCreator')}</th>
<td>
<SelectUser onChange={this._updateUser} value={vm.creation?.user} />
</td>
</tr>
</tbody>
</table>
</Col>
Expand Down

0 comments on commit f024238

Please sign in to comment.