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)
|
zkhandler.writedata(zk_conn, zk_data)
|
||||||
|
|
||||||
if restart:
|
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' })
|
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'restart' })
|
||||||
|
|
||||||
return True, ''
|
return True, ''
|
||||||
|
@ -301,7 +301,7 @@ def undefine_vm(zk_conn, domain):
|
||||||
current_vm_state = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(dom_uuid))
|
current_vm_state = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(dom_uuid))
|
||||||
if current_vm_state != 'stop':
|
if current_vm_state != 'stop':
|
||||||
# Set the domain into stop mode
|
# 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' })
|
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'stop' })
|
||||||
|
|
||||||
# Wait for 2 seconds to allow state to flow to all nodes
|
# 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))
|
current_vm_state = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(dom_uuid))
|
||||||
if current_vm_state != 'stop':
|
if current_vm_state != 'stop':
|
||||||
# Set the domain into stop mode
|
# 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' })
|
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'stop' })
|
||||||
|
|
||||||
# Wait for 2 seconds to allow state to flow to all nodes
|
# 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)
|
return False, 'ERROR: Could not find VM "{}" in the cluster!'.format(domain)
|
||||||
|
|
||||||
# Set the VM to start
|
# 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' })
|
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'start' })
|
||||||
|
|
||||||
return True, 'Starting VM "{}".'.format(domain)
|
return True, 'Starting VM "{}".'.format(domain)
|
||||||
|
@ -379,7 +379,7 @@ def restart_vm(zk_conn, domain, wait=False):
|
||||||
retmsg = 'Restarting VM "{}".'.format(domain)
|
retmsg = 'Restarting VM "{}".'.format(domain)
|
||||||
|
|
||||||
# Set the VM to restart
|
# 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' })
|
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'restart' })
|
||||||
|
|
||||||
if wait:
|
if wait:
|
||||||
|
@ -403,7 +403,7 @@ def shutdown_vm(zk_conn, domain, wait=False):
|
||||||
retmsg = 'Shutting down VM "{}"'.format(domain)
|
retmsg = 'Shutting down VM "{}"'.format(domain)
|
||||||
|
|
||||||
# Set the VM to shutdown
|
# 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' })
|
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'shutdown' })
|
||||||
|
|
||||||
if wait:
|
if wait:
|
||||||
|
@ -423,7 +423,7 @@ def stop_vm(zk_conn, domain):
|
||||||
current_state = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(dom_uuid))
|
current_state = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(dom_uuid))
|
||||||
|
|
||||||
# Set the VM to start
|
# 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' })
|
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'stop' })
|
||||||
|
|
||||||
return True, 'Forcibly stopping VM "{}".'.format(domain)
|
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)
|
return False, 'ERROR: VM "{}" must be stopped before disabling!'.format(domain)
|
||||||
|
|
||||||
# Set the VM to start
|
# 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' })
|
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'disable' })
|
||||||
|
|
||||||
return True, 'Marked VM "{}" as disable.'.format(domain)
|
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)
|
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, {
|
zkhandler.writedata(zk_conn, {
|
||||||
'/domains/{}/state'.format(dom_uuid): target_state,
|
'/domains/{}/state'.format(dom_uuid): target_state,
|
||||||
'/domains/{}/node'.format(dom_uuid): target_node,
|
'/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)
|
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, {
|
zkhandler.writedata(zk_conn, {
|
||||||
'/domains/{}/state'.format(dom_uuid): target_state,
|
'/domains/{}/state'.format(dom_uuid): target_state,
|
||||||
'/domains/{}/node'.format(dom_uuid): target_node,
|
'/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)
|
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, {
|
zkhandler.writedata(zk_conn, {
|
||||||
'/domains/{}/state'.format(dom_uuid): target_state,
|
'/domains/{}/state'.format(dom_uuid): target_state,
|
||||||
'/domains/{}/node'.format(dom_uuid): target_node,
|
'/domains/{}/node'.format(dom_uuid): target_node,
|
||||||
|
|
Loading…
Reference in New Issue