feat(xo-server/RestApi): add VDI import

Related to zammad#7036
This commit is contained in:
Julien Fontanet
2022-05-29 16:45:53 +02:00
parent 0ec5f4bf68
commit 0e49150b8e
3 changed files with 53 additions and 0 deletions

View File

@@ -141,6 +141,23 @@ curl \
> myDisk.vhd
```
## VDI Import
A VHD can be imported on an SR to create a VDI at `/rest/v0/srs/<sr uuid>/vdis`.
```bash
curl \
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
--progress-bar \
--data-binary @myDisk.vhd \
'https://xo.example.org/rest/v0/srs/357bd56c-71f9-4b2a-83b8-3451dec04b8f/vdis'
```
The following query parameters are supported to customize the created VDI:
- `name_label`
- `name_description`
## The future
We are adding features and improving the REST API step by step. If you have interesting use cases or feedback, please ask directly at <https://xcp-ng.org/forum/category/12/xen-orchestra>

View File

@@ -4,6 +4,7 @@
- [Collections](#collections)
- [VM Export](#vm-export)
- [VDI Export](#vdi-export)
- [VDI Import](#vdi-import)
- [The future](#the-future)
> This [REST](https://en.wikipedia.org/wiki/Representational_state_transfer)-oriented API is experimental. Non-backward compatible changes or removal may occur in any future release. Use of the feature is not recommended in production environments.
@@ -137,6 +138,23 @@ curl \
> myDisk.vhd
```
## VDI Import
A VHD can be imported on an SR to create a VDI at `/rest/v0/srs/<sr uuid>/vdis`.
```bash
curl \
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
--progress-bar \
--data-binary @myDisk.vhd \
'https://xo.company.lan/rest/v0/srs/357bd56c-71f9-4b2a-83b8-3451dec04b8f/vdis'
```
The following query parameters are supported to customize the created VDI:
- `name_label`
- `name_description`
## The future
We are adding features and improving the REST API step by step. If you have interesting use cases or feedback, please ask directly at <https://xcp-ng.org/forum/category/12/xen-orchestra>

View File

@@ -119,6 +119,24 @@ export default class RestApi {
})
}
api.post('/srs/:uuid/vdis', async (req, res, next) => {
try {
const sr = await app.getXapiObject(req.params.uuid, 'SR')
req.length = +req.headers['content-length']
const { name_label, name_description } = req.query
const vdiRef = await sr.$importVdi(req, { name_label, name_description })
res.end(vdiRef)
} catch (error) {
if (noSuchObject.is(error)) {
next()
} else {
next(error)
}
}
})
api.get('/vdis/:uuid.vhd', async (req, res, next) => {
try {
const vdi = await app.getXapiObject(req.params.uuid, 'VDI')