From e4fd4f858c10e988b30e3dac21dfbbd9a08d183e Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sun, 10 Jun 2018 21:07:21 -0400 Subject: [PATCH] Don't try to stop a stopped VM when undefining --- pvc.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pvc.py b/pvc.py index 37e1d7f9..e8420c07 100755 --- a/pvc.py +++ b/pvc.py @@ -205,15 +205,17 @@ def undefine_vm(dom_name, dom_uuid): click.echo('ERROR: Could not find VM "{}" in the cluster!'.format(message_name)) return - click.echo('Forcibly stopping VM "{}".'.format(dom_uuid)) - # Set the domain into stop mode - transaction = zk.transaction() - transaction.set_data('/domains/{}/state'.format(dom_uuid), 'stop'.encode('ascii')) - results = transaction.commit() + current_vm_state = zk.get('/domains/{}/state'.format(dom_uuid))[0].decode('ascii') + if current_vm_state != 'stop': + click.echo('Forcibly stopping VM "{}".'.format(dom_uuid)) + # Set the domain into stop mode + transaction = zk.transaction() + transaction.set_data('/domains/{}/state'.format(dom_uuid), 'stop'.encode('ascii')) + transaction.commit() - # Wait for 3 seconds to allow state to flow to all hypervisors - click.echo('Waiting for cluster to update.') - time.sleep(3) + # Wait for 3 seconds to allow state to flow to all hypervisors + click.echo('Waiting for cluster to update.') + time.sleep(3) # Delete the configurations click.echo('Undefining VM "{}".'.format(dom_uuid))