File: domrestore.py

package info (click to toggle)
libvirt-python 11.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,428 kB
  • sloc: ansic: 10,787; python: 4,608; xml: 910; makefile: 19
file content (31 lines) | stat: -rwxr-xr-x 690 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3
"""
Restore all the domains contained in DIR.
It is assumed that all files in DIR are images of domU's previously created with save.
"""

import libvirt
import os
from argparse import ArgumentParser


parser = ArgumentParser(description=__doc__)
parser.add_argument("dir")
args = parser.parse_args()

imgs = os.listdir(args.dir)

try:
    conn = libvirt.open(None)
except libvirt.libvirtError:
    print('Failed to open connection to the hypervisor')
    exit(1)

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