| 1 |
|
| 2 |
""" |
| 3 |
Save all currently running domU's into DIR. |
| 4 |
DIR must exist and be writable by this process. |
| 5 |
""" |
| 6 |
|
| 7 |
import libvirt |
| 8 |
import os |
| 9 |
from argparse import ArgumentParser |
| 10 |
|
| 11 |
|
| 12 |
parser = ArgumentParser(description=__doc__) |
| 13 |
parser.add_argument("dir") |
| 14 |
args = parser.parse_args() |
| 15 |
|
| 16 |
try: |
| 17 |
conn = libvirt.open(None) |
| 18 |
except libvirt.libvirtError: |
| 19 |
print('Failed to open connection to the hypervisor') |
| 20 |
exit(1) |
| 21 |
|
| 22 |
doms = conn.listDomainsID() |
| 23 |
for id in doms: |
| 24 |
if id == 0: |
| 25 |
continue |
| 26 |
dom = conn.lookupByID(id) |
| 27 |
print("Saving %s[%d] ... " % (dom.name(), id)) |
| 28 |
path = os.path.join(args.dir, dom.name()) |
| 29 |
ret = dom.save(path) |
| 30 |
if ret == 0: |
| 31 |
print("done") |
| 32 |
else: |
| 33 |
print("error %d" % ret) |
| 34 |
|
| 35 |
|