chore(api): decaffeinate vbd (#642)

This commit is contained in:
Julien Fontanet 2018-01-08 13:56:41 +01:00 committed by GitHub
parent cfcd302294
commit a65b1325fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 103 deletions

View File

@ -1,103 +0,0 @@
# FIXME: too low level, should be removed.
{coroutine: $coroutine} = require 'bluebird'
#=====================================================================
delete_ = ({vbd}) -> @getXapi(vbd).deleteVbd(vbd)
delete_.params = {
id: { type: 'string' }
}
delete_.resolve = {
vbd: ['id', 'VBD', 'administrate'],
}
exports.delete = delete_
#---------------------------------------------------------------------
disconnect = $coroutine ({vbd}) ->
xapi = @getXapi vbd
yield xapi.disconnectVbd(vbd._xapiRef)
return
disconnect.params = {
id: { type: 'string' }
}
disconnect.resolve = {
vbd: ['id', 'VBD', 'administrate'],
}
exports.disconnect = disconnect
#---------------------------------------------------------------------
connect = $coroutine ({vbd}) ->
xapi = @getXapi vbd
yield xapi.connectVbd(vbd._xapiRef)
return
connect.params = {
id: { type: 'string' }
}
connect.resolve = {
vbd: ['id', 'VBD', 'administrate'],
}
exports.connect = connect
#---------------------------------------------------------------------
set = $coroutine (params) ->
{vbd} = params
xapi = @getXapi vbd
{ _xapiRef: ref } = vbd
# VBD position
if 'position' of params
yield xapi.call 'VBD.set_userdevice', ref, String(params.position)
set.params = {
# Identifier of the VBD to update.
id: { type: 'string' }
position: { type: ['string', 'number'], optional: true }
}
set.resolve = {
vbd: ['id', 'VBD', 'administrate'],
}
exports.set = set
#---------------------------------------------------------------------
setBootable = $coroutine ({vbd, bootable}) ->
xapi = @getXapi vbd
{ _xapiRef: ref } = vbd
yield xapi.call 'VBD.set_bootable', ref, bootable
return
setBootable.params = {
vbd: { type: 'string' }
bootable: { type: 'boolean' }
}
setBootable.resolve = {
vbd: ['vbd', 'VBD', 'administrate'],
}
exports.setBootable = setBootable
#=====================================================================
Object.defineProperty(exports, '__esModule', {
value: true
})

82
src/api/vbd.js Normal file
View File

@ -0,0 +1,82 @@
// FIXME: too low level, should be removed.
async function delete_ ({vbd}) {
await this.getXapi(vbd).deleteVbd(vbd)
}
delete_.params = {
id: { type: 'string' },
}
delete_.resolve = {
vbd: ['id', 'VBD', 'administrate'],
}
export { delete_ as delete }
// -------------------------------------------------------------------
export async function disconnect ({vbd}) {
const xapi = this.getXapi(vbd)
await xapi.disconnectVbd(vbd._xapiRef)
}
disconnect.params = {
id: { type: 'string' },
}
disconnect.resolve = {
vbd: ['id', 'VBD', 'administrate'],
}
// -------------------------------------------------------------------
export async function connect ({vbd}) {
const xapi = this.getXapi(vbd)
await xapi.connectVbd(vbd._xapiRef)
}
connect.params = {
id: { type: 'string' },
}
connect.resolve = {
vbd: ['id', 'VBD', 'administrate'],
}
// -------------------------------------------------------------------
export async function set ({position, vbd}) {
if (position !== undefined) {
const xapi = this.getXapi(vbd)
await xapi.call('VBD.set_userdevice', vbd._xapiRef, String(position))
}
}
set.params = {
// Identifier of the VBD to update.
id: { type: 'string' },
position: { type: ['string', 'number'], optional: true },
}
set.resolve = {
vbd: ['id', 'VBD', 'administrate'],
}
// -------------------------------------------------------------------
export async function setBootable ({vbd, bootable}) {
const xapi = this.getXapi(vbd)
await xapi.call('VBD.set_bootable', vbd._xapiRef, bootable)
}
setBootable.params = {
vbd: { type: 'string' },
bootable: { type: 'boolean' },
}
setBootable.resolve = {
vbd: ['vbd', 'VBD', 'administrate'],
}