File: domsave.py

package info (click to toggle)
libvirt 0.8.3-5%2Bsqueeze5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 77,288 kB
  • ctags: 30,516
  • sloc: ansic: 177,367; xml: 26,161; sh: 13,271; python: 4,929; makefile: 2,083; ml: 472; perl: 221; awk: 48; sed: 16
file content (40 lines) | stat: -rwxr-xr-x 858 bytes parent folder | download | duplicates (2)
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
37
38
39
40
#! /usr/bin/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 '       Save all currently running domU\'s into DIR'
   print '       DIR must exist and be writable by this process'

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

dir = sys.argv[1]

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

doms = conn.listDomainsID()
for id in doms:
    if id == 0:
        continue
    dom = conn.lookupByID(id)
    print "Saving %s[%d] ... " % (dom.name(), id),
    sys.stdout.flush()
    path = os.path.join(dir, dom.name())
    ret = dom.save(path)
    if ret == 0:
        print "done"
    else:
        print "error %d" % ret

#pdb.set_trace()