Implement VM metadata and use it

Implements the storing of three VM metadata attributes:
1. Node limits - allows specifying a list of hosts on which the VM must
run. This limit influences the migration behaviour of VMs.
2. Per-VM node selectors - allows each VM to have its migration
autoselection method specified, to automatically allow different methods
per VM based on the administrator's preferences.
3. VM autorestart - allows a VM to be automatically restarted from a
stopped state, presumably due to a failure to find a target node (either
due to limits or otherwise) during a flush/fence recovery, on the next
node unflush/ready state of its home hypervisor. Useful mostly in
conjunction with limits to ensure that VMs which were shut down due to
there being no valid migration targets are started back up when their
node becomes ready again.

Includes the full client interaction with these metadata options,
including printing, as well as defining a new function to modify this
metadata. For the CLI it is set/modified either on `vm define` or via the
`vm meta` command. For the API it is set/modified either on a POST to
the `/vm` endpoint (during VM definition) or on POST to the `/vm/<vm>`
endpoint. For the API this replaces the previous reserved word for VM
creation from scratch as this will no longer be implemented in-daemon
(see #22).

Closes #52
This commit is contained in:
2019-10-12 01:17:39 -04:00
parent 94501f400f
commit 5995353597
10 changed files with 233 additions and 51 deletions

View File

@ -235,11 +235,23 @@ def api_vm_root():
else:
node = None
# Get target selector
# Set target limit metadata
if 'limit' in flask.request.values:
limit = flask.request.values['limit']
else:
limit = None
# Set target selector metadata
if 'selector' in flask.request.values:
selector = flask.request.values['selector']
else:
selector = None
selector = 'mem'
# Set target autostart metadata
if 'autostart' in flask.request.values:
autostart = True
else:
autostart = False
return pvcapi.vm_define(vm, libvirt_xml, node, selector)
@ -251,8 +263,27 @@ def api_vm_element(vm):
return pvcapi.vm_list(None, None, vm, is_fuzzy=False)
if flask.request.method == 'POST':
# TODO: #22
flask.abort(501)
# Set target limit metadata
if 'limit' in flask.request.values:
limit = flask.request.values['limit']
else:
limit = None
# Set target selector metadata
if 'selector' in flask.request.values:
selector = flask.request.values['selector']
else:
selector = None
# Set target autostart metadata
if 'no-autostart' in flask.request.values:
autostart = False
elif 'autostart' in flask.request.values:
autostart = True
else:
autostart = None
return pvcapi.vm_meta(vm, limit, selector, autostart)
if flask.request.method == 'PUT':
libvirt_xml = flask.request.data