'Create volume from snapshot.
- search for snapshot and retention_policy
- create a view from snapshot and attach view
- create a volume and attach volume
- copy data from attached view to attached volume
- detach volume and view and finally delete view'

@kaminario_logger
def create_volume_from_snapshot(self, volume, snapshot):

    snap_name = self.get_snap_name(snapshot.id)
    view_name = self.get_view_name(volume.id)
    vol_name = self.get_volume_name(volume.id)
    cview = src_attach_info = dest_attach_info = None
    rpolicy = self.get_policy()
    properties = utils.brick_get_connector_properties()
    LOG.debug('Searching    for    snapshot:    %s    in    K2.', snap_name)
    snap_rs = self.client.search('snapshots', short_name=snap_name)
    if (hasattr(snap_rs, 'hits') and (snap_rs.total != 0)):
        snap = snap_rs.hits[0]
        LOG.debug('Creating    a    view:    %(view)s    from    snapshot:    %(snap)s', {'view': view_name, 'snap': snap_name})
        try:
            cview = self.client.new('snapshots', short_name=view_name, source=snap, retention_policy=rpolicy, is_exposable=True).save()
        except Exception as ex:
            LOG.exception('Creating    a    view:    %(view)s    from    snapshot:    %(snap)s    failed', {'view': view_name, 'snap': snap_name})
            raise exception.KaminarioCinderDriverException(reason=ex)
    else:
        msg = (_('Snapshot:    %s    search    failed    in    K2.') % snap_name)
        LOG.error(msg)
        raise exception.KaminarioCinderDriverException(reason=msg)
    try:
        conn = self.initialize_connection(cview, properties)
        src_attach_info = self._connect_device(conn)
        self.create_volume(volume)
        conn = self.initialize_connection(volume, properties)
        dest_attach_info = self._connect_device(conn)
        vol_utils.copy_volume(src_attach_info['device']['path'], dest_attach_info['device']['path'], (snapshot.volume.size * units.Ki), self.configuration.volume_dd_blocksize, sparse=True)
        self._kaminario_disconnect_volume(src_attach_info, dest_attach_info)
        self.terminate_connection(volume, properties)
        self.terminate_connection(cview, properties)
        cview.delete()
    except Exception as ex:
        self._kaminario_disconnect_volume(src_attach_info, dest_attach_info)
        self.terminate_connection(cview, properties)
        self.terminate_connection(volume, properties)
        cview.delete()
        self.delete_volume(volume)
        LOG.exception('Copy    to    volume:    %(vol)s    from    view:    %(view)s    failed', {'vol': vol_name, 'view': view_name})
        raise exception.KaminarioCinderDriverException(reason=ex)
