Skip to content

Instantly share code, notes, and snippets.

@rmk40 rmk40/snapshot-via-rebase
Last active Dec 11, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.