Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
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])
Ejemplo n.º 5
0
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])
Ejemplo n.º 6
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])
Ejemplo n.º 7
0
def test_split_ref_exc():
    with pytest.raises(ValueError):
        util.split_ref('asdf123a')
    with pytest.raises(ValueError):
        util.split_ref('123asdf')
Ejemplo n.º 8
0
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')
Ejemplo n.º 9
0
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")
Ejemplo n.º 10
0
def test_split_ref_exc():
    with pytest.raises(ValueError):
        util.split_ref("asdf123a")
    with pytest.raises(ValueError):
        util.split_ref("123asdf")
Ejemplo n.º 11
0
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")
Ejemplo n.º 12
0
def test_split_ref_exc():
    with pytest.raises(ValueError):
        util.split_ref("asdf123a")
    with pytest.raises(ValueError):
        util.split_ref("123asdf")