daemon: Move TLS initialization to virInitialize
[libvirt/zwu.git] / examples / python / domrestore.py
blobccc82f633c5e5527082938dfe16c8e9b3a793d3a
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 == 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 sys.stdout.flush()
32 ret = conn.restore(file)
33 if ret == 0:
34 print "done"
35 else:
36 print "error %d" % ret