Re: Cobbler patch OMAPI v2 ;)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



	Morning!

El mar, 29-04-2008 a las 22:27 -0400, Michael DeHaan escribió:
> Should be applied Thursday or so barring any other comments, and that 
> will make this easier for people to test.   I also need to do a test 
> release for 0.9 soon (let's call this 0.9.1 ... there will be more test 
> releases with some other features likely being added prior to the 1.0).

	Count with me for the beta-testing :)


> Quick question -- Should omapi in settings be off by default?  It only 
> works with modifications to the dhcp.template to enable it -- though we 
> /could/ enable that by default in the template and solve the problem.

	For me, as cobbler is rewriting dhcp info, should be enabled by
default. This could need another check for the code I submitted
yesterday to check if "manage dhcp is enabled for isc".

	For example, in trigger, the code is:

     if manage_dhcp_mode == "isc":
        if not omapi:
          if not omapi_port:
            rc = os.system("/sbin/service dhcpd restart")

	So, if manage mode is "ISC", and omapi is not enabled nor omapi_port,
then it does a restart. 

	I don't think that this could hurt anyone if already using Cobbler for
managing DHCP, if not, system will just do the other tasks, but nothing
about DHCP

> 
> Comments from folks who use Cobbler for DHCP management?
> 
> The main goal of this is to keep DHCP running throughout sync operations 
> -- but also to allow for less reasons to ever need to do "sync".  Since 
> kickstart generation is now dynamic in 0.9/1.0, the only real reason to 
> run sync is to rebuild some of the tftpboot tree, the rest of the 
> "partial" data gets built each time you make a change to the associated 
> objects (and all descendents automatically update).  


	Well, regarding this, right now I had to put the new stanza for
cleaning leases just in case of machines removal. The best thing will be
to put the code in "cobbler system add" "cobbler system remove" and
"cobbler system rename" in order to just make this calls when needed,
remmoving the need for the "leases-cleanup code", as the systems will
get created on DHCP or removed dinamically.

> We can probably even make that less important as time goes on, by 
> knowing basic things like if we add a profile, we can also quickly 
> rebuild the pxemenus (since the number of profiles is going to be very 
> small, etc).

	That would be a good point, in this way, cobbler state could just use
"sync" for forcing a full cobbler files recreation just to be sure,
remove possible problems, as all the other operations would get
inmediate action on system .

	Regards
	Pablo

PD: Attached patch adds an extra check to the DHCP leases cleanup code
to check if we're doing ISC

-- 

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..686b341 100644
--- a/cobbler/dhcpgen.py
+++ b/cobbler/dhcpgen.py
@@ -22,6 +22,9 @@ import sys
 import glob
 import traceback
 import errno
+import popen2
+from shlex import shlex
+
 
 import utils
 from cexceptions import *
@@ -53,6 +56,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
@@ -84,10 +131,28 @@ class DHCPGen:
 
         system_definitions = {}
         counter = 0
+        
+        
+        # Clean system definitions in /var/lib/dhcpd/dhcpd.leases just in
+        # case to avoid conflicts with the hosts we're defining and to clean
+        # possible removed hosts (only if using OMAPI)
+        #
+        # Pablo Iranzo Gómez (Pablo.Iranzo@xxxxxxxxxx)
+        if mode == "isc" and self.settings.omapi and self.settings.omapi_port:
+          file = open('/var/lib/dhcpd/dhcpd.leases')
+          item = shlex(file)
+          while 1:
+            elem = item.get_token()
+            if not elem:
+              break
+            if elem == 'host':
+              hosttoremove =  item.get_token()
+              self.removeDHCPLease(self.settings.omapi_port,hosttoremove)
+        
 
         # we used to just loop through each system, but now we must loop
         # through each network interface of each system.
-
+        
         for system in self.systems:
             profile = system.get_conceptual_parent()
             distro  = profile.get_conceptual_parent()
@@ -121,6 +186,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 +270,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/cobbler/webui/master.py b/cobbler/webui/master.py
index 22391eb..c1ff179 100644
--- a/cobbler/webui/master.py
+++ b/cobbler/webui/master.py
@@ -33,10 +33,10 @@ VFN=valueForName
 currentTime=time.time
 __CHEETAH_version__ = '2.0.1'
 __CHEETAH_versionTuple__ = (2, 0, 1, 'final', 0)
-__CHEETAH_genTime__ = 1209057202.737108
-__CHEETAH_genTimestamp__ = 'Thu Apr 24 13:13:22 2008'
+__CHEETAH_genTime__ = 1209458104.666045
+__CHEETAH_genTimestamp__ = 'Tue Apr 29 10:35:04 2008'
 __CHEETAH_src__ = 'webui_templates/master.tmpl'
-__CHEETAH_srcLastModified__ = 'Thu Apr 24 12:59:37 2008'
+__CHEETAH_srcLastModified__ = 'Sat Apr 26 00:34:42 2008'
 __CHEETAH_docstring__ = 'Autogenerated by CHEETAH: The Python-Powered Template Engine'
 
 if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
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
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:

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

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux