How to use the peeringdb.get_backend function in peeringdb

To help you get started, we’ve selected a few peeringdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github peeringdb / peeringdb-py / tests / test_sync.py View on Github external
client = client_dup
    # sanity check - do we actually have a duplicate
    swapdup = client.get(Network, 9)
    d = client._fetcher.fetch_latest(Network, FIRST_NET, 0, since=0)
    assert d[0][0]['name'] == swapdup.name

    # obj that doesn't exist remotely
    assert client.get(Network, 12)

    rs = all_resources()
    client.update_all(rs, since=0)

    assert client.get(Network, FIRST_NET)

    # remotely deleted dup should be gone
    B = peeringdb.get_backend()
    with pytest.raises(B.object_missing_error()):
        client.get(Network, 12)
github peeringdb / peeringdb-py / tests / test_sync.py View on Github external
def test_reversed(client_empty):
    client = client_empty
    # sanity check for empty client
    B = peeringdb.get_backend()
    with pytest.raises(B.object_missing_error()):
        client.get(Network, FIRST_NET)

    rs = all_resources()
    rs = reversed(rs)
    client.update_all(rs)
github peeringdb / peeringdb-py / tests / test_sync.py View on Github external
def test_dry_run(client_empty):
    client = peeringdb.PeeringDB(helper.CONFIG, dry_run=True)
    rs = all_resources()
    client.update_all(rs)
    # still empty?
    with pytest.raises(peeringdb.get_backend().object_missing_error()):
        client.get(Network, FIRST_NET)
github peeringdb / peeringdb-py / peeringdb / util.py View on Github external
def __init__(self, concrete):
        backend = get_backend()
        kinds = {kind: {} for kind in FieldGroups.GROUPS}
        fields = backend.get_fields(concrete)
        for field in fields:
            name = field.name
            related, multiple = backend.is_field_related(concrete, name)

            if related:
                if multiple:
                    group = kinds['many_refs']
                else:
                    group = kinds['one_refs']
            else:
                group = kinds['scalars']

            group[name] = field
        self._fields = kinds
github peeringdb / peeringdb-py / peeringdb / client.py View on Github external
def get(self, res, pk):
        "Get a resource instance by primary key (id)"
        B = get_backend()
        return B.get_object(B.get_concrete(res), pk)
github peeringdb / peeringdb-py / peeringdb / client.py View on Github external
def all(self, res):
        "Get resources using a filter condition"
        B = get_backend()
        return B.get_objects(B.get_concrete(res))