Annet Netbox client
Project description
Annetbox - Netbox client used by annet and related projects
This project implements subset of Netbox API methods
Usage
- Install
syncorasyncversion
pip install 'annetbox[sync]'
- Create client instance according to your netbox version (only some are supported)
from annetbox.v37.client_sync import NetboxV37
netbox = NetboxV37(url="https://demo.netbox.dev", token="YOUR NETBOX TOKEN")
- Call methods
res = netbox.dcim_devices(limit=1)
Configuration
Verbose logging
For sync client
import http.client
import logging
logging.basicConfig()
http.client.HTTPConnection.debuglevel = 1
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
Custom SSL context
- Create context
import ssl
context = ssl.create_default_context(cafile="path/to/cacert.pem")
- Pass it to client
netbox = NetboxV37(url=url, token=token, ssl_context=context)
Development
Adding new methods
- Read openapi spec
- Edit
models.py - Edit
client_async.py, do not forget addinglimit/offset - Convert async code to sync
python transform_to_sync.py src/annetbox/v37/client_async.py > src/annetbox/v37/client_sync.py
python transform_to_sync.py src/annetbox/v41/client_async.py > src/annetbox/v41/client_sync.py
python transform_to_sync.py src/annetbox/v42/client_async.py > src/annetbox/v42/client_sync.py
Integration tests
Integration tests are declarade in tests/integration/definitions.yaml.
They are defined as call to specific client method:
#
# client.dcim_cables(limit=5)
#
- id: dcim_cables_01
method: dcim_cables
versions: ["v37", "v41", "v42"]
args:
limit: 5
Also supported chaining two calls:
#
# client.dcim_console_port(
# id=client.dcim_console_ports(limit=5)[0]
# )
#
- id: dcim_console_port_01
method: dcim_console_port
versions: ["v37", "v41", "v42"]
args:
id: !from_call
call: dcim_console_ports
args: {limit: 5}
extract: results[0].id
Frozen snapshot of data is stored in tests/integration/fixtures/v<client version>/<test case>/:
expected.yaml: holds name of a method, passed args and results.cassette.yaml: holds raw netbox query and response generated byvcrpylib.
Adding/modifying a test
- Spin up local netbox instances
make docker(once) - Edit
tests/integration/definitions.yaml - Run
make fixturesand commit new generated files.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file annetbox-1.0.0rc1.tar.gz.
File metadata
- Download URL: annetbox-1.0.0rc1.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd112f7e039aabeffd50989729aeeefed0dccf3fe47553b1040bb50de117f6fd
|
|
| MD5 |
68e1d2f439b35c882987570085e2d38b
|
|
| BLAKE2b-256 |
210ade77651159366055d3072c41a387a57cdcea360854037f514d3c7c08b5f2
|
Provenance
The following attestation bundles were made for annetbox-1.0.0rc1.tar.gz:
Publisher:
publish-to-pypi.yml on annetutil/annetbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
annetbox-1.0.0rc1.tar.gz -
Subject digest:
bd112f7e039aabeffd50989729aeeefed0dccf3fe47553b1040bb50de117f6fd - Sigstore transparency entry: 1572649063
- Sigstore integration time:
-
Permalink:
annetutil/annetbox@a47bbff5560bd308f3ffd307c4387f70322c522d -
Branch / Tag:
refs/tags/v1.0.0rc1 - Owner: https://github.com/annetutil
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@a47bbff5560bd308f3ffd307c4387f70322c522d -
Trigger Event:
push
-
Statement type:
File details
Details for the file annetbox-1.0.0rc1-py3-none-any.whl.
File metadata
- Download URL: annetbox-1.0.0rc1-py3-none-any.whl
- Upload date:
- Size: 27.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e5448f18d9e1cd6766b59a5191b32cfa6ecf4a8ef378426a152eed9820afbae
|
|
| MD5 |
155bf89f8a55391becd5f56a700c7195
|
|
| BLAKE2b-256 |
ae33382fed597ec11b6f3fd5709966e64335bc28284368adc3cc9bfcd659132d
|
Provenance
The following attestation bundles were made for annetbox-1.0.0rc1-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on annetutil/annetbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
annetbox-1.0.0rc1-py3-none-any.whl -
Subject digest:
8e5448f18d9e1cd6766b59a5191b32cfa6ecf4a8ef378426a152eed9820afbae - Sigstore transparency entry: 1572649070
- Sigstore integration time:
-
Permalink:
annetutil/annetbox@a47bbff5560bd308f3ffd307c4387f70322c522d -
Branch / Tag:
refs/tags/v1.0.0rc1 - Owner: https://github.com/annetutil
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@a47bbff5560bd308f3ffd307c4387f70322c522d -
Trigger Event:
push
-
Statement type: