def _sort_snapshots(self, volumes, snapshots):
    if ((not volumes) or (not snapshots) or (len(volumes) != len(snapshots))):
        msg = _('Input volumes or snapshots are invalid.')
        LOG.error(msg)
        raise exception.InvalidInput(reason=msg)
    sorted_snapshots = []
    for vol in volumes:
        found_snaps = [snap for snap in snapshots if (snap['id'] == vol['snapshot_id'])]
        if (not found_snaps):
            LOG.error(_LE('Source snapshot cannot be found for target volume %(volume_id)s.'), {'volume_id': vol['id']})
            raise exception.SnapshotNotFound(snapshot_id=vol['snapshot_id'])
        sorted_snapshots.extend(found_snaps)
    return sorted_snapshots
def _sort_snapshots(self, volumes, snapshots):
    if ((not volumes) or (not snapshots) or (len(volumes) != len(snapshots))):
        msg = _('Input volumes or snapshots are invalid.')
        LOG.error(msg)
        raise exception.InvalidInput(reason=msg)
    sorted_snapshots = []
    for vol in volumes:
        found_snaps = [snap for snap in snapshots if (snap['id'] == vol['snapshot_id'])]
        if (not found_snaps):
            LOG.error(_LE('Source snapshot cannot be found for target volume %(volume_id)s.'), {'volume_id': vol['id']})
            raise exception.SnapshotNotFound(snapshot_id=vol['snapshot_id'])
        sorted_snapshots.extend(found_snaps)
    return sorted_snapshots