chore(xo-server): use @xen-orchestra/xapi/VM_import when possible
This commit is contained in:
parent
12140143d2
commit
70b09839c7
@ -63,7 +63,7 @@ export async function copyVm({ vm, sr }) {
|
||||
const input = await srcXapi.VM_export(vm._xapiRef)
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('import full VM...')
|
||||
await tgtXapi.VM_destroy((await tgtXapi.importVm(input, { srId: sr })).$ref)
|
||||
await tgtXapi.VM_destroy(await tgtXapi.VM_import(input, sr._xapiRef))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1297,7 +1297,8 @@ async function import_({ data, sr, type = 'xva', url }) {
|
||||
throw invalidParameters('URL import is only compatible with XVA')
|
||||
}
|
||||
|
||||
return (await xapi.importVm(await hrp(url), { srId, type })).$id
|
||||
const ref = await xapi.VM_import(await hrp(url), sr._xapiRef)
|
||||
return xapi.call('VM.get_by_uuid', ref)
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -965,10 +965,7 @@ async function _importGlusterVM(xapi, template, lvmsrId) {
|
||||
namespace: 'xosan',
|
||||
version: template.version,
|
||||
})
|
||||
const newVM = await xapi.importVm(templateStream, {
|
||||
srId: lvmsrId,
|
||||
type: 'xva',
|
||||
})
|
||||
const newVM = await xapi.VM_import(templateStream, this.getObject(lvmsrId, 'SR')._xapiRef)
|
||||
await xapi.editVm(newVM, {
|
||||
autoPoweron: true,
|
||||
name_label: 'XOSAN imported VM',
|
||||
|
@ -389,7 +389,7 @@ export default class Xapi extends XapiBase {
|
||||
|
||||
const onVmCreation = nameLabel !== undefined ? vm => vm.set_name_label(nameLabel) : null
|
||||
|
||||
const vm = await targetXapi._getOrWaitObject(await targetXapi._importVm(stream, sr, onVmCreation))
|
||||
const vm = await targetXapi._getOrWaitObject(await targetXapi.VM_import(stream, sr.$ref, onVmCreation))
|
||||
|
||||
return {
|
||||
vm,
|
||||
@ -674,36 +674,6 @@ export default class Xapi extends XapiBase {
|
||||
)
|
||||
}
|
||||
|
||||
@cancelable
|
||||
async _importVm($cancelToken, stream, sr, onVmCreation = undefined) {
|
||||
const taskRef = await this.task_create('VM import')
|
||||
const query = {}
|
||||
|
||||
if (sr != null) {
|
||||
query.sr_id = sr.$ref
|
||||
}
|
||||
|
||||
if (onVmCreation != null) {
|
||||
this.waitObject(
|
||||
obj => obj != null && obj.current_operations != null && taskRef in obj.current_operations,
|
||||
onVmCreation
|
||||
)
|
||||
}
|
||||
|
||||
const vmRef = await this.putResource($cancelToken, stream, '/import/', {
|
||||
query,
|
||||
task: taskRef,
|
||||
}).then(extractOpaqueRef, error => {
|
||||
// augment the error with as much relevant info as possible
|
||||
error.pool_master = this.pool.$master
|
||||
error.SR = sr
|
||||
|
||||
throw error
|
||||
})
|
||||
|
||||
return vmRef
|
||||
}
|
||||
|
||||
@decorateWith(deferrable)
|
||||
async _importOvaVm($defer, stream, { descriptionLabel, disks, memory, nameLabel, networks, nCpus, tables }, sr) {
|
||||
// 1. Create VM.
|
||||
@ -812,7 +782,7 @@ export default class Xapi extends XapiBase {
|
||||
const sr = srId && this.getObject(srId)
|
||||
|
||||
if (type === 'xva') {
|
||||
return /* await */ this._getOrWaitObject(await this._importVm(stream, sr))
|
||||
return /* await */ this._getOrWaitObject(await this.VM_import(stream, sr?.$ref))
|
||||
}
|
||||
|
||||
if (type === 'ova') {
|
||||
|
@ -271,13 +271,13 @@ export default class Proxy {
|
||||
[namespace]: { xva },
|
||||
} = await app.getResourceCatalog()
|
||||
const xapi = app.getXapi(srId)
|
||||
const vm = await xapi.importVm(
|
||||
const vm = await xapi.VM_import(
|
||||
await app.requestResource({
|
||||
id: xva.id,
|
||||
namespace,
|
||||
version: xva.version,
|
||||
}),
|
||||
{ srId }
|
||||
srId && this.getObject(srId, 'SR')._xapiRef
|
||||
)
|
||||
$defer.onFailure(() => xapi.VM_destroy(vm.$ref))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user