theforeman / smart_proxy_dhcp_dnsmasq

dnsmasq DHCP plugin for Foreman smart-proxy
GNU General Public License v3.0
7 stars 7 forks source link

Consider using single file storage #1

Closed lzap closed 7 years ago

lzap commented 7 years ago

Hello,

I just noticed this exist. I already started implementing this but I have never finished my work. Got only partially working DHCP. More details about my implementation at:

http://projects.theforeman.org/issues/13806

I wanted to design it in a way that each host entry (DNS or DHCP) is an individual file, dnsmasq can do it's own inotify on directory (for DHCP, not working for DNS). I was thinking even storing some data in filenames too.

I could share my code but you are perhaps far than me. Ping me if you are interested anyway.

ananace commented 7 years ago

Hey, sorry about the delay, GitHub decided to not in any way notify me about this issue.

Your thoughts on doing individual files does sound like a slightly cleaner method than just stuffing them all into the same one, I didn't actually know dnsmasq supported that. Thought only configuration files could be loaded from directories. I wouldn't mind seeing any code or design you've done, there are still a few parts of both this and the DNS plugin that I'm unsure of if they're thought out properly, having thrown this whole thing together just for my own usage - and started it based off of OpenWRT-specific configuration at that.

lzap commented 7 years ago

Damn I wrote initial version of the plugin and accidentaly trashed the directory, it's gone. But it was not that useful, just initial version of dhcp module and unit tests. As simple as putting a file in a directory and that was really it. And sending the SIGHUP signal.

ananace commented 7 years ago

Ah well, already have an idea on how to start reworking this for single-file storage, though do feel free to share any plans or designs you had in mind when doing your prototype. Like I said earlier, I've got no idea how other dnsmasq setups might look, basing this whole plugin off of what's running on my OpenWRT router.

On 23 May 2017 3:53 pm, "Lukáš Zapletal" notifications@github.com wrote:

Damn I wrote initial version of the plugin and accidentaly trashed the directory, it's gone. But it was not that useful, just initial version of dhcp module and unit tests. As simple as putting a file in a directory and that was really it. And sending the SIGHUP signal.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ace13/smart_proxy_dhcp_dnsmasq/issues/1#issuecomment-303404908, or mute the thread https://github.com/notifications/unsubscribe-auth/AAgnvG81yDuKkT9oqh1_W4fv15MCMrN3ks5r8uTEgaJpZM4MuWw6 .

ananace commented 7 years ago

Been looking into this, and from what I can see it won't be possible to do true "single file storage" for the DHCP part

The --dhcp-hostsfile option should work fine for the reservations, but I'll have to use --dhcp-optsfile as well to provide the DHCP boot options for all the hosts. So each host will get two files, in two separate folders.

Something like;

$ cat /etc/dnsmasq.d/foreman/hostsfile/<host_id>.conf
01:02:03:04:05:06,set:01:02:03:04:05:06,10.1.0.24,example.network.local
$ cat /etc/dnsmasq.d/foreman/optsfile/<host_id>.conf
tag:01:02:03:04:05:06,option:tftp-server,10.0.0.10
tag:01:02:03:04:05:06,option:bootfile-name,pxelinux.0
lzap commented 7 years ago

Oh that's bad, I did not see that coming.

But usually we only set tftp-server and bootfile-name and both are pretty static - how about creating tags for them and then using them. This way the optsfile will not change often, it will pretty much contain only four items: tftp-server IP, boot files for PXELinux, PXEGrub and PXEGrub2. We do not set anything else. Tags can be named as simple alphanum entities:

tag:tftp_server_10_0_0_10,option:tftp-server,10.0.0.10
tag:bootfile_name_pxelinux_0,option:bootfile-name,pxelinux.0

Then this becomes:

01:02:03:04:05:06,set:tftp_server_10_0_0_10,bootfile_name_pxelinux_0,10.1.0.24,example.network.local

Also the tftp-server is excessibely written by ISC DHCP, we should be able detect that it's the default value and not set it at all if that's a global setting.

Tags would be created dynamically, if plugin won't find tag in the optsfile it can easily create it. But you can also design it in a static way - tftp server can be a global option (we never change that via API) and then we have just several filenames available in Foreman 1.15.

ananace commented 7 years ago

Got some free time so took another look at this, going to see about testing to make sure everything works like it should, but then I should be able to publish a new version with single-file storage in place.

lzap commented 6 years ago

I haven't noticed you referenced this (no notification), so sorry for the late response.

This looks great! I like separate reservation files, so the final design created file with reservation and then appends to the option file if the line is not already present. That's fair design, but what happens then there is a change in the filename? It can happen, so you only append and dnsmasq reads multiple values ignoring previous ones? Is this the assumption that was made?

In that case there should be a mechanism which will "squash" the file on every restart (I'd avoid new thread because of concurrency). That would do it.

Anyway thanks this looks good, I will take a closer look on the whole codebase now.