Wrapper around requests module to query ISC Kea DHCP API Daemons (ctrlagent, dhcp4, dhcp6, ddns)
Project description
pyisckea is a python module used to interact with the ISC Kea DHCP daemons running on an ISC Kea server. This module also implements Pydantic to improve the developer experience when working in a code editor like VSCode and also provide super fast data validation functionality on python objects before they get serialized and sent to the Kea APIs.
Get Started
- Install the module.
pip install pyisckea
- Import the Kea class.
from pyisckea import Kea
server = Kea("http://localhost:8000")
- Call API commands based on the Daemon to interact with the APIs.
subnets_v4 = server.dhcp4.subnet4_list()
for subnet in subnets_v4:
print(subnet.subnet, subnet.option_data, subnet.relay, subnet.pools_list)
my_subnet = server.dhcp6.subnet4_get(name="pyisckea-pytest")
print(my_subnet.json(exclude_none=True, indent=4))
# {
# "valid_lifetime": 4000,
# "renew_timer": 1000,
# "rebind_timer": 2000,
# "option_data": [],
# "calculate_tee_times": true,
# "t1_percent": 0.5,
# "t2_percent": 0.8,
# "store_extended_info": false,
# "name": "pyisckea-pytest",
# "relay": {
# "ip-addresses": []
# },
# "subnet6": [
# {
# "valid_lifetime": 4000,
# "renew_timer": 1000,
# "rebind_timer": 2000,
# "option_data": [],
# "calculate_tee_times": true,
# "t1_percent": 0.5,
# "t2_percent": 0.8,
# "store_extended_info": false,
# "id": 40123,
# "subnet": "2001:db8::/64",
# "preferred_lifetime": 3600,
# "pd_pools": [],
# "rapid_commit": false
# }
# ],
# "rapid_commit": false
# }
- Utilize the Pydantic models which provide basic data validation.
from pyisckea.models.dhcp4.subnet import Subnet4
my_subnet = Subnet4(
id=1234, subnet="192.0.2.32/31", option_data=[{"code": 3, "data": "192.0.2.32"}]
)
create_subnet = server.dhcp4.subnet4_add(subnets=[my_subnet])
print(create_subnet.result, create_subnet.text)
# Note because subnet_cmds hook library is not loaded, we run into an exception here:
# pyisckea.exceptions.KeaHookLibraryNotConfiguredException: Hook library 'subnet_cmds' is not configured for 'dhcp4' service. Please ensure this is enabled in the configuration for the 'dhcp4' daemon
Basic Authentication
If you have basic authentication enabled on your Kea Servers, import the BasicAuth class from the httpx library and pass it into the Kea object like this:
from pyisckea.kea import Kea
from httpx import BasicAuth
auth = BasicAuth("kea", "secret123")
api = Kea("http://localhost:8000", auth=auth)
TLS
Create a context using the ssl library and then pass this context into a httpx Client object to be used with Kea like this:
from httpx import Client
from pyisckea.kea import Kea
ctx = ssl.create_default_context(cafile="/path/to/the/ca-cert.pem")
ctx.load_cert_chain(
certfile="/path/to/the/agent-cert.pem", keyfile="/path/to/the/agent-key.pem"
)
client = Client(verify=ctx)
api = Kea("http://localhost:8000", client=client)
API Reference
All supported commands by the daemons are in the format of the API referenced commands with the exception of replacing any hyphen or space with an underscore. Eg. the build-report API command for all daemons is implemented as build_report so it heavily ties into the Kea predefined commands when looking at their documentation. Currently everything is built towards Kea 2.2.0. Pydantic variables will replace any hyphens with an underscore however when loading/exporting the data models, it will replace all keys with the hyphen to adhere to the Kea expected variables, ensure that the KeaBaseModel (located in from pyisckea.models.generic.base import KeaBaseModel instead of from pydantic import BaseModel) is used when creating any Pydantic models to inherit this functionality.
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 pyisckea-0.9.0a1.tar.gz.
File metadata
- Download URL: pyisckea-0.9.0a1.tar.gz
- Upload date:
- Size: 38.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c2a2219aba3083b4dc05fac8e876b8d57ad00c8cef565652a8b6a482e9943f3
|
|
| MD5 |
34d044dc79773d772906d406a9a9c3ed
|
|
| BLAKE2b-256 |
08ff5a6719d50d596772941b5ec005e3675cafb2c35fd10ab358439c6db40447
|
Provenance
The following attestation bundles were made for pyisckea-0.9.0a1.tar.gz:
Publisher:
ci.yml on veesix-networks/pyisckea
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyisckea-0.9.0a1.tar.gz -
Subject digest:
8c2a2219aba3083b4dc05fac8e876b8d57ad00c8cef565652a8b6a482e9943f3 - Sigstore transparency entry: 193550555
- Sigstore integration time:
-
Permalink:
veesix-networks/pyisckea@3a1233135ac14af178d9c46e366a664c2c693f2e -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/veesix-networks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@3a1233135ac14af178d9c46e366a664c2c693f2e -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyisckea-0.9.0a1-py3-none-any.whl.
File metadata
- Download URL: pyisckea-0.9.0a1-py3-none-any.whl
- Upload date:
- Size: 60.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59397de442a35987f17d138edc7b18bd547f798d94e32ebcde7fa7a0fc445da8
|
|
| MD5 |
6e7b21d265afb1af132f3501684e97ec
|
|
| BLAKE2b-256 |
0a95eac1d33339af6e3a7d9ab4e48290e969662b76080f4d9eb81f008514f009
|
Provenance
The following attestation bundles were made for pyisckea-0.9.0a1-py3-none-any.whl:
Publisher:
ci.yml on veesix-networks/pyisckea
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyisckea-0.9.0a1-py3-none-any.whl -
Subject digest:
59397de442a35987f17d138edc7b18bd547f798d94e32ebcde7fa7a0fc445da8 - Sigstore transparency entry: 193550558
- Sigstore integration time:
-
Permalink:
veesix-networks/pyisckea@3a1233135ac14af178d9c46e366a664c2c693f2e -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/veesix-networks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@3a1233135ac14af178d9c46e366a664c2c693f2e -
Trigger Event:
release
-
Statement type: