Skip to content

Commit

Permalink
chore(xo-server): use @xen-orchestra/xapi/VBD_unplug
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-f committed Jun 2, 2022
1 parent 9860bd7 commit 379e4d7
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 20 deletions.
3 changes: 1 addition & 2 deletions packages/xo-server/src/api/vbd.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export { delete_ as delete }
// -------------------------------------------------------------------

export async function disconnect({ vbd }) {
const xapi = this.getXapi(vbd)
await xapi.disconnectVbd(vbd._xapiRef)
await this.getXapiObject(vbd).$unplug()
}

disconnect.params = {
Expand Down
2 changes: 1 addition & 1 deletion packages/xo-server/src/api/xosan.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ async function replaceBrickOnSameVM(xosansr, previousBrick, newLvmSr, brickSize)
CURRENT_POOL_OPERATIONS[poolId] = { ...OPERATION_OBJECT, state: 3 }
await umountDisk(localEndpoint, previousBrickRoot)
const previousVBD = previousVM.$VBDs.find(vbd => vbd.device === previousBrickDevice)
await xapi.disconnectVbd(previousVBD)
await previousVBD.$unplug()
await xapi.VDI_destroy(previousVBD.VDI)
CURRENT_POOL_OPERATIONS[poolId] = { ...OPERATION_OBJECT, state: 4 }
await xapi.callAsync('SR.scan', xapi.getObject(xosansr).$ref)
Expand Down
17 changes: 0 additions & 17 deletions packages/xo-server/src/xapi/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,23 +1075,6 @@ export default class Xapi extends XapiBase {
await this.callAsync('VBD.plug', vbdId)
}

async _disconnectVbd(vbd) {
// TODO: check if VBD is attached before
try {
await this.call('VBD.unplug_force', vbd.$ref)
} catch (error) {
if (error.code === 'VBD_NOT_UNPLUGGABLE') {
await vbd.set_unpluggable(true)
return this.call('VBD.unplug_force', vbd.$ref)
}
throw error
}
}

async disconnectVbd(vbdId) {
await this._disconnectVbd(this.getObject(vbdId))
}

// TODO: remove when no longer used.
async destroyVbdsFromVm(vmId) {
await Promise.all(this.getObject(vmId).VBDs.map(async ref => this.VBD_destroy(ref)))
Expand Down

0 comments on commit 379e4d7

Please sign in to comment.