feat(xo-server/rest-api): support setting name_label/name_description
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
- [Licenses] Makes `id` and `boundObjectId` copyable (PR [#6634](https://github.com/vatesfr/xen-orchestra/pull/6634))
|
||||
- [REST API] The raw content of a VDI can be downloaded directly
|
||||
- [Kubernetes recipe] Add the possibility to create the cluster with a static network configuration (PR [#6598](https://github.com/vatesfr/xen-orchestra/pull/6598))
|
||||
- [REST API] Ability to update the name and description of objects
|
||||
|
||||
### Bug fixes
|
||||
|
||||
|
||||
@@ -121,6 +121,20 @@ Content-Type: application/x-ndjson
|
||||
{"name_label":"Debian 10 Cloudinit self-service","power_state":"Halted","url":"/rest/v0/vms/5019156b-f40d-bc57-835b-4a259b177be1"}
|
||||
```
|
||||
|
||||
## Properties update
|
||||
|
||||
> This feature is restricted to `name_label` and `name_description` at the moment.
|
||||
|
||||
```bash
|
||||
curl \
|
||||
-X PATCH \
|
||||
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H 'Accept: application/json' \
|
||||
-d '{ "name_label": "The new name", "name_description": "The new description" }' \
|
||||
'https://xo.example.org/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac'
|
||||
```
|
||||
|
||||
## VM and VDI destruction
|
||||
|
||||
For a VM:
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
- [Authentication](#authentication)
|
||||
- [Collections](#collections)
|
||||
- [Properties update](#properties-update)
|
||||
- [VM destruction](#vm-destruction)
|
||||
- [VM Export](#vm-export)
|
||||
- [VDI destruction](#vdi-destruction)
|
||||
@@ -113,6 +114,20 @@ Content-Type: application/x-ndjson
|
||||
{"name_label":"Debian 10 Cloudinit self-service","power_state":"Halted","url":"/rest/v0/vms/5019156b-f40d-bc57-835b-4a259b177be1"}
|
||||
```
|
||||
|
||||
## Properties update
|
||||
|
||||
> This feature is restricted to `name_label` and `name_description` at the moment.
|
||||
|
||||
```bash
|
||||
curl \
|
||||
-X PATCH \
|
||||
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H 'Accept: application/json' \
|
||||
-d '{ "name_label": "The new name", "name_description": "The new description" }' \
|
||||
'https://xo.company.lan/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac'
|
||||
```
|
||||
|
||||
## VM destruction
|
||||
|
||||
```bash
|
||||
|
||||
@@ -2,7 +2,7 @@ import { every } from '@vates/predicates'
|
||||
import { ifDef } from '@xen-orchestra/defined'
|
||||
import { invalidCredentials, noSuchObject } from 'xo-common/api-errors.js'
|
||||
import { pipeline } from 'stream'
|
||||
import { Router } from 'express'
|
||||
import { json, Router } from 'express'
|
||||
import createNdJsonStream from '../_createNdJsonStream.mjs'
|
||||
import pick from 'lodash/pick.js'
|
||||
import map from 'lodash/map.js'
|
||||
@@ -125,6 +125,34 @@ export default class RestApi {
|
||||
}
|
||||
}
|
||||
})
|
||||
.patch('/:id', json(), async (req, res, next) => {
|
||||
let obj
|
||||
try {
|
||||
obj = await app.getXapiObject(req.params.id, type)
|
||||
} catch (error) {
|
||||
if (noSuchObject.is(error)) {
|
||||
next()
|
||||
} else {
|
||||
next(error)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const promises = []
|
||||
const { body } = req
|
||||
for (const key of ['name_description', 'name_label']) {
|
||||
const value = body[key]
|
||||
if (value !== undefined) {
|
||||
promises.push(obj['set_' + key](value))
|
||||
}
|
||||
}
|
||||
await promises
|
||||
res.sendStatus(200)
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
api.post('/srs/:uuid/vdis', async (req, res, next) => {
|
||||
|
||||
Reference in New Issue
Block a user