Perl-Fu- Install Linux En-Masse Using OMAPI/MySQL

Last year I wrote a utility called SysProD(System Provisioner Daemon) which was an amazing piece of Perl voodoo magic. It PXEbooted and installed CentOS 5.2 on 120 machines for the new MRI cluster at USF. It was a DHCP/TFTP server with some additional features that helped in identifying the hostname/ip based on a machine’s location in a switch. You plugged in a server right out of the box, turned it on, and it was ready to accept jobs in 15 minutes. It was nothing short of miraculous. Even Sun Microsystems was wowed by it, and they wanted a copy to integrate with their HPC tools. I’m happy I didn’t, because now I have something much better.

The only problem was that SysProD was clunky and it did too much for it’s own good. First, the tftp functionality wasn’t up to snuff so I removed it, replacing it with the packaged tftpd that xinetd was responsible for. Then, I no longer needed the network-aware logic so I ripped that out too. Soon I began to realize that the reason I liked SysProD so much over just using ISC’s dhcpd was that it dynamically handed out DHCP leases based on what was in a database. Why can’t I have dhcpd do that for me somehow so I can remain RFC compliant?

Well, I discovered that indeed there was an interface to ISC’s DHCPD that allowed creation/deletion of leases in real time without daemon restart. Called OMAPI, it represented leases as objects (think in the OOP sense). With this, I can refactor SysproD to the point of not being a daemon at all. All that would need to be done is to specify a machine, reboot it, create the lease, and let the installer environment remove the lease for us. The program responsible for accessing OMAPI is omshell. Unfortunately, there wasn’t a workable lib that it was built against, so I will need to call it directly in the code I write.

A few hours of divinely-inspired coding later, I had install-node-ng. Here are the features:

  • You can specify a list of hosts of any length to install, and any item in the list can be a POSIX regular expression.
  • If you specify IPMI interfaces in the database for certain hosts, those hosts will instantly reboot/start up.
  • Authentication using a shared key
  • Support for multiple bootloader configurations (supports PXELinux, will support PXEGRUB for Solaris)

I will distribute the code and some documentation soon.. stay tuned.. Here’s the omshell call in action:

# Create the host in omapi. Admittedly, this is unwieldy, but there's no perl lib.
open (OMSHELL, "|omshell &> /dev/null") || die ("Unable to open omshell\n");
print OMSHELL "server $dhcp_server\n";
print OMSHELL "port 9991\n";
print OMSHELL "key omapi_key \"$omapikey\"\n";
print OMSHELL "connect\n";
print OMSHELL "new host\n";

print OMSHELL "set name = \"$name\"\n";
print OMSHELL "set hardware-address = $hex_mac\n";
print OMSHELL "set hardware-type = 1\n";
print OMSHELL "set ip-address = $ip\n";
print OMSHELL "set group = \"$group\"\n";
print OMSHELL "create\n";
close (OMSHELL) || die "Unable to close omshell.\n";