MartijnBraam / python-isc-dhcp-leases

Small python module for reading /var/lib/dhcp/dhcpd.leases from isc-dhcp-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extract leases - Binding state backup

opened this issue · comments

Hello,

My problem is the following:
I can't extract from the leases.get (), the leases whose binding state is backup and of which there is no end.

I can :

lease **** {
  starts 4 2017/10/05 15:22:29;
  ends 1 2017/10/16 08:09:23;
  tstp 1 2017/10/16 15:22:29;
  tsfp 1 2017/10/16 15:22:29;
  atsfp 1 2017/10/16 15:22:29;
  cltt 4 2017/10/05 15:22:29;
  binding state backup;
  hardware ethernet *****;
  uid *****;

I can"t :

lease ******* {
  starts 2 2017/10/10 12:05:14;
  tstp 2 2017/10/10 12:05:14;
  tsfp 2 2017/10/10 12:05:14;
  atsfp 2 2017/10/10 12:05:14;
  binding state backup;

Is there a solution ?

Regards,

Well it should ignore incomplete leases since those aren't valid. I'll check why your backup lease won't work.

So in fact, this lease does not appear in the list of leases.get() because it lacks the "ends" ?

Oh I thought you meant end as in "missing the }". Leases without end should work.

I've added testcases for both your leases and it seems to work fine. You can see my lease file here: https://github.com/MartijnBraam/python-isc-dhcp-leases/pull/21/files

Maybe you have something different in your lease file that makes it stop working?

In fact, as the lease is backup it has never been used, there is not the line "hardware ethernet ***" and I think the problem is there

It would be necessary that the code accepts that the lease does not have ends and harware

The current version does support leases without ends but skips leases without hardware. In #21 I've added a option to the get() method to allow you to get hardware-less leases.

Can you try if that version works if you specify get(include_backups=True)?

Thank you ! It works very well in case there is no hardware but I still have the following error if I do not have any ends

line 209, in __init__
    if properties['ends'] == 'never':
KeyError: 'ends'

Hmm that line doesn't exist in the current codebase. Are you using an older version?

This corresponded to line 213 in the most recent version. I missed get('ends', 'never'), it's works now !

I've just released 0.9.0 on pypi with the fixes for this included.