'Creates a volume from a snapshot.'

def create_volume_from_snapshot(self, volume, snapshot):

    src_volume = None
    vgID = None
    snapshotID = snapshot['id']
    src_volumeID = snapshot['volume_id']
    cgsnapshotID = snapshot.get('group_snapshot_id', None)
    if cgsnapshotID:
        try:
            src_volume = self.db.volume_get(src_volumeID)
        except Exception:
            msg = (_('Flexvisor    unable    to    find    the    source    volume    %(id)s    info.') % {'id': src_volumeID})
            raise exception.VolumeBackendAPIException(data=msg)
    if src_volume:
        vgID = src_volume.group_id
    if vgID:
        snapshotID = self._get_snapshotid_of_vgsnapshot(self._conver_uuid2hex(vgID), self._conver_uuid2hex(cgsnapshotID), self._conver_uuid2hex(src_volumeID))
    pool = volume_utils.extract_host(volume['host'], level='pool')
    if (not pool):
        if (not self.configuration.dpl_pool):
            msg = _('Pool    is    not    available    in    the    volume    host    fields.')
            raise exception.InvalidHost(reason=msg)
        else:
            pool = self.configuration.dpl_pool
    (ret, output) = self.dpl.create_vdev_from_snapshot(self._conver_uuid2hex(volume['id']), volume.get('display_name', ''), volume.get('display_description', ''), self._conver_uuid2hex(snapshotID), pool, self.configuration.san_thin_provision)
    if (ret == errno.EAGAIN):
        (ret, event_uuid) = self._get_event_uuid(output)
        if (ret == 0):
            status = self._wait_event(self.dpl.get_vdev_status, volume['id'], event_uuid)
            if (status['state'] != 'available'):
                msg = (_('Flexvisor    failed    to    create    volume    from    snapshot    %(id)s:%(status)s.') % {'id': snapshot['id'], 'status': ret})
                raise exception.VolumeBackendAPIException(data=msg)
        else:
            msg = (_('Flexvisor    failed    to    create    volume    from    snapshot    (failed    to    get    event)    %(id)s.') % {'id': snapshot['id']})
            raise exception.VolumeBackendAPIException(data=msg)
    elif (ret != 0):
        msg = (_('Flexvisor    failed    to    create    volume    from    snapshot    %(id)s:    %(status)s.') % {'id': snapshot['id'], 'status': ret})
        raise exception.VolumeBackendAPIException(data=msg)
    else:
        LOG.info('Flexvisor    succeeded    to    create    volume    %(id)s    from    snapshot.', {'id': volume['id']})
    if (volume['size'] > snapshot['volume_size']):
        self.extend_volume(volume, volume['size'])
    if volume.group_id:
        group = volume_utils.group_get_by_id(volume.group_id)
        if volume_utils.is_group_a_cg_snapshot_type(group):
            try:
                self._join_volume_group(volume, volume.group_id)
            except Exception:
                self.dpl.delete_vdev(self._conver_uuid2hex(volume['id']))
                raise
