feat(xo-server/RestApi): add raw VDI import
This commit is contained in:
parent
2fbeaa618a
commit
82452e9616
@ -5,6 +5,7 @@ const { decorateClass } = require('@vates/decorate-with')
|
||||
const { defer } = require('golike-defer')
|
||||
const { incorrectState } = require('xo-common/api-errors')
|
||||
const { VDI_FORMAT_VHD } = require('./index.js')
|
||||
const assert = require('node:assert').strict
|
||||
const peekFooterFromStream = require('vhd-lib/peekFooterFromVhdStream')
|
||||
|
||||
const AggregateError = require('./_AggregateError.js')
|
||||
@ -150,12 +151,26 @@ class Sr {
|
||||
$defer,
|
||||
ref,
|
||||
stream,
|
||||
{ name_label = '[XO] Imported disk - ' + new Date().toISOString(), ...vdiCreateOpts } = {}
|
||||
{
|
||||
format = VDI_FORMAT_VHD,
|
||||
name_label = '[XO] Imported disk - ' + new Date().toISOString(),
|
||||
virtual_size,
|
||||
...vdiCreateOpts
|
||||
} = {}
|
||||
) {
|
||||
const footer = await peekFooterFromStream(stream)
|
||||
const vdiRef = await this.VDI_create({ ...vdiCreateOpts, name_label, SR: ref, virtual_size: footer.currentSize })
|
||||
if (virtual_size === undefined) {
|
||||
if (format === VDI_FORMAT_VHD) {
|
||||
const footer = await peekFooterFromStream(stream)
|
||||
virtual_size = footer.currentSize
|
||||
} else {
|
||||
virtual_size = stream.length
|
||||
assert.notEqual(virtual_size, undefined)
|
||||
}
|
||||
}
|
||||
|
||||
const vdiRef = await this.VDI_create({ ...vdiCreateOpts, name_label, SR: ref, virtual_size })
|
||||
$defer.onFailure.call(this, 'callAsync', 'VDI.destroy', vdiRef)
|
||||
await this.VDI_importContent(vdiRef, stream, { format: VDI_FORMAT_VHD })
|
||||
await this.VDI_importContent(vdiRef, stream, { format })
|
||||
return vdiRef
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
> Users must be able to say: “Nice enhancement, I'm eager to test it”
|
||||
|
||||
- [REST API] VDI import now also supports the raw format
|
||||
|
||||
### Bug fixes
|
||||
|
||||
> Users must be able to say: “I had this issue, happy to know it's fixed”
|
||||
@ -33,6 +35,7 @@
|
||||
- @vates/async-each major
|
||||
- @xen-orchestra/xapi patch
|
||||
- xo-cli patch
|
||||
- xo-server minor
|
||||
- xo-web patch
|
||||
|
||||
<!--packages-end-->
|
||||
|
@ -143,14 +143,14 @@ curl \
|
||||
|
||||
## VDI Import
|
||||
|
||||
A VHD can be imported on an SR to create a VDI at `/rest/v0/srs/<sr uuid>/vdis`.
|
||||
A VHD or a raw export can be imported on an SR to create a new VDI at `/rest/v0/srs/<sr uuid>/vdis`.
|
||||
|
||||
```bash
|
||||
curl \
|
||||
-X POST \
|
||||
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
|
||||
-T myDisk.vhd \
|
||||
'https://xo.example.org/rest/v0/srs/357bd56c-71f9-4b2a-83b8-3451dec04b8f/vdis?name_label=my_imported_VDI' \
|
||||
-T myDisk.raw \
|
||||
'https://xo.example.org/rest/v0/srs/357bd56c-71f9-4b2a-83b8-3451dec04b8f/vdis?raw&name_label=my_imported_VDI' \
|
||||
| cat
|
||||
```
|
||||
|
||||
@ -162,6 +162,7 @@ The following query parameters are supported to customize the created VDI:
|
||||
|
||||
- `name_label`
|
||||
- `name_description`
|
||||
- `raw`: this parameter must be used if importing a raw export instead of a VHD
|
||||
|
||||
## The future
|
||||
|
||||
|
@ -140,14 +140,14 @@ curl \
|
||||
|
||||
## VDI Import
|
||||
|
||||
A VHD can be imported on an SR to create a VDI at `/rest/v0/srs/<sr uuid>/vdis`.
|
||||
A VHD or a raw export can be imported on an SR to create a new VDI at `/rest/v0/srs/<sr uuid>/vdis`.
|
||||
|
||||
```bash
|
||||
curl \
|
||||
-X POST \
|
||||
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
|
||||
-T myDisk.vhd \
|
||||
'https://xo.company.lan/rest/v0/srs/357bd56c-71f9-4b2a-83b8-3451dec04b8f/vdis?name_label=my_imported_VDI' \
|
||||
-T myDisk.raw \
|
||||
'https://xo.company.lan/rest/v0/srs/357bd56c-71f9-4b2a-83b8-3451dec04b8f/vdis?raw&name_label=my_imported_VDI' \
|
||||
| cat
|
||||
```
|
||||
|
||||
@ -159,6 +159,7 @@ The following query parameters are supported to customize the created VDI:
|
||||
|
||||
- `name_label`
|
||||
- `name_description`
|
||||
- `raw`: this parameter must be used if importing a raw export instead of a VHD
|
||||
|
||||
## The future
|
||||
|
||||
|
@ -8,6 +8,7 @@ import pick from 'lodash/pick.js'
|
||||
import map from 'lodash/map.js'
|
||||
import * as CM from 'complex-matcher'
|
||||
import fromCallback from 'promise-toolbox/fromCallback'
|
||||
import { VDI_FORMAT_RAW, VDI_FORMAT_VHD } from '@xen-orchestra/xapi'
|
||||
|
||||
function sendObjects(objects, req, res) {
|
||||
const { query } = req
|
||||
@ -124,8 +125,12 @@ export default class RestApi {
|
||||
const sr = 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 })
|
||||
const { name_label, name_description, raw } = req.query
|
||||
const vdiRef = await sr.$importVdi(req, {
|
||||
format: raw !== undefined ? VDI_FORMAT_RAW : VDI_FORMAT_VHD,
|
||||
name_label,
|
||||
name_description,
|
||||
})
|
||||
|
||||
res.end(await sr.$xapi.getField('VDI', vdiRef, 'uuid'))
|
||||
} catch (error) {
|
||||
|
Loading…
Reference in New Issue
Block a user