peeringdb

PeeringDB module.

exception spicerack.peeringdb.CacheMiss[source]

Bases: SpicerackError

Custom exception class for cache management.

exception spicerack.peeringdb.PeeringDBError[source]

Bases: SpicerackError

Custom exception class for errors of the PeeringDB class.

class spicerack.peeringdb.PeeringDB(*, ttl: int = 86400, cachedir: Optional[Path] = None, proxies: Optional[MutableMapping[str, str]] = None, token: str = '')[source]

Bases: object

Basic dumb wrapper over the PeeringDB API.

Implements the beta/v0 PeeringDB API. Tries to be smart by:

  1. keeping a persistent keep-alived session for multiple requests

  2. operating a local filesystem cache, if so desired.

Initiliaze the module.

Parameters
  • ttl (int) -- TTL for cached objects.

  • cachedir (Path, optional) -- Root path for objects caching.

  • proxies (MutableMapping, optional) -- Proxies for Internet access.

  • token (str, optional) -- PeeringDB read-only token.

fetch(resource: str, resource_id: Optional[int] = None, filters: Optional[Dict] = None) Dict[source]

Get a PeeringDB resource.

Parameters
  • resource (str) -- The PeeringDB resource requested

  • resource_id (int) -- Optional resource number

  • filters (dict) -- A dictionary of addtional filter parameters

Returns

dict: A dictionary representing the data

fetch_asn(asn: int) Dict[source]

Fetch a specific asn.

Parameters

asn (int) -- The Autonomous system number

Returns

dict: A dictionary representing the data