From 88556f4a33565dc3ea19462b413d782c4dd2d469 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Wed, 21 Oct 2020 11:12:36 -0400 Subject: [PATCH] Convert from exclusive to write lock --- daemon-common/vm.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/daemon-common/vm.py b/daemon-common/vm.py index 222a5109..4c11fbb0 100644 --- a/daemon-common/vm.py +++ b/daemon-common/vm.py @@ -276,7 +276,7 @@ def modify_vm(zk_conn, domain, restart, new_vm_config): zkhandler.writedata(zk_conn, zk_data) if restart: - with zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): + with zkhandler.writelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'restart' }) return True, '' @@ -301,7 +301,7 @@ def undefine_vm(zk_conn, domain): current_vm_state = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(dom_uuid)) if current_vm_state != 'stop': # Set the domain into stop mode - with zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): + with zkhandler.writelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'stop' }) # Wait for 2 seconds to allow state to flow to all nodes @@ -328,7 +328,7 @@ def remove_vm(zk_conn, domain): current_vm_state = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(dom_uuid)) if current_vm_state != 'stop': # Set the domain into stop mode - with zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): + with zkhandler.writelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'stop' }) # Wait for 2 seconds to allow state to flow to all nodes @@ -360,7 +360,7 @@ def start_vm(zk_conn, domain): return False, 'ERROR: Could not find VM "{}" in the cluster!'.format(domain) # Set the VM to start - with zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): + with zkhandler.writelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'start' }) return True, 'Starting VM "{}".'.format(domain) @@ -379,7 +379,7 @@ def restart_vm(zk_conn, domain, wait=False): retmsg = 'Restarting VM "{}".'.format(domain) # Set the VM to restart - with zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): + with zkhandler.writelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'restart' }) if wait: @@ -403,7 +403,7 @@ def shutdown_vm(zk_conn, domain, wait=False): retmsg = 'Shutting down VM "{}"'.format(domain) # Set the VM to shutdown - with zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): + with zkhandler.writelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'shutdown' }) if wait: @@ -423,7 +423,7 @@ def stop_vm(zk_conn, domain): current_state = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(dom_uuid)) # Set the VM to start - with zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): + with zkhandler.writelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'stop' }) return True, 'Forcibly stopping VM "{}".'.format(domain) @@ -440,7 +440,7 @@ def disable_vm(zk_conn, domain): return False, 'ERROR: VM "{}" must be stopped before disabling!'.format(domain) # Set the VM to start - with zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): + with zkhandler.writelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'disable' }) return True, 'Marked VM "{}" as disable.'.format(domain) @@ -491,7 +491,7 @@ def move_vm(zk_conn, domain, target_node, wait=False, force_live=False): retmsg = 'Permanently migrating VM "{}" to node "{}".'.format(domain, target_node) - with zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): + with zkhandler.writelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): target_state, '/domains/{}/node'.format(dom_uuid): target_node, @@ -554,7 +554,7 @@ def migrate_vm(zk_conn, domain, target_node, force_migrate, wait=False, force_li retmsg = 'Migrating VM "{}" to node "{}".'.format(domain, target_node) - with zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): + with zkhandler.writelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): target_state, '/domains/{}/node'.format(dom_uuid): target_node, @@ -592,7 +592,7 @@ def unmigrate_vm(zk_conn, domain, wait=False, force_live=False): retmsg = 'Unmigrating VM "{}" back to node "{}".'.format(domain, target_node) - with zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): + with zkhandler.writelock(zk_conn, '/domains/{}/state'.format(dom_uuid)): zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): target_state, '/domains/{}/node'.format(dom_uuid): target_node,