chore(xo-server/xapi#exportVm): minor code improvement
This commit is contained in:
parent
72a4179c03
commit
90de47d708
@ -743,33 +743,28 @@ export default class Xapi extends XapiBase {
|
|||||||
@cancelable
|
@cancelable
|
||||||
async exportVm ($cancelToken, vmId, { compress = true } = {}) {
|
async exportVm ($cancelToken, vmId, { compress = true } = {}) {
|
||||||
const vm = this.getObject(vmId)
|
const vm = this.getObject(vmId)
|
||||||
|
const useSnapshot = isVmRunning(vm)
|
||||||
let snapshotRef
|
const exportedVm = useSnapshot
|
||||||
if (isVmRunning(vm)) {
|
? await this._snapshotVm($cancelToken, vm, `[XO Export] ${vm.name_label}`)
|
||||||
snapshotRef = (await this._snapshotVm(
|
: vm
|
||||||
$cancelToken,
|
|
||||||
vm,
|
|
||||||
`[XO Export] ${vm.name_label}`
|
|
||||||
)).$ref
|
|
||||||
}
|
|
||||||
|
|
||||||
const promise = this.getResource($cancelToken, '/export/', {
|
const promise = this.getResource($cancelToken, '/export/', {
|
||||||
query: {
|
query: {
|
||||||
ref: snapshotRef || vm.$ref,
|
ref: exportedVm.$ref,
|
||||||
use_compression: compress ? 'true' : 'false',
|
use_compression: compress ? 'true' : 'false',
|
||||||
},
|
},
|
||||||
task: this.createTask('VM export', vm.name_label),
|
task: this.createTask('VM export', vm.name_label),
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
// augment the error with as much relevant info as possible
|
// augment the error with as much relevant info as possible
|
||||||
error.pool_master = this.pool.$master
|
error.pool_master = this.pool.$master
|
||||||
error.VM = snapshotRef || vm
|
error.VM = exportedVm
|
||||||
|
|
||||||
throw error
|
throw error
|
||||||
})
|
})
|
||||||
|
|
||||||
if (snapshotRef !== undefined) {
|
if (useSnapshot) {
|
||||||
promise.then(_ =>
|
promise.then(_ =>
|
||||||
_.task::pFinally(() => this.deleteVm(snapshotRef)::ignoreErrors())
|
_.task::pFinally(() => this.deleteVm(exportedVm)::ignoreErrors())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user