Hi all Regarding ticket: https://fedorahosted.org/cobbler/ticket/85 I'm submitting a patch that will need extra work from any of you willing to ;) This patch introduces two new setting options: omapi and omapi_port omapi is a protocol spoke by DHCP to perform real-time modification to entries without restarting the daemon, for doing so, it needs a new setting in your dhcp.template "omapi port" and restart of the server. After that, the code for generating the DHCP config just send those commands directly and avoids final dhcp restart. Thinks lacking: - Error checking if dhcp has no omapi enabled and cobbler configuration says so - No dhcp started - no password authentication enabled (described in omshell) - Port used is 647 as it's defined in SELinux for DHCP, but not sure if used for any other thing... but for me, it works. You can check if this works this way: -creating the entries in /var/lib/cobbler/settings and /etc/cobbler/dhcp.template. - Running cobbler sync to write new entry with "omapi port" for /etc/dhcpd.conf - Stopping dhcpd - Editing /etc/dhcpd.conf and remove all host definitions created by cobbler - Emptying /var/lib/dhcpd/dhcpd.leases - Starting dhcpd After this, you can run cobbler sync and have a look at "/var/lib/dhcpd/dhcpd.leases" and have a look at the new "host" entries which will have a "dynamic" stating that have been generated dinamically with OMAPI. As the new DHCPD.conf is generated as it was before, in case of a system restart, the host will be still there. Please, patches and comments are very welcome :) Pablo -- Pablo Iranzo Gómez (Pablo.Iranzo@xxxxxxxxxx) RHCE/Global Profesional Services Consultant Spain Phone: +34 645 01 01 49 (CET/CEST) GnuPG KeyID: 0xFAD3CF0D --- Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta 3ºD, 28016 Madrid, Spain Dirección Registrada: Red Hat S.L., C/ Velazquez 63, Madrid 28001, Spain Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941
diff --git a/cobbler/dhcpgen.py b/cobbler/dhcpgen.py index 2d6facf..1677f7c 100644 --- a/cobbler/dhcpgen.py +++ b/cobbler/dhcpgen.py @@ -22,6 +22,8 @@ import sys import glob import traceback import errno +import popen2 + import utils from cexceptions import * @@ -53,6 +55,50 @@ class DHCPGen: self.repos = config.repos() self.templar = templar.Templar(config) + def writeDHCPLease(self,port,host,ip,mac): + """writeDHCPLease(port,host,ip,mac) + Use DHCP's API to create a DHCP entry in the /var/lib/dhcpd/dhcpd.leases file """ + #Code from http://svn.osgdc.org/browse/kusu/kusu/trunk/src/kits/base/packages/kusu-base-installer/lib/kusu/nodefun.py?r=3025 + fromchild, tochild = popen2.popen2("/usr/bin/omshell") + tochild.write("port %s\n" % port) + tochild.flush() + tochild.write("connect\n") + tochild.flush() + tochild.write("new host\n") + tochild.flush() + tochild.write('set name = \"%s\"\n' % host) + tochild.flush() + tochild.write("set ip-address = %s\n" % ip) + tochild.flush() + tochild.write("set hardware-address = %s\n" % mac) + tochild.flush() + tochild.write("set hardware-type = 1\n") + tochild.flush() + tochild.write("create\n") + tochild.flush() + tochild.close() + fromchild.close() + + def removeDHCPLease(self,port,host): + """removeDHCPLease(port,host) + Use DHCP's API to delete a DHCP entry in the /var/lib/dhcpd/dhcpd.leases file """ + fromchild, tochild = popen2.popen2("/usr/bin/omshell") + tochild.write("port %s\n" % port) + tochild.flush() + tochild.write("connect\n") + tochild.flush() + tochild.write("new host\n") + tochild.flush() + tochild.write('set name = \"%s\"\n' % host) + tochild.flush() + tochild.write("open\n") # opens register with host information + tochild.flush() + tochild.write("remove\n") + tochild.flush() + tochild.close() + fromchild.close() + + def write_dhcp_file(self): """ DHCP files are written when manage_dhcp is set in @@ -121,6 +167,19 @@ class DHCPGen: if ip is not None and ip != "": systxt = systxt + " fixed-address %s;\n" % ip systxt = systxt + "}\n" + + # If we have all values defined and we're using omapi, + # we will just create entries dinamically into DHCPD + # without requiring a restart (but file will be written + # as usual for having it working after restart) + + if ip is not None and ip != "": + if mac is not None and mac != "": + if host is not None and host != "": + if self.settings.omapi and self.settings.omapi_port: + self.removeDHCPLease(self.settings.omapi_port,host) + self.writeDHCPLease(self.settings.omapi_port,host,ip,mac) + else: # dnsmasq. don't have to write IP and other info here, but we do tag @@ -192,5 +251,3 @@ class DHCPGen: if host is not None and host != "" and ip is not None and ip != "": fh.write(ip + "\t" + host + "\n") fh.close() - - diff --git a/cobbler/settings.py b/cobbler/settings.py index 40ed571..491de75 100644 --- a/cobbler/settings.py +++ b/cobbler/settings.py @@ -58,6 +58,8 @@ DEFAULTS = { "manage_dhcp" : 0, "manage_dhcp_mode" : "isc", "next_server" : "127.0.0.1", + "omapi" : 1, + "omapi_port" : 647, "pxe_just_once" : 0, "register_new_installs" : 0, "run_install_triggers" : 1, diff --git a/templates/dhcp.template b/templates/dhcp.template index 705cc77..19afcad 100644 --- a/templates/dhcp.template +++ b/templates/dhcp.template @@ -9,6 +9,7 @@ ddns-update-style interim; allow booting; allow bootp; +omapi-port 647; ignore client-updates; set vendorclass = option vendor-class-identifier; diff --git a/triggers/restart-services.trigger b/triggers/restart-services.trigger index b65b825..6a0e320 100644 --- a/triggers/restart-services.trigger +++ b/triggers/restart-services.trigger @@ -8,11 +8,19 @@ bootapi = capi.BootAPI() settings = bootapi.settings() manage_dhcp = str(settings.manage_dhcp).lower() manage_dhcp_mode = str(settings.manage_dhcp_mode).lower() +omapi = settings.omapi +omapi_port = settings.omapi_port + + + +# We're just going to restart DHCPD if using ISC and if not using OMAPI at all rc = 0 if manage_dhcp != "0": if manage_dhcp_mode == "isc": - rc = os.system("/sbin/service dhcpd restart") + if not omapi: + if not omapi_port: + rc = os.system("/sbin/service dhcpd restart") elif manage_dhcp_mode == "dnsmasq": rc = os.system("/sbin/service dnsmasq restart") else: diff --git a/config/settings b/config/settings index 10e06e2..724f419 100644 --- a/config/settings +++ b/config/settings @@ -32,6 +32,8 @@ ldap_search_prefix: 'uid=' manage_dhcp: 0 manage_dhcp_mode: isc next_server: '127.0.0.1' +omapi: 1 +omapi_port: 647 pxe_just_once: 0 register_new_installs: 0 run_install_triggers: 1
Attachment:
signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente
_______________________________________________ et-mgmt-tools mailing list et-mgmt-tools@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/et-mgmt-tools