def get(config, depth, output_format, poids): """ get an object from peeringdb """ pdb = client.PeeringDB(conf_dir=config) codec = munge.get_codec(output_format)() for poid in poids: (typ, pk) = util.split_ref(poid) data = pdb.get(typ, pk, depth=depth) codec.dump(data, sys.stdout)
def handle(config, poids, output_format, depth, remote, **_): client = Client(config) for poid in poids: (tag, pk) = util.split_ref(poid) res = resource.get_resource(tag) B = peeringdb.get_backend() try: obj = client.get(res, pk) except B.object_missing_error(B.get_concrete(res)): if remote: obj = client.fetch(res, pk, depth)[0] else: print(f"Not found: {tag}-{pk}", file=sys.stderr) return 1 dump(obj, depth, sys.stdout)
def whois(config, poids): """ simulate a whois lookup supports as<ASN> : query by AS ixlans<net id> : query networks on an IX """ pdb = client.PeeringDB(conf_dir=config) fmt = WhoisFormat() for poid in poids: (typ, pk) = util.split_ref(poid) (typ, data) = pdb.whois(typ, pk) fmt.print(typ, data[0])
def handle(config, poids, **_): client = Client(config) def get(res, **kwargs): objs = client.fetch_all(res, depth=2, **kwargs) if not objs: raise peeringdb.sync.NotFoundException return objs fmt = WhoisFormat() for poid in poids: (tag, key) = util.split_ref(poid) try: data = _lookup_tag(tag, key, get) except peeringdb.sync.NotFoundException: print(f"Not found: resource for {tag}={key}", file=sys.stderr) return 1 fmt.display(tag, data[0])
def test_split_ref_exc(): with pytest.raises(ValueError): util.split_ref('asdf123a') with pytest.raises(ValueError): util.split_ref('123asdf')
def test_split_ref(): assert ('net', 20) == util.split_ref('net20') assert ('net', 20) == util.split_ref('NET20') assert ('net', 20) == util.split_ref('net 20') assert ('net', 20) == util.split_ref('net-20')
def test_split_ref(): assert ("net", 20) == util.split_ref("net20") assert ("net", 20) == util.split_ref("NET20") assert ("net", 20) == util.split_ref("net 20") assert ("net", 20) == util.split_ref("net-20")
def test_split_ref_exc(): with pytest.raises(ValueError): util.split_ref("asdf123a") with pytest.raises(ValueError): util.split_ref("123asdf")