[Solved]Python script converts Opnsense configuration file into kea reservations

Started by Monju0525, February 05, 2024, 04:47:17 PM

Previous topic - Next topic
The script looks at the contents of
['dhcpd']['lan']['staticmap'] and essentially copies the contents into the kea section
['reservations'] starting as ['reservation uuid']

U will see what I migrated by running:

opnsense_isc_to_kea_reservations.py config-OPNsense.localdomain-20240218111111.xml

Diff the merge.xml and config-OPNsense.localdomain-20240218111111.xml


It does not do vlans but it something I can look into.
I am not familiar with vlans but tell me what you want to migrate from and to.
I need xml tags or gators🐊 and your sanitized config-OPNsense*.xml file.

Also, I  need to know what the final populated xml should look like.










I did look at the contents of your merge output.

This will be the first time I've used Kea, so I'm not sure what the final result will need to be.

When I get time I'll run another machine with my firewall config on it and add additional subnets into Kea. Then see what the xml looks like.

I'll also dig out some old bash scripts I wrote which I used to migrate in ISC DHCP configs when I moved some clients from an external ISC DHCP server to OPNsense.

If u enable kea,  move one of the vlans to a kea reservation, save the new config and then diff the orig config vs the new kea config , u will see what actually moved with kea enabled.

curious if/how this script might accommodate the below 24.1.3 change:

     o kea-dhcp: add import/export as CSV on reservations


If export/import is added to the ISC DHCPv4/v6 using the same file format as the existing Kea export/import, then migration of reservations between the two becomes trivial.

@randyg503
It does not. I wrote the script on 24.1.2 before they released  kea csv import/export functionality. My use case was to move the current isc static leases into kea reservations. It assumes u have a working kea dhcp with one kea reservation created. No export/import needed since it automatically does the merges into a newly created merge.xml. Ur original config-OPNsense*.xml is never modified.

On 02252024, I made changes and now it supports a command line argument.

Install Python3 ( I installed python 3.12.1 on my W11 desktop)

>>>  python3  opnsense_isc_to_kea_reservations.py  <your_config-OPNsense*.xml>
Note: I regex check ur opnsense config file name format.

The migrated changes are in merge.xml

https://github.com/patrick0525/Python-Opn-isc-kea


Thank you for your feedback regarding my question and for your work on this script.

@randyg53
No problem. It really added to my Python, xml, ElementTree, Python dictionary, json object, json array, regex understanding and knowledge. It was challenging but it is not my day job.