blob: c1090a5dba1921471755b17e1410da4030208bf4 (
plain)
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
|
#!/usr/bin/env python3
"""
Save all currently running domU's into DIR.
DIR must exist and be writable by this process.
"""
import libvirt
import os
from argparse import ArgumentParser
parser = ArgumentParser(description=__doc__)
parser.add_argument("dir")
args = parser.parse_args()
try:
conn = libvirt.open(None)
except libvirt.libvirtError:
print('Failed to open connection to the hypervisor')
exit(1)
doms = conn.listDomainsID()
for id in doms:
if id == 0:
continue
dom = conn.lookupByID(id)
print("Saving %s[%d] ... " % (dom.name(), id))
path = os.path.join(args.dir, dom.name())
ret = dom.save(path)
if ret == 0:
print("done")
else:
print("error %d" % ret)
# import pdb; pdb.set_trace()
|