libvirt-restart-running: properly shutdown vms

master
neingeist 7 years ago
parent 7cd22de890
commit 51584914e5

@ -1,10 +1,9 @@
#!/usr/bin/python
#!/usr/bin/python3
# Restart all running libvirt domains
from __future__ import division, print_function
import libvirt
import sys
import time
conn = libvirt.open('qemu:///system')
if not conn:
@ -14,6 +13,12 @@ if not conn:
for domain in conn.listAllDomains():
name = domain.name()
if domain.isActive():
print('Restarting {}...'.format(name))
domain.destroyFlags(flags=libvirt.VIR_DOMAIN_DESTROY_GRACEFUL)
print('Restarting {}'.format(name), end='', flush=True)
domain.shutdown()
while domain.isActive():
print('.', end='', flush=True)
time.sleep(1)
print()
domain.create()

Loading…
Cancel
Save