1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-07-28 15:41:52 +03:00

Move python example programs into python/examples/ subdirectory

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange
2013-11-22 15:55:39 +00:00
parent 70b8c9a2a3
commit 34aa32ba8a
10 changed files with 1139 additions and 0 deletions

40
examples/domsave.py Executable file
View File

@ -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()