candlerb / netbox-webhook-kea-dhcp

Netbox tool to configure ISC KEA DHCP server from Netbox database
Apache License 2.0
28 stars 0 forks source link

shared-networks #1

Closed TimothyTH closed 4 years ago

TimothyTH commented 4 years ago

Hi, Thank you for your work. Is it possible that this works for share networks ?

My error : Traceback (most recent call last): File "./netbox-webhook-kea-dhcp/kea_conf_update.py", line 131, in <module> confs = read_confs() File "./netbox-webhook-kea-dhcp/kea_conf_update.py", line 44, in read_confs "4": rd("/etc/kea/kea-dhcp4.conf"), File "./netbox-webhook-kea-dhcp/kea_conf_update.py", line 42, in rd return json.loads(data) File "/usr/lib/python3.6/json/__init__.py", line 354, in loads return _default_decoder.decode(s) File "/usr/lib/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.6/json/decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 77 column 14 (char 2166)

candlerb commented 4 years ago

I think shared networks should be fine, it's just that the KEA config you have provided is not valid JSON. KEA accepts a wider syntax which is not-quite-JSON, e.g. it allows trailing commas:

{
    "foo": 1,
    "bar": 2,
}

This is valid in KEA but not in JSON. KEA also allows comments. The python code in rd() strips out comments with a regex, but otherwise just uses the regular python JSON parser.

Your solution is to modify the KEA config into valid JSON. Alternatively, you could try uncommenting this line, but I don't think it worked well in practice which is why I left it commented out.

candlerb commented 4 years ago

Changing import json to

from jsoncomment import JsonComment
json = JsonComment()

might also work. However I'm not sure how well maintained that package is - the homepage link is broken.

TimothyTH commented 4 years ago

I deleted the comment & it's progressing :) Traceback (most recent call last): File "./netbox-webhook-kea-dhcp/kea_conf_update.py", line 135, in <module> update_confs(conn, confs) File "./netbox-webhook-kea-dhcp/kea_conf_update.py", line 88, in update_confs for r in confs["4"]["Dhcp4"]["subnet4"]:# + confs["6"]["Dhcp6"]["subnet6"]: KeyError: 'subnet4'

I continue Thx

candlerb commented 4 years ago

Your dhcp4 config is expected to have the structure:

"Dhcp4": {
...
  "subnet4": [
  ...
  ]
}

If there's no "subnet4" section then there's nowhere for the static host reservations to be inserted.

candlerb commented 4 years ago

Sorry, I think you were right first time. The code currently doesn't work with shared-subnets where the subnet4 is nested inside shared-subnets. Sorry... but it you patch this, I'll merge.

TimothyTH commented 4 years ago

thank you, I'm working on it.

candlerb commented 4 years ago

Actually, it looks easier than I thought. I've just pushed a change, can you test it?

TimothyTH commented 4 years ago

Very good it works, thank you very much.