MartijnBraam / python-isc-dhcp-leases

Small python module for reading /var/lib/dhcp/dhcpd.leases from isc-dhcp-server
MIT License
123 stars 47 forks source link

Format host_identifier, iaid and duid as colon-separated hex strings #30

Open jjakob opened 5 years ago

jjakob commented 5 years ago

This would then equal the format that dhcpd.conf takes as identifier, so the values could be used to directly transfer to host blocks.

We are using this library in vyos to display the leases in a user friendly format, which requires additional parsing inside our script to add the colons. show_dhcpv6.py#L49

MartijnBraam commented 5 years ago

I'll check if I can add that functionality without breaking the existing api

jaredmauch commented 5 months ago

If you set

lease-id-format hex;

in dhcpd6.conf you will get the proper results, but it does seem that the parsing does not work in this library due to the regex match:

    regex_leaseblock6 = re.compile(
        r"ia-(?P<type>ta|na|pd) \"(?P<id>[^\"\\]*(?:\\.[^\"\\]*)*)\" {(?P<config>[\s\S]+?)\n}")

with a lease such as this:

ia-na 03:00:00:00:00:03:00:01:18:fd:74:8f:3e:46 {
  cltt 5 2024/05/31 01:28:56;
  iaaddr 2001:db8:3::ffbb {
    binding state active;
    preferred-life 604800;
    max-life 2592000;
    ends 0 2024/06/30 01:28:56;
    set cid = "b4fbe41b4a18/3/70a741336758/1:100";
    on release {
      log (error, 
          concat ("RELEASE6 from", cid));
    }
  }
}

while the previous octal output and match works. I'm hoping that @MartijnBraam could make that match work as well :-)