Last active
December 11, 2015 14:58
-
-
Save rmk40/4617831 to your computer and use it in GitHub Desktop.
Proof of concept for blockRebase-based snapshots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import libvirt | |
import os | |
import sys | |
import time | |
import uuid | |
try: | |
instance_name = sys.argv[1] | |
except: | |
sys.exit(1) | |
conn = libvirt.open('qemu:///system') | |
domain = conn.lookupByName(instance_name) | |
try: | |
domain.undefine() | |
except: | |
pass | |
try: | |
domain.blockJobAbort('vda', 0) | |
except: | |
pass | |
snapshot_name = os.path.join('/tmp', 'snap-' + str(uuid.uuid4())) | |
domain.blockRebase('vda', snapshot_name, 0, libvirt.VIR_DOMAIN_BLOCK_REBASE_COPY) | |
def wait_for_block_job(domain): | |
status = domain.blockJobInfo('vda', 0) | |
if status is None: | |
return False | |
print status | |
cur = status.get('cur', 0) | |
end = status.get('end', 0) | |
if cur == end and cur != 0 and end != 0: | |
return False | |
else: | |
return True | |
while wait_for_block_job(domain): | |
print "Sleeping ... " | |
time.sleep(0.5) | |
domain.blockJobAbort('vda', 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment