| 1 |
|
| 2 |
""" |
| 3 |
Restore all the domains contained in DIR. |
| 4 |
It is assumed that all files in DIR are images of domU's previously created with save. |
| 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 |
imgs = os.listdir(args.dir) |
| 17 |
|
| 18 |
try: |
| 19 |
conn = libvirt.open(None) |
| 20 |
except libvirt.libvirtError: |
| 21 |
print('Failed to open connection to the hypervisor') |
| 22 |
exit(1) |
| 23 |
|
| 24 |
for img in imgs: |
| 25 |
file = os.path.join(args.dir, img) |
| 26 |
print("Restoring %s ... " % img) |
| 27 |
ret = conn.restore(file) |
| 28 |
if ret == 0: |
| 29 |
print("done") |
| 30 |
else: |
| 31 |
print("error %d" % ret) |