def filter_by_prefix(cls, prefix, reql=False): return cls.filter(lambda a: r.ip_prefix_contains( r.ip_prefix(prefix['network'], prefix['length']), r.ip_address(a['ip']) ), reql=reql)
def get_by_ip(cls, vrf, ip, reql=False): query = cls.filter(lambda p: r.ip_prefix_contains( r.ip_prefix(p['network'], p['length']), r.ip_address(ip) ), reql=True) \ .filter({'vrf': vrf}) \ .order_by(r.desc("length")).nth(0) if reql: return query else: try: return query.run(get_connection()) except r.errors.ReqlNonExistenceError: raise RethinkObjectNotFound("no prefix found for IP %s" % ip)
def filter_by_block(cls, block, reql=False): return cls.filter(lambda p: r.ip_prefix_contains( r.ip_prefix(block['network'], block['length']), r.ip_address(p['network'])), reql=reql)