Skip to content

Instantly share code, notes, and snippets.

@rmk40
Last active December 11, 2015 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmk40/4617831 to your computer and use it in GitHub Desktop.
Save rmk40/4617831 to your computer and use it in GitHub Desktop.
Proof of concept for blockRebase-based snapshots
#!/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