File: domrestore.py

package info (click to toggle)
libvirt 0.9.12.3-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 115,024 kB
  • sloc: ansic: 324,394; xml: 44,112; sh: 15,676; python: 6,198; makefile: 2,916; perl: 2,003; ml: 472; sed: 16
file content (36 lines) | stat: -rwxr-xr-x 814 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# domstart - make sure a given domU is running, if not start it

import libvirt
import sys
import os
import libxml2
import pdb

def usage():
   print 'Usage: %s DIR' % sys.argv[0]
   print '       Restore all the domains contained in DIR'
   print '       It is assumed that all files in DIR are'
   print '       images of domU\'s previously created with save'

if len(sys.argv) != 2:
    usage()
    sys.exit(2)

dir = sys.argv[1]
imgs = os.listdir(dir)

conn = libvirt.open(None)
if conn == None:
    print 'Failed to open connection to the hypervisor'
    sys.exit(1)

for img in imgs:
    file = os.path.join(dir, img)
    print "Restoring %s ... " % img,
    sys.stdout.flush()
    ret = conn.restore(file)
    if ret == 0:
        print "done"
    else:
        print "error %d" % ret