feat(xo-server): VM_destroy instead of deleteVm (#5693)

Continuation of 5f1c127
This commit is contained in:
Mathieu 2021-03-26 14:23:04 +01:00 committed by GitHub
parent 22ba1302d2
commit cb52a8b51b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 30 additions and 39 deletions

View File

@ -64,7 +64,7 @@ export async function destroy({ sr }) {
const config = xapi.xo.getData(sr, 'xosan_config') const config = xapi.xo.getData(sr, 'xosan_config')
// we simply forget because the hosted disks are being destroyed with the VMs // we simply forget because the hosted disks are being destroyed with the VMs
await xapi.forgetSr(sr._xapiId) await xapi.forgetSr(sr._xapiId)
await asyncMapSettled(config.nodes, node => xapi.deleteVm(node.vm.id)) await asyncMapSettled(config.nodes, node => this.getXapiObject(node.vm.id).$destroy())
await xapi.deleteNetwork(config.network) await xapi.deleteNetwork(config.network)
if (sr.SR_type === 'xosan') { if (sr.SR_type === 'xosan') {
await this.unbindXosanLicense({ srId: sr.id }) await this.unbindXosanLicense({ srId: sr.id })

View File

@ -60,7 +60,7 @@ export async function copyVm({ vm, sr }) {
console.log('export full VM...') console.log('export full VM...')
const input = await srcXapi.exportVm(vm) const input = await srcXapi.exportVm(vm)
console.log('import full VM...') console.log('import full VM...')
await tgtXapi.deleteVm(await tgtXapi.importVm(input, { srId: sr })) await tgtXapi.VM_destroy((await tgtXapi.importVm(input, { srId: sr })).$ref)
} }
// delta // delta
@ -72,7 +72,7 @@ export async function copyVm({ vm, sr }) {
srId: sr, srId: sr,
}) })
console.log('transfered size:', transferSize) console.log('transfered size:', transferSize)
await tgtXapi.deleteVm(copyVm) await tgtXapi.VM_destroy(copyVm.$ref)
} }
} }

View File

@ -152,7 +152,7 @@ export const create = defer(async function ($defer, params) {
} }
const xapiVm = await xapi.createVm(template._xapiId, params, checkLimits) const xapiVm = await xapi.createVm(template._xapiId, params, checkLimits)
$defer.onFailure(() => xapi.deleteVm(xapiVm.$id, true, true)) $defer.onFailure(() => xapi.VM_destroy(xapiVm.$ref, true, true))
const vm = xapi.xo.addObject(xapiVm) const vm = xapi.xo.addObject(xapiVm)
@ -385,7 +385,7 @@ const delete_ = defer(async function (
} }
}) })
return xapi.deleteVm(vm._xapiId, deleteDisks, force, forceDeleteDefaultTemplate) return xapi.VM_destroy(vm._xapiRef, deleteDisks, force, forceDeleteDefaultTemplate)
}) })
delete_.params = { delete_.params = {
@ -664,11 +664,11 @@ export const clone = defer(async function ($defer, { vm, name, full_copy: fullCo
await checkPermissionOnSrs.call(this, vm) await checkPermissionOnSrs.call(this, vm)
const xapi = this.getXapi(vm) const xapi = this.getXapi(vm)
const { $id: cloneId } = await xapi.cloneVm(vm._xapiRef, { const { $id: cloneId, $ref: cloneRef } = await xapi.cloneVm(vm._xapiRef, {
nameLabel: name, nameLabel: name,
fast: !fullCopy, fast: !fullCopy,
}) })
$defer.onFailure(() => xapi.deleteVm(cloneId)) $defer.onFailure(() => xapi.VM_destroy(cloneRef))
const isAdmin = this.user.permission === 'admin' const isAdmin = this.user.permission === 'admin'
if (!isAdmin) { if (!isAdmin) {
@ -786,10 +786,10 @@ export const snapshot = defer(async function (
} }
const xapi = this.getXapi(vm) const xapi = this.getXapi(vm)
const { $id: snapshotId } = await (saveMemory const { $id: snapshotId, $ref: snapshotRef } = await (saveMemory
? xapi.checkpointVm(vm._xapiRef, name) ? xapi.checkpointVm(vm._xapiRef, name)
: xapi.snapshotVm(vm._xapiRef, name)) : xapi.snapshotVm(vm._xapiRef, name))
$defer.onFailure(() => xapi.deleteVm(snapshotId)) $defer.onFailure(() => xapi.VM_destroy(snapshotRef))
if (description !== undefined) { if (description !== undefined) {
await xapi.editVm(snapshotId, { name_description: description }) await xapi.editVm(snapshotId, { name_description: description })

View File

@ -585,10 +585,10 @@ export const createSR = defer(async function (
const firstSr = srsObjects[0] const firstSr = srsObjects[0]
CURRENT_POOL_OPERATIONS[poolId] = { ...OPERATION_OBJECT, state: 1 } CURRENT_POOL_OPERATIONS[poolId] = { ...OPERATION_OBJECT, state: 1 }
const firstVM = await this::_importGlusterVM(xapi, template, firstSr) const firstVM = await this::_importGlusterVM(xapi, template, firstSr)
$defer.onFailure(() => xapi.deleteVm(firstVM, true)) $defer.onFailure(() => xapi.VM_destroy(firstVM.$ref, true))
CURRENT_POOL_OPERATIONS[poolId] = { ...OPERATION_OBJECT, state: 2 } CURRENT_POOL_OPERATIONS[poolId] = { ...OPERATION_OBJECT, state: 2 }
const copiedVms = await asyncMapSettled(srsObjects.slice(1), sr => const copiedVms = await asyncMapSettled(srsObjects.slice(1), sr =>
copyVm(xapi, firstVM, sr)::tap(({ vm }) => $defer.onFailure(() => xapi.deleteVm(vm))) copyVm(xapi, firstVM, sr)::tap(({ vm }) => $defer.onFailure(() => xapi.VM_destroy(vm.$ref)))
) )
const vmsAndSrs = [ const vmsAndSrs = [
{ {
@ -602,7 +602,7 @@ export const createSR = defer(async function (
const sr = firstSr const sr = firstSr
const arbiterIP = networkPrefix + vmIpLastNumber++ const arbiterIP = networkPrefix + vmIpLastNumber++
const arbiterVm = await xapi.copyVm(firstVM, sr) const arbiterVm = await xapi.copyVm(firstVM, sr)
$defer.onFailure(() => xapi.deleteVm(arbiterVm, true)) $defer.onFailure(() => xapi.VM_destroy(arbiterVm.$ref, true))
arbiter = await _prepareGlusterVm(xapi, sr, arbiterVm, xosanNetwork, arbiterIP, { arbiter = await _prepareGlusterVm(xapi, sr, arbiterVm, xosanNetwork, arbiterIP, {
labelSuffix: '_arbiter', labelSuffix: '_arbiter',
increaseDataDisk: false, increaseDataDisk: false,
@ -870,7 +870,7 @@ export async function replaceBrick({ xosansr, previousBrick, newLvmSr, brickSize
await xapi.xo.setData(xosansr, 'xosan_config', data) await xapi.xo.setData(xosansr, 'xosan_config', data)
CURRENT_POOL_OPERATIONS[poolId] = { ...OPERATION_OBJECT, state: 2 } CURRENT_POOL_OPERATIONS[poolId] = { ...OPERATION_OBJECT, state: 2 }
if (previousVMEntry) { if (previousVMEntry) {
await xapi.deleteVm(previousVMEntry.vm, true) await xapi.VM_destroy(previousVMEntry.vm.$ref, true)
} }
CURRENT_POOL_OPERATIONS[poolId] = { ...OPERATION_OBJECT, state: 3 } CURRENT_POOL_OPERATIONS[poolId] = { ...OPERATION_OBJECT, state: 3 }
await xapi.callAsync('SR.scan', xapi.getObject(xosansr).$ref) await xapi.callAsync('SR.scan', xapi.getObject(xosansr).$ref)
@ -1013,7 +1013,7 @@ const insertNewGlusterVm = defer(async function (
const srObject = xapi.getObject(lvmsrId) const srObject = xapi.getObject(lvmsrId)
// can't really copy an existing VM, because existing gluster VMs disks might too large to be copied. // can't really copy an existing VM, because existing gluster VMs disks might too large to be copied.
const newVM = await this::_importGlusterVM(xapi, data.template, lvmsrId) const newVM = await this::_importGlusterVM(xapi, data.template, lvmsrId)
$defer.onFailure(() => xapi.deleteVm(newVM, true)) $defer.onFailure(() => xapi.VM_destroy(newVM.$ref, true))
const addressAndHost = await _prepareGlusterVm(xapi, srObject, newVM, xosanNetwork, ipAddress, { const addressAndHost = await _prepareGlusterVm(xapi, srObject, newVM, xosanNetwork, ipAddress, {
labelSuffix, labelSuffix,
increaseDataDisk, increaseDataDisk,
@ -1051,7 +1051,7 @@ export const addBricks = defer(async function ($defer, { xosansr, lvmsrs, brickS
newAddresses.push(ipAddress) newAddresses.push(ipAddress)
const { newVM, addressAndHost } = await this::insertNewGlusterVm(xapi, xosansr, newSr, { ipAddress, brickSize }) const { newVM, addressAndHost } = await this::insertNewGlusterVm(xapi, xosansr, newSr, { ipAddress, brickSize })
$defer.onFailure(() => glusterCmd(glusterEndpoint, 'peer detach ' + ipAddress, true)) $defer.onFailure(() => glusterCmd(glusterEndpoint, 'peer detach ' + ipAddress, true))
$defer.onFailure(() => xapi.deleteVm(newVM, true)) $defer.onFailure(() => xapi.VM_destroy(newVM.$ref, true))
const brickName = addressAndHost.brickName const brickName = addressAndHost.brickName
newNodes.push({ newNodes.push({
brickName, brickName,
@ -1070,7 +1070,7 @@ export const addBricks = defer(async function ($defer, { xosansr, lvmsrs, brickS
data.type = 'replica' data.type = 'replica'
await xapi.xo.setData(xosansr, 'xosan_config', data) await xapi.xo.setData(xosansr, 'xosan_config', data)
await glusterCmd(glusterEndpoint, 'peer detach ' + arbiterNode.vm.ip, true) await glusterCmd(glusterEndpoint, 'peer detach ' + arbiterNode.vm.ip, true)
await xapi.deleteVm(arbiterNode.vm.id, true) await xapi.VM_destroy(await xapi.call('VM.get_by_uuid', arbiterNode.vm.id), true)
} }
CURRENT_POOL_OPERATIONS[poolId] = { ...OPERATION_OBJECT, state: 1 } CURRENT_POOL_OPERATIONS[poolId] = { ...OPERATION_OBJECT, state: 1 }
await glusterCmd(glusterEndpoint, `volume add-brick xosan ${newNodes.map(n => n.brickName).join(' ')}`) await glusterCmd(glusterEndpoint, `volume add-brick xosan ${newNodes.map(n => n.brickName).join(' ')}`)
@ -1123,7 +1123,7 @@ export const removeBricks = defer(async function ($defer, { xosansr, bricks }) {
remove(data.nodes, node => ips.includes(node.vm.ip)) remove(data.nodes, node => ips.includes(node.vm.ip))
await xapi.xo.setData(xosansr.id, 'xosan_config', data) await xapi.xo.setData(xosansr.id, 'xosan_config', data)
await xapi.callAsync('SR.scan', xapi.getObject(xosansr._xapiId).$ref) await xapi.callAsync('SR.scan', xapi.getObject(xosansr._xapiId).$ref)
await asyncMapSettled(brickVMs, vm => xapi.deleteVm(vm.vm, true)) await asyncMapSettled(brickVMs, vm => xapi.VM_destroy(vm.vm.$ref, true))
} finally { } finally {
delete CURRENT_POOL_OPERATIONS[xapi.pool.$id] delete CURRENT_POOL_OPERATIONS[xapi.pool.$id]
} }

View File

@ -563,15 +563,6 @@ export default class Xapi extends XapiBase {
) )
} }
/**
* @deprecated Use VM_destroy instead
*/
async deleteVm(vmOrId, deleteDisks = true, force = false, forceDeleteDefaultTemplate = false) {
const $ref = typeof vmOrId === 'string' ? this.getObject(vmOrId).$ref : vmOrId.$ref
return this.VM_destroy($ref, { deleteDisks, force, forceDeleteDefaultTemplate })
}
getVmConsole(vmId) { getVmConsole(vmId) {
const vm = this.getObject(vmId) const vm = this.getObject(vmId)

View File

@ -75,7 +75,6 @@ declare export class Xapi {
barrier(): Promise<void>; barrier(): Promise<void>;
barrier(ref: string): Promise<XapiObject>; barrier(ref: string): Promise<XapiObject>;
deleteVm(vm: Id): Promise<void>;
editVm(vm: Id, $Dict<mixed>): Promise<void>; editVm(vm: Id, $Dict<mixed>): Promise<void>;
exportDeltaVm( exportDeltaVm(
cancelToken: mixed, cancelToken: mixed,

View File

@ -79,7 +79,7 @@ export default {
// Clones the template. // Clones the template.
const vmRef = await this[clone ? '_cloneVm' : '_copyVm'](template, nameLabel) const vmRef = await this[clone ? '_cloneVm' : '_copyVm'](template, nameLabel)
$defer.onFailure(() => this.deleteVm(vmRef)) $defer.onFailure(() => this.VM_destroy(vmRef))
// Copy BIOS strings // Copy BIOS strings
// https://support.citrix.com/article/CTX230618 // https://support.citrix.com/article/CTX230618

View File

@ -374,7 +374,7 @@ export default class {
bypassVdiChainsCheck: force, bypassVdiChainsCheck: force,
snapshotNameLabel: `XO_DELTA_EXPORT: ${targetSr.name_label} (${targetSr.uuid})`, snapshotNameLabel: `XO_DELTA_EXPORT: ${targetSr.name_label} (${targetSr.uuid})`,
}) })
$defer.onFailure(() => srcXapi.deleteVm(delta.vm.uuid)) $defer.onFailure(() => this._xo.getXapiObject(delta.vm.uuid).$destroy())
$defer.onFailure(cancel) $defer.onFailure(cancel)
const date = safeDateFormat(Date.now()) const date = safeDateFormat(Date.now())
@ -400,11 +400,11 @@ export default class {
// Once done, (asynchronously) remove the (now obsolete) local // Once done, (asynchronously) remove the (now obsolete) local
// base. // base.
if (localBaseUuid) { if (localBaseUuid) {
promise.then(() => srcXapi.deleteVm(localBaseUuid))::ignoreErrors() promise.then(() => this._xo.getXapiObject(localBaseUuid).$destroy())::ignoreErrors()
} }
if (toRemove !== undefined) { if (toRemove !== undefined) {
promise.then(() => asyncMapSettled(toRemove, _ => targetXapi.deleteVm(_.$id)))::ignoreErrors() promise.then(() => asyncMapSettled(toRemove, _ => targetXapi.VM_destroy(_.$ref)))::ignoreErrors()
} }
// (Asynchronously) Identify snapshot as future base. // (Asynchronously) Identify snapshot as future base.
@ -591,7 +591,7 @@ export default class {
) )
const baseVm = bases.pop() const baseVm = bases.pop()
forEach(bases, base => { forEach(bases, base => {
xapi.deleteVm(base.$id)::ignoreErrors() xapi.VM_destroy(base.$ref)::ignoreErrors()
}) })
// Check backup dirs. // Check backup dirs.
@ -621,7 +621,8 @@ export default class {
fullVdisRequired, fullVdisRequired,
disableBaseTags: true, disableBaseTags: true,
}) })
$defer.onFailure(() => xapi.deleteVm(delta.vm.uuid)) const exportedVmRef = await xapi.call('VM.get_by_uuid', delta.vm.uuid)
$defer.onFailure(() => xapi.VM_destroy(exportedVmRef))
$defer.onFailure(cancel) $defer.onFailure(cancel)
// Save vdis. // Save vdis.
@ -711,7 +712,7 @@ export default class {
await this._removeOldDeltaVmBackups(xapi, { vm, handler, dir, retention }) await this._removeOldDeltaVmBackups(xapi, { vm, handler, dir, retention })
if (baseVm) { if (baseVm) {
xapi.deleteVm(baseVm.$id)::ignoreErrors() xapi.VM_destroy(baseVm.$ref)::ignoreErrors()
} }
return { return {
@ -837,7 +838,7 @@ export default class {
const promises = [] const promises = []
for (let surplus = snapshots.length - (retention - 1); surplus > 0; surplus--) { for (let surplus = snapshots.length - (retention - 1); surplus > 0; surplus--) {
const oldSnap = snapshots.shift() const oldSnap = snapshots.shift()
promises.push(xapi.deleteVm(oldSnap.uuid)) promises.push(xapi.VM_destroy(oldSnap.$ref))
} }
await Promise.all(promises) await Promise.all(promises)
} }
@ -846,7 +847,7 @@ export default class {
return Promise.all( return Promise.all(
mapToArray(vms, vm => mapToArray(vms, vm =>
// Do not consider a failure to delete an old copy as a fatal error. // Do not consider a failure to delete an old copy as a fatal error.
xapi.deleteVm(vm.$id)::ignoreErrors() xapi.VM_destroy(vm.$ref)::ignoreErrors()
) )
) )
} }

View File

@ -107,7 +107,7 @@ export default class Proxy {
const { vmUuid } = await this._getProxy(id) const { vmUuid } = await this._getProxy(id)
if (vmUuid !== undefined) { if (vmUuid !== undefined) {
try { try {
await this._app.getXapi(vmUuid).deleteVm(vmUuid) await this._app.getXapiObject(vmUuid).$destroy()
} catch (error) { } catch (error) {
if (!noSuchObject.is(error)) { if (!noSuchObject.is(error)) {
throw error throw error
@ -208,7 +208,7 @@ export default class Proxy {
}), }),
{ srId } { srId }
) )
$defer.onFailure(() => xapi._deleteVm(vm)) $defer.onFailure(() => xapi.VM_destroy(vm.$ref))
const arg = { licenseId, boundObjectId: vm.uuid } const arg = { licenseId, boundObjectId: vm.uuid }
await app.bindLicense(arg) await app.bindLicense(arg)
@ -268,7 +268,7 @@ export default class Proxy {
const { vmUuid } = await this._getProxy(proxyId) const { vmUuid } = await this._getProxy(proxyId)
if (vmUuid !== undefined) { if (vmUuid !== undefined) {
try { try {
await app.getXapi(vmUuid).deleteVm(vmUuid) await app.getXapiObject(vmUuid).$destroy()
} catch (error) { } catch (error) {
if (!noSuchObject.is(error)) { if (!noSuchObject.is(error)) {
throw error throw error