Add VM device hot attach/detach support

Adds a new API endpoint to support hot attach/detach of devices, and the
corresponding client-side logic to use this endpoint when doing VM
network/storage add/remove actions.

The live attach is now the default behaviour for these types of
additions and removals, and can be disabled if needed.

Closes #141
This commit is contained in:
2021-09-12 15:41:05 -04:00
parent 5841c98a59
commit 73c96d1e93
6 changed files with 500 additions and 83 deletions

View File

@ -2003,6 +2003,72 @@ class API_VM_Rename(Resource):
api.add_resource(API_VM_Rename, '/vm/<vm>/rename')
# /vm/<vm>/device
class API_VM_Device(Resource):
@RequestParser([
{'name': 'xml', 'required': True, 'helptext': "A Libvirt XML device document must be specified"},
])
@Authenticator
def post(self, vm, reqargs):
"""
Hot-attach device XML to {vm}
---
tags:
- vm
parameters:
- in: query
name: xml
type: string
required: true
description: The raw Libvirt XML definition of the device to attach
responses:
200:
description: OK
schema:
type: object
id: Message
400:
description: Bad request
schema:
type: object
id: Message
"""
return api_helper.vm_attach_device(vm, reqargs.get('xml', None))
@RequestParser([
{'name': 'xml', 'required': True, 'helptext': "A Libvirt XML device document must be specified"},
])
@Authenticator
def delete(self, vm, reqargs):
"""
Hot-detach device XML to {vm}
---
tags:
- vm
parameters:
- in: query
name: xml
type: string
required: true
description: The raw Libvirt XML definition of the device to detach
responses:
200:
description: OK
schema:
type: object
id: Message
400:
description: Bad request
schema:
type: object
id: Message
"""
return api_helper.vm_detach_device(vm, reqargs.get('xml', None))
api.add_resource(API_VM_Device, '/vm/<vm>/device')
##########################################################
# Client API - Network
##########################################################