feat(xo-server): provide zstd compression for VM export (#3878)
See #3773
This commit is contained in:
parent
55b762f490
commit
bce0bf05e5
@ -11,7 +11,7 @@ export function createJob({ schedules, ...job }) {
|
|||||||
createJob.permission = 'admin'
|
createJob.permission = 'admin'
|
||||||
createJob.params = {
|
createJob.params = {
|
||||||
compression: {
|
compression: {
|
||||||
enum: ['', 'native'],
|
enum: ['', 'native', 'zstd'],
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
mode: {
|
mode: {
|
||||||
@ -68,7 +68,7 @@ export function editJob(props) {
|
|||||||
editJob.permission = 'admin'
|
editJob.permission = 'admin'
|
||||||
editJob.params = {
|
editJob.params = {
|
||||||
compression: {
|
compression: {
|
||||||
enum: ['', 'native'],
|
enum: ['', 'native', 'zstd'],
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
id: {
|
id: {
|
||||||
|
@ -706,7 +706,7 @@ export async function copy({ compress, name: nameLabel, sr, vm }) {
|
|||||||
|
|
||||||
copy.params = {
|
copy.params = {
|
||||||
compress: {
|
compress: {
|
||||||
type: 'boolean',
|
type: ['boolean', 'string'],
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
@ -1132,7 +1132,7 @@ revert.resolve = {
|
|||||||
|
|
||||||
async function handleExport(req, res, { xapi, id, compress }) {
|
async function handleExport(req, res, { xapi, id, compress }) {
|
||||||
const stream = await xapi.exportVm(id, {
|
const stream = await xapi.exportVm(id, {
|
||||||
compress: compress != null ? compress : true,
|
compress,
|
||||||
})
|
})
|
||||||
res.on('close', () => stream.cancel())
|
res.on('close', () => stream.cancel())
|
||||||
// Remove the filename as it is already part of the URL.
|
// Remove the filename as it is already part of the URL.
|
||||||
@ -1167,7 +1167,7 @@ async function export_({ vm, compress }) {
|
|||||||
|
|
||||||
export_.params = {
|
export_.params = {
|
||||||
vm: { type: 'string' },
|
vm: { type: 'string' },
|
||||||
compress: { type: 'boolean', optional: true },
|
compress: { type: ['boolean', 'string'], optional: true },
|
||||||
}
|
}
|
||||||
|
|
||||||
export_.resolve = {
|
export_.resolve = {
|
||||||
|
@ -539,7 +539,7 @@ export default class Xapi extends XapiBase {
|
|||||||
vmId,
|
vmId,
|
||||||
targetXapi,
|
targetXapi,
|
||||||
targetSrId,
|
targetSrId,
|
||||||
{ compress = true, nameLabel = undefined } = {}
|
{ compress, nameLabel = undefined } = {}
|
||||||
) {
|
) {
|
||||||
// Fall back on local copy if possible.
|
// Fall back on local copy if possible.
|
||||||
if (targetXapi === this) {
|
if (targetXapi === this) {
|
||||||
@ -783,7 +783,7 @@ export default class Xapi extends XapiBase {
|
|||||||
// Returns a stream to the exported VM.
|
// Returns a stream to the exported VM.
|
||||||
@concurrency(2, stream => stream.then(stream => fromEvent(stream, 'end')))
|
@concurrency(2, stream => stream.then(stream => fromEvent(stream, 'end')))
|
||||||
@cancelable
|
@cancelable
|
||||||
async exportVm($cancelToken, vmId, { compress = true } = {}) {
|
async exportVm($cancelToken, vmId, { compress = false } = {}) {
|
||||||
const vm = this.getObject(vmId)
|
const vm = this.getObject(vmId)
|
||||||
const useSnapshot = isVmRunning(vm)
|
const useSnapshot = isVmRunning(vm)
|
||||||
const exportedVm = useSnapshot
|
const exportedVm = useSnapshot
|
||||||
@ -793,7 +793,12 @@ export default class Xapi extends XapiBase {
|
|||||||
const promise = this.getResource($cancelToken, '/export/', {
|
const promise = this.getResource($cancelToken, '/export/', {
|
||||||
query: {
|
query: {
|
||||||
ref: exportedVm.$ref,
|
ref: exportedVm.$ref,
|
||||||
use_compression: compress ? 'true' : 'false',
|
use_compression:
|
||||||
|
compress === 'zstd'
|
||||||
|
? 'zstd'
|
||||||
|
: compress === true || compress === 'gzip'
|
||||||
|
? 'true'
|
||||||
|
: 'false',
|
||||||
},
|
},
|
||||||
task: this.createTask('VM export', vm.name_label),
|
task: this.createTask('VM export', vm.name_label),
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
@ -93,7 +93,7 @@ declare export class Xapi {
|
|||||||
exportVm(
|
exportVm(
|
||||||
cancelToken: mixed,
|
cancelToken: mixed,
|
||||||
vm: Vm,
|
vm: Vm,
|
||||||
options ?: Object
|
options?: { compress?: true | false | 'gzip' | 'zstd' }
|
||||||
): Promise<AugmentedReadable>;
|
): Promise<AugmentedReadable>;
|
||||||
getObject(object: Id): XapiObject;
|
getObject(object: Id): XapiObject;
|
||||||
importDeltaVm(data: DeltaVmImport, options: Object): Promise<{ vm: Vm }>;
|
importDeltaVm(data: DeltaVmImport, options: Object): Promise<{ vm: Vm }>;
|
||||||
|
@ -81,7 +81,7 @@ type SimpleIdPattern = {|
|
|||||||
|
|
||||||
export type BackupJob = {|
|
export type BackupJob = {|
|
||||||
...$Exact<Job>,
|
...$Exact<Job>,
|
||||||
compression?: 'native',
|
compression?: 'native' | 'zstd' | '',
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
remotes?: SimpleIdPattern,
|
remotes?: SimpleIdPattern,
|
||||||
settings: $Dict<Settings>,
|
settings: $Dict<Settings>,
|
||||||
@ -177,6 +177,9 @@ const isMetadataFile = (filename: string) => filename.endsWith('.json')
|
|||||||
const isVhd = (filename: string) => filename.endsWith('.vhd')
|
const isVhd = (filename: string) => filename.endsWith('.vhd')
|
||||||
const isXva = (filename: string) => filename.endsWith('.xva')
|
const isXva = (filename: string) => filename.endsWith('.xva')
|
||||||
|
|
||||||
|
const getJobCompression = ({ compression: c }) =>
|
||||||
|
c === undefined || c === '' ? false : c === 'native' ? 'gzip' : 'zstd'
|
||||||
|
|
||||||
const listReplicatedVms = (
|
const listReplicatedVms = (
|
||||||
xapi: Xapi,
|
xapi: Xapi,
|
||||||
scheduleId: string,
|
scheduleId: string,
|
||||||
@ -1119,7 +1122,7 @@ export default class BackupNg {
|
|||||||
parentId: taskId,
|
parentId: taskId,
|
||||||
},
|
},
|
||||||
xapi.exportVm($cancelToken, snapshot, {
|
xapi.exportVm($cancelToken, snapshot, {
|
||||||
compress: job.compression === 'native',
|
compress: getJobCompression(job),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
const exportTask = xva.task
|
const exportTask = xva.task
|
||||||
|
Loading…
Reference in New Issue
Block a user