feat(xo-server/rest-api): possibility to import a VM

This commit is contained in:
Julien Fontanet
2023-11-28 17:54:10 +01:00
parent 5820e19731
commit 61e1f83a9f
4 changed files with 52 additions and 0 deletions

View File

@@ -8,6 +8,7 @@
> Users must be able to say: “Nice enhancement, I'm eager to test it”
- [VM/Disks] Display task information when importing VDIs (PR [#7197](https://github.com/vatesfr/xen-orchestra/pull/7197))
- [REST API] Support VM import using the XVA format
### Bug fixes
@@ -30,6 +31,7 @@
<!--packages-start-->
- @xen-orchestra/backups patch
- xo-server minor
- xo-web minor
<!--packages-end-->

View File

@@ -199,6 +199,23 @@ curl \
> myDisk.vhd
```
## VM Import
A VM can be imported by posting to `/rest/v0/pools/:id/vms`.
```sh
curl \
-X POST \
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
-T myDisk.raw \
'https://xo.example.org/rest/v0/pools/355ee47d-ff4c-4924-3db2-fd86ae629676/vms?sr=357bd56c-71f9-4b2a-83b8-3451dec04b8f' \
| cat
```
The `sr` query parameter can be used to specify on which SR the VM should be imported, if not specified, the default SR will be used.
> Note: the final `| cat` ensures cURL's standard output is not a TTY, which is necessary for upload stats to be dislayed.
## VDI Import
### Existing VDI

View File

@@ -180,6 +180,23 @@ curl \
> myVM.xva
```
## VM Import
A VM can be imported by posting to `/rest/v0/pools/:id/vms`.
```sh
curl \
-X POST \
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
-T myDisk.raw \
'https://xo.company.lan/rest/v0/pools/355ee47d-ff4c-4924-3db2-fd86ae629676/vms?sr=357bd56c-71f9-4b2a-83b8-3451dec04b8f' \
| cat
```
The `sr` query parameter can be used to specify on which SR the VM should be imported, if not specified, the default SR will be used.
> Note: the final `| cat` ensures cURL's standard output is not a TTY, which is necessary for upload stats to be dislayed.
## VDI destruction
```sh

View File

@@ -576,6 +576,22 @@ export default class RestApi {
})
)
api.post(
'/:collection(pools)/:object/vms',
wrap(async (req, res) => {
let srRef
const { sr } = req.params
if (sr !== undefined) {
srRef = app.getXapiObject(sr, 'SR').$ref
}
const { $xapi } = req.xapiObject
const ref = await $xapi.VM_import(req, srRef)
res.end(await $xapi.getField('VM', ref, 'uuid'))
})
)
api.post(
'/:collection(srs)/:object/vdis',
wrap(async (req, res) => {