pypxe / PyPXE

Pure Python PXE (DHCP-(Proxy)/TFTP/HTTP/NBD) Server
MIT License
539 stars 125 forks source link

Enable Exporting Leases to JSON #110

Closed psychomario closed 9 years ago

psychomario commented 9 years ago

Handles SIG{INT,ALRM,TERM,HUP} to dump out the leases object to --saveleases file as json. On start with --saveleases the self.leases object is updated with the contents, so non-expired (BUG we don't check, will fix) (fixed in 2936162) leases are used

The keys are translated to human readable (and json compatible) mac addresses on export, and back on import.

I've also moved self.leases[client_mac]['options'] to a separate object. It means we don't have to clean up the self.leases dict every time we save it.

mmattioli commented 9 years ago

@psychomario looks like you didn't use pickle? Also, this looks good but I just wanted to point out the variable and function naming should maybe be more inline with PEP8 (def export_leases rather than def exportLeases).

psychomario commented 9 years ago

I don't really like pickle, it leaves a completely opaque binary file on disk, it would have worked significantly better for storing the binary data from options, but given that I've moved that elsewhere it isn't an issue anymore.. This method leaves a nice json file which, for whatever reason, is editable and viewable.

psychomario commented 9 years ago

I've pushed a new commit with the style improvements you suggested.

mmattioli commented 9 years ago

@psychomario sorry to be a pest but I made a few line comment where variable names should still be modified to conform with PEP8. Give it a look once more? Thanks.

psychomario commented 9 years ago

As ever, you're correct. I'm not able to make these changes for the next few days but I will do so when I can.

mmattioli commented 9 years ago

@psychomario since #111 was just merged you're going to need to do a rebase anyway lol

psychomario commented 9 years ago

@mmattioli I think I've got all your changes, I almost made a mess of the branch in the process.

mmattioli commented 9 years ago

:+1: LGTM