Port VM on-node tasks to Celery worker system

Adds Celery versions of the flush_locks, device_attach, and
device_detach functions.
This commit is contained in:
2023-11-05 22:32:41 -05:00
parent f0c2e9d295
commit 89681d54b9
9 changed files with 577 additions and 174 deletions

View File

@ -28,8 +28,6 @@ from threading import Thread
from xml.etree import ElementTree
from re import match
import daemon_lib.common as common
import pvcnoded.objects.VMConsoleWatcherInstance as VMConsoleWatcherInstance
@ -1058,54 +1056,3 @@ class VMInstance(object):
)
return True
# Primary command function
def vm_command(zkhandler, logger, this_node, data):
# Get the command and args
command, dom_uuid, *args = data.split()
if match("success-.*", command) or match("failure-.*", command):
return
logger.out(
'Getting command "{}" for domain "{}"'.format(command, dom_uuid), state="i"
)
# Verify that the VM is set to run on this node
domain = this_node.d_domain.get(dom_uuid, None)
if domain is None:
return False
if domain.getnode() != this_node.name:
return
# Lock the command queue
zk_lock = zkhandler.writelock("base.cmd.domain")
with zk_lock:
# Flushing VM RBD locks
if command == "flush_locks":
result = VMInstance.flush_locks(zkhandler, logger, dom_uuid, this_node)
# Attaching a device
elif command == "attach_device":
xml_spec = " ".join(args)
result = domain.attach_device(xml_spec)
# Detaching a device
elif command == "detach_device":
xml_spec = " ".join(args)
result = domain.detach_device(xml_spec)
# Command not defined
else:
result = False
# Command succeeded
if result:
# Update the command queue
zkhandler.write([("base.cmd.domain", "success-{}".format(data))])
# Command failed
else:
# Update the command queue
zkhandler.write([("base.cmd.domain", "failure-{}".format(data))])
# Wait 1 seconds before we free the lock, to ensure the client hits the lock
time.sleep(1)