Compare commits

...

1 Commits

Author SHA1 Message Date
b-Nollet
de4efdaf7a feat(xo-server): implement VUSB API 2024-02-21 17:19:41 +01:00
4 changed files with 87 additions and 0 deletions

View File

@@ -7,3 +7,4 @@ export { default as VDI } from './vdi.mjs'
export { default as VIF } from './vif.mjs'
export { default as VM } from './vm.mjs'
export { default as VTPM } from './vtpm.mjs'
export { default as VUSB } from './vusb.mjs'

View File

@@ -0,0 +1,16 @@
import ignoreErrors from 'promise-toolbox/ignoreErrors'
export default class Vusb {
async create(VM, USB_group) {
return this.call('VUSB.create', VM, USB_group)
}
async unplug(ref) {
await this.call('VUSB.unplug', ref)
}
async destroy(ref) {
await ignoreErrors.call(this.VUSB_unplug(ref))
await this.call('VUSB.destroy', ref)
}
}

View File

@@ -0,0 +1,42 @@
// Creates a VUSB which will be plugged to the VM at its next restart
// Only one VUSB can be attached to a given USB_group, and up to six VUSB can be attached to a VM.
export async function create({ vm, usbGroup }) {
const xapi = this.getXapi(vm)
const vusbRef = await xapi.VUSB_create(vm._xapiRef, usbGroup._xapiRef)
return xapi.getField('VUSB', vusbRef, 'uuid')
}
create.params = {
vmId: { type: 'string' },
usbGroupId: { type: 'string' },
}
create.resolve = {
vm: ['vmId', 'VM', 'administrate'],
usbGroup: ['usbGroupId', 'USB_group', 'administrate'],
}
// Unplug VUSB until next VM restart
export async function unplug({ vusb }) {
await this.getXapi(vusb).VUSB_unplug(vusb._xapiRef)
}
unplug.params = {
id: { type: 'string' },
}
unplug.resolve = {
vusb: ['id', 'VUSB', 'administrate'],
}
export async function destroy({ vusb }) {
await this.getXapi(vusb).VUSB_destroy(vusb._xapiRef)
}
destroy.params = {
id: { type: 'string' },
}
destroy.resolve = {
vusb: ['id', 'VUSB', 'administrate'],
}

View File

@@ -882,6 +882,8 @@ const TRANSFORMS = {
}
},
// -----------------------------------------------------------------
vtpm(obj) {
return {
type: 'VTPM',
@@ -889,6 +891,32 @@ const TRANSFORMS = {
vm: link(obj, 'VM'),
}
},
// -----------------------------------------------------------------
vusb(obj) {
return {
type: 'VUSB',
vm: link(obj, 'VM'),
currentlyAttached: obj.currently_attached,
usbGroup: link(obj, 'USB_group'),
}
},
// -----------------------------------------------------------------
usb_group(obj) {
return {
type: 'USB_group',
PUSB: link(obj, 'PUSBs'),
VUSB: link(obj, 'VUSBs'),
nameDescription: obj.name_description,
nameLabel: obj.name_label,
otherConfig: obj.other_config,
}
},
}
// ===================================================================