diff --git a/src/api/vm.coffee b/src/api/vm.coffee index a5d29ee8f..4f6aa0ff3 100644 --- a/src/api/vm.coffee +++ b/src/api/vm.coffee @@ -211,7 +211,7 @@ create.params = { resourceSet: { type: 'string', optional: true - }, + } installation: { type: 'object' @@ -222,6 +222,16 @@ create.params = { } } + vgpuType: { + type: 'string', + optional: true + } + + gpuGroup: { + type: 'string', + optional: true + } + # Name/description of the new VM. name_label: { type: 'string' } name_description: { type: 'string', optional: true } @@ -310,6 +320,8 @@ create.params = { create.resolve = { template: ['template', 'VM-template', ''], + vgpuType: ['vgpuType', 'vgpuType', ''], + gpuGroup: ['gpuGroup', 'gpuGroup', ''], } exports.create = create @@ -1352,6 +1364,43 @@ createCloudInitConfigDrive.resolve = { } exports.createCloudInitConfigDrive = createCloudInitConfigDrive +#--------------------------------------------------------------------- + +createVgpu = $coroutine ({ vm, gpuGroup, vgpuType }) -> + # TODO: properly handle device. Can a VM have 2 vGPUS? + yield @getXapi(vm).createVgpu(vm._xapiId, gpuGroup._xapiId, vgpuType._xapiId) + + return true + +createVgpu.params = { + vm: { type: 'string' }, + gpuGroup: { type: 'string' }, + vgpuType: { type: 'string' } +} + +createVgpu.resolve = { + vm: ['vm', 'VM', 'administrate'], + gpuGroup: ['gpuGroup', 'gpuGroup', ''], + vgpuType: ['vgpuType', 'vgpuType', ''] +} +exports.createVgpu = createVgpu + +#--------------------------------------------------------------------- + +deleteVgpu = $coroutine ({ vgpu }) -> + yield @getXapi(vgpu).deleteVgpu(vgpu._xapiId) + + return true + +deleteVgpu.params = { + vgpu: { type: 'string' } +} + +deleteVgpu.resolve = { + vgpu: ['vgpu', 'vgpu', ''] +} +exports.deleteVgpu = deleteVgpu + #===================================================================== Object.defineProperty(exports, '__esModule', { diff --git a/src/xapi-object-to-xo.js b/src/xapi-object-to-xo.js index 24dfa35ee..e79301612 100644 --- a/src/xapi-object-to-xo.js +++ b/src/xapi-object-to-xo.js @@ -675,6 +675,7 @@ const TRANSFORMS = { dom0Access: obj.dom0_access, enabledVgpuTypes: link(obj, 'enabled_VGPU_types'), + gpuGroup: link(obj, 'GPU_group'), isSystemDisplayDevice: Boolean(obj.is_system_display_device), pci: link(obj, 'PCI'), supportedVgpuMaxCapcities: link(obj, 'supported_VGPU_max_capacities'), @@ -692,7 +693,7 @@ const TRANSFORMS = { vgpu (obj) { return { - type: 'VGPU', + type: 'vgpu', currentlyAttached: Boolean(obj.currently_attached), device: obj.device, @@ -730,12 +731,12 @@ const TRANSFORMS = { experimental: Boolean(obj.experimental), framebufferSize: obj.framebuffer_size, - gpuGroup: link(obj, 'GPU_group'), + gpuGroups: link(obj, 'enabled_on_GPU_groups'), maxHeads: obj.max_heads, maxResolutionX: obj.max_resolution_x, maxResolutionY: obj.max_resolution_y, modelName: obj.model_name, - pgpu: link(obj, 'PGPU'), + pgpus: link(obj, 'enabled_on_PGPUs'), vendorName: obj.vendor_name, vgpus: link(obj, 'VGPUs') } diff --git a/src/xapi/mixins/gpu.js b/src/xapi/mixins/gpu.js new file mode 100644 index 000000000..bc65b1408 --- /dev/null +++ b/src/xapi/mixins/gpu.js @@ -0,0 +1,9 @@ +export default { + createVgpu (vm, gpuGroup, vgpuType) { + // TODO: properly handle device. Can a VM have 2 vGPUS? + return this.call('VGPU.create', this.getObject(vm).$ref, this.getObject(gpuGroup).$ref, '0', {}, this.getObject(vgpuType).$ref) + }, + deleteVgpu (vgpu) { + return this.call('VGPU.destroy', this.getObject(vgpu).$ref) + } +} diff --git a/src/xapi/mixins/vm.js b/src/xapi/mixins/vm.js index f3cbe18ad..1b744c0e5 100644 --- a/src/xapi/mixins/vm.js +++ b/src/xapi/mixins/vm.js @@ -41,6 +41,9 @@ export default { coreOs = false, cloudConfig = undefined, + vgpuType = undefined, + gpuGroup = undefined, + ...props } = {}, checkLimits) { const installMethod = (() => { @@ -187,7 +190,9 @@ export default { ))) } - // TODO: Assign VGPUs. + if (vgpuType !== undefined && gpuGroup !== undefined) { + await this.createVgpu(vm, gpuGroup, vgpuType) + } if (cloudConfig != null) { // Refresh the record.