Skip to content

Commit e38d47f

Browse files
committed
Use subnet-list command instead of config
1 parent b298cfe commit e38d47f

5 files changed

Lines changed: 21 additions & 27 deletions

File tree

netbox_kea/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
CLIENT_ID_MAX_OCTETS = DUID_MAX_OCTETS
1616
CLIENT_ID_MIN_OCTETS = 2
1717

18-
KEA_BASIC_PASSWORD = "kea"
18+
KEA_BASIC_PASSWORD = "kea1234"
1919
KEA_BASIC_URL = "http://nginx"
2020
KEA_BASIC_USERNAME = "kea"
2121
KEA_CA = "/certs/ca.crt"

netbox_kea/tables.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from typing import Any
2+
13
import django_tables2 as tables
2-
from django.urls import reverse
34
from django.utils.http import urlencode
45
from netbox.tables import BaseTable, NetBoxTable, ToggleColumn, columns
56

@@ -137,10 +138,7 @@ class SubnetTable(GenericTable):
137138
subnet = tables.Column(
138139
linkify=lambda record, table: (
139140
(
140-
reverse(
141-
f"plugins:netbox_kea:server_leases{record['dhcp_version']}",
142-
args=[record["server_pk"]],
143-
)
141+
table.server_url
144142
+ "?"
145143
+ urlencode({"by": "subnet", "q": record["subnet"]})
146144
)
@@ -156,6 +154,12 @@ class Meta(GenericTable.Meta):
156154
fields = ("id", "subnet", "shared_network", "actions")
157155
default_columns = ("id", "subnet", "shared_network")
158156

157+
def __init__(self, *args: Any, **kwargs: Any) -> None:
158+
super().__init__(*args, **kwargs)
159+
160+
# This must be set before rendering.
161+
self.server_url: str | None = None
162+
159163

160164
class BaseLeaseTable(GenericTable):
161165
# This column is for the select checkboxes.

netbox_kea/views.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -501,34 +501,18 @@ def get_subnets(self, server: Server) -> list[dict[str, Any]]:
501501
client = server.get_client(self.dhcp_version)
502502
assert client is not None, "TODO"
503503

504-
config = client.command("config-get")
504+
config = client.command(f"subnet{self.dhcp_version}-list")
505505
assert config[0]["arguments"] is not None
506-
subnets = config[0]["arguments"][f"Dhcp{self.dhcp_version}"][
507-
f"subnet{self.dhcp_version}"
508-
]
506+
subnets = config[0]["arguments"]["subnets"]
509507
subnet_list = [
510508
{
511509
"id": s["id"],
512510
"subnet": s["subnet"],
513-
"dhcp_version": self.dhcp_version,
514-
"server_pk": server.pk,
511+
"shared_network": s["shared-network-name"],
515512
}
516513
for s in subnets
517-
if "id" in s and "subnet" in s
518514
]
519515

520-
for sn in config[0]["arguments"][f"Dhcp{self.dhcp_version}"]["shared-networks"]:
521-
subnet_list.extend(
522-
{
523-
"id": s["id"],
524-
"subnet": s["subnet"],
525-
"shared_network": sn["name"],
526-
"dhcp_version": self.dhcp_version,
527-
"server_pk": server.pk,
528-
}
529-
for s in sn[f"subnet{self.dhcp_version}"]
530-
)
531-
532516
return subnet_list
533517

534518
def get(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
@@ -542,6 +526,10 @@ def get(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
542526

543527
table_data = self.prep_table_data(request, child_objects, instance)
544528
table = self.get_table(table_data, request, False)
529+
table.server_url = reverse(
530+
f"plugins:netbox_kea:server_leases{self.dhcp_version}",
531+
args=[instance.pk],
532+
)
545533

546534
if "export" in request.GET:
547535
return export_table(

tests/docker/kea_configs/kea-dhcp4.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@
285285
// hook libraries, see https://gitlab.isc.org/isc-projects/kea/wikis/Hooks-available.
286286
"hooks-libraries": [
287287
{"library": "/usr/lib/kea/hooks/libdhcp_lease_cmds.so"},
288-
{"library": "/usr/lib/kea/hooks/libdhcp_stat_cmds.so"}
288+
{"library": "/usr/lib/kea/hooks/libdhcp_stat_cmds.so"},
289+
{"library": "/usr/lib/kea/hooks/libdhcp_subnet_cmds.so"}
289290
],
290291
// {
291292
// // Forensic Logging library generates forensic type of audit trail

tests/docker/kea_configs/kea-dhcp6.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@
231231
// hook libraries, see https://gitlab.isc.org/isc-projects/kea/wikis/Hooks-available.
232232
"hooks-libraries": [
233233
{"library": "/usr/lib/kea/hooks/libdhcp_lease_cmds.so"},
234-
{"library": "/usr/lib/kea/hooks/libdhcp_stat_cmds.so"}
234+
{"library": "/usr/lib/kea/hooks/libdhcp_stat_cmds.so"},
235+
{"library": "/usr/lib/kea/hooks/libdhcp_subnet_cmds.so"}
235236
],
236237
// {
237238
// // Forensic Logging library generates forensic type of audit trail

0 commit comments

Comments
 (0)