diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2013-11-22 14:36:37 +0000 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2013-11-22 14:44:45 +0000 |
commit | 3d9e3178c4d2e18425ba6df23f27ee7b1da07453 (patch) | |
tree | e9f7ce2c8481adda52bf489263403a30e01772f3 /examples/domsave.py | |
parent | d163eef08210826d17cff668ec78e8cb769e57d9 (diff) | |
download | libvirt-python-v8-3d9e3178c4d2e18425ba6df23f27ee7b1da07453.tar.gz libvirt-python-v8-3d9e3178c4d2e18425ba6df23f27ee7b1da07453.tar.xz libvirt-python-v8-3d9e3178c4d2e18425ba6df23f27ee7b1da07453.zip |
Move python example programs into python/examples/ subdirectory
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'examples/domsave.py')
-rwxr-xr-x | examples/domsave.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/domsave.py b/examples/domsave.py new file mode 100755 index 0000000..bac4536 --- /dev/null +++ b/examples/domsave.py @@ -0,0 +1,40 @@ +#!/usr/bin/env 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 ' Save all currently running domU\'s into DIR' + print ' DIR must exist and be writable by this process' + +if len(sys.argv) != 2: + usage() + sys.exit(2) + +dir = sys.argv[1] + +conn = libvirt.open(None) +if conn is None: + print 'Failed to open connection to the hypervisor' + sys.exit(1) + +doms = conn.listDomainsID() +for id in doms: + if id == 0: + continue + dom = conn.lookupByID(id) + print "Saving %s[%d] ... " % (dom.name(), id), + sys.stdout.flush() + path = os.path.join(dir, dom.name()) + ret = dom.save(path) + if ret == 0: + print "done" + else: + print "error %d" % ret + +#pdb.set_trace() |