def temp_snapshot(driver, volume, src_vref): snapshot = {'volume_name': src_vref['name'], 'volume_id': src_vref['id'], 'volume_size': src_vref['size'], 'name': 'snapshot-clone-%s' % volume['id'], 'id': 'tmp-snap-%s' % volume['id'], 'size': src_vref['size']} driver.create_snapshot(snapshot) try: yield snapshot finally: driver.delete_snapshot(snapshot)