Add virDomainCheckpoint APIs
[libvirt-python/ericb.git] / examples / domrestore.py
blob06fdfbc085e9da43b8eee6aee0f1c46e6c4a710a
1 #!/usr/bin/env python
2 # domstart - make sure a given domU is running, if not start it
4 import libvirt
5 import sys
6 import os
7 import libxml2
8 import pdb
10 def usage():
11 print('Usage: %s DIR' % sys.argv[0])
12 print(' Restore all the domains contained in DIR')
13 print(' It is assumed that all files in DIR are')
14 print(' images of domU\'s previously created with save')
16 if len(sys.argv) != 2:
17 usage()
18 sys.exit(2)
20 dir = sys.argv[1]
21 imgs = os.listdir(dir)
23 conn = libvirt.open(None)
24 if conn is None:
25 print('Failed to open connection to the hypervisor')
26 sys.exit(1)
28 for img in imgs:
29 file = os.path.join(dir, img)
30 print("Restoring %s ... " % img)
31 ret = conn.restore(file)
32 if ret == 0:
33 print("done")
34 else:
35 print("error %d" % ret)