Convert from exclusive to write lock
This commit is contained in:
parent
017953c2e6
commit
88556f4a33
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue