← Back to team overview

maas-devel team mailing list archive

Re: Strategy regarding DNS and static DHCP leases

 

On Friday 20 July 2012 13:58:13 Julian Edwards wrote:
> On Thursday 19 July 2012 19:52:50 Julian Edwards wrote:
> >      b) use the OMAPI  (via omshell) - problematic because you can't
> >      create
> > 
> > a static lease with the OMAPI
> 
> Actually, this was a bad memory of mine, you can!
> 
> So, I'm formulating a plan to write static leases out, I'll send another
> email later.


After a long chat with Rob we managed to add static lease maps using omshell 
which talks to DHCPD using OMAPI.

So what we'll do now is have an API call that the lease parser will call when 
it sees a new lease added (which will be at enlistment time).  The API method 
that the lease parser calls will use omshell to add the permanent mapping in 
the DHCPD.  By the time the node reboots and starts commissioning the mapping 
will be in place.

Here's how omshell works:

First we need to generate a shared key:
 $ dnssec-keygen -r /dev/urandom -a HMAC-MD5 -b 512 -n HOST omapi_key
 $ cat Komapi_key.+*.private |grep ^Key|cut -d ' ' -f2-

Then edit /etc/dhcpd.conf and add these lines:

omapi-port 7911;
key omapi_key {
  algorithm HMAC-MD5;
  secret "XXXXXXXXX"; # ← The output from the generated key above.
};
omapi-key omapi_key;

Now run omshell:

$ omshell
> server 127.0.0.1
> key omapi_key XXXXXXXXX  # ← The output from the generated key above.
> connect
> new host
> set ip-address = 192.168.1.1
> set hardware-address = 00:80:c7:84:b1:94
> set name = "192.168.1.1"  # ← will look up by this label later
> create

This has now created an entry in the leases file that looks like this:
       host  192.168.1.1 {
         dynamic;
         hardware ethernet 00:80:c7:84:b1:94;
         fixed-address 192.168.1.1;
       }

At some point in the future we'll potentially need to delete this mapping, if 
and when the node is decommissioned:

$ omshell
... connect as usual
> new host
> set name = "192.168.1.1"  # ← have to look up by the host label
> open
> remove

And now the leases file is appended with the following:

host 192.168.1.1 {
  dynamic;
  deleted;
}


If the DHCPD ever gets restarted, the two entries cancel each other out and 
both are completely removed.


References