Backends¶
A backend is the code that talks to one RIR's API. The plugin ships one: ARIN, through pyregrws.
Current state¶
The plugin is laid out for several backends, but only ARIN is wired in:
netbox_rir_manager/backends/base.pydefines the abstractRIRBackendinterface.netbox_rir_manager/backends/__init__.pykeeps a registry: the@register_backenddecorator adds a class toBACKENDSunder itsname, andget_backend(name)looks one up.- The views, REST API actions and jobs construct
ARINBackenddirectly. Nothing looks a backend up from the registry or from the RIR of a config, and there is no setting to choose backends.
Adding another RIR therefore takes more than a new RIRBackend subclass: the call sites must also choose the backend for each config. The sync also relies on find_net, which ARINBackend provides but RIRBackend does not declare.
The RIRBackend interface¶
| Method | Returns |
|---|---|
authenticate(rir_config) |
Whether the credentials work. |
get_organization(handle) |
The organization as a dict, or None. |
get_poc(handle) |
The point of contact as a dict, or None. |
get_network(handle) |
The network as a dict, or None. |
get_customer(handle) |
The customer as a dict, or None. |
get_asn(asn) |
The ASN as a dict, or None. |
sync_resources(rir_config, resource_type=None) |
A list of synced resource dicts. |
update_network(handle, data) |
The updated network dict, or None. |
reassign_network(parent_handle, net_data) |
Ticket details, or None. |
reallocate_network(parent_handle, net_data) |
Ticket details, or None. |
remove_network(handle) |
True on success. |
delete_network(handle) |
Ticket details, or None. |
create_customer(parent_net_handle, data) |
The customer as a dict, or None. |
For the write methods, None (or False from remove_network) means the RIR could not be reached. Two exceptions from backends/base.py report the other failures, and their messages are shown to the user:
RIRDataError: the data cannot form a valid request, so nothing was sent. The REST API answers400.RIRRequestError: the RIR refused the request; the message is the RIR's reason. The REST API answers502.
The ARIN backend¶
ARINBackend (netbox_rir_manager/backends/arin.py) registers itself under the name ARIN.
- Connection:
ARINBackend.for_user_key(user_key)builds apyregrwsclient with the key's API key and, when set, the key's config's API URL in place of thepyregrwsdefault. - Retries: every call is retried on
ConnectionError,OSErrorandTimeoutError, as set byapi_retry_countandapi_retry_backoff(see Settings). An error response from ARIN is not retried. - Reads return
Nonewhen the call fails or ARIN answers with an error. - Writes raise
RIRRequestErrorwith ARIN's reason when ARIN answers with an error, and raiseRIRDataErrorwhenpyregrwsrejects the payload or the customer's country is not an ISO 3166-1 alpha-2 code. Customer details are converted to ASCII before they are sent. - Not implemented:
get_asnalways returnsNoneandsync_resourcesalways returns an empty list. The sync does not use them; it callsget_organization,get_poc,find_netandget_networkitself (see Syncing Resources).