'Excludes subnets on segments not reachable by the host
The query gets two kinds of subnets: those that are on segments that
the host can reach and those that are not on segments at all (assumed
reachable by all hosts). Hence, subnets on segments that the host
*cannot* reach are excluded.'

@staticmethod
def _query_filter_by_segment_host_mapping(query, host):

    Subnet = models_v2.Subnet
    SegmentHostMapping = segment_model.SegmentHostMapping
    query = query.add_entity(SegmentHostMapping)
    query = query.outerjoin(SegmentHostMapping, and_((Subnet.segment_id == SegmentHostMapping.segment_id), (SegmentHostMapping.host == host)))
    query = query.filter(or_(and_(Subnet.segment_id.isnot(None), SegmentHostMapping.host.isnot(None)), and_(Subnet.segment_id.is_(None), SegmentHostMapping.host.is_(None))))
    return query
