libvirt/examples/python/domrestore.py
Daniel P. Berrange cebeba7bd7 Move docs/examples into examples/
* Makefile.am: Add examples/dominfo examples/domsuspend examples/python
  as SUBDIRS
* configure.in: Update AC_OUTPUT for new/old Makefiles
* docs/Makefile.am: Remove examples from SUBDIRS
* docs/examples/info1.c: Move to examples/dominfo/info1.c
* docs/examples/suspend.c: Move to examples/domsuspend/suspend.c
* docs/examples: Remove all remaining files
* docs/examples/python: Moved to examples/python/
* examples/dominfo/Makefile.am, examples/domsuspend/Makefile.am: New
  build files
* libvirt.spec.in: Update to take account of moved examples
2009-09-21 14:41:46 +01:00

37 lines
811 B
Python
Executable File

#! /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 ' Restore all the domains contained in DIR'
print ' It is assumed that all files in DIR are'
print ' images of domU\'s previously created with save'
if len(sys.argv) != 2:
usage()
sys.exit(2)
dir = sys.argv[1]
imgs = os.listdir(dir)
conn = libvirt.open(None)
if conn == None:
print 'Failed to open connection to the hypervisor'
sys.exit(1)
for img in imgs:
file = os.path.join(dir, img)
print "Restoring %s ... " % img,
sys.stdout.flush()
ret = conn.restore(file)
if ret == 0:
print "done"
else:
print "error %d" % ret