Ticket #85: omshell.diff

File omshell.diff, 5.2 KB (added by iranzo, 6 years ago)
  • cobbler/dhcpgen.py

    diff --git a/cobbler/dhcpgen.py b/cobbler/dhcpgen.py
    index 2d6facf..1677f7c 100644
    a b import sys 
    2222import glob 
    2323import traceback 
    2424import errno 
     25import popen2 
     26 
    2527 
    2628import utils 
    2729from cexceptions import * 
    class DHCPGen: 
    5355        self.repos       = config.repos() 
    5456        self.templar     = templar.Templar(config) 
    5557 
     58    def writeDHCPLease(self,port,host,ip,mac): 
     59            """writeDHCPLease(port,host,ip,mac) 
     60            Use DHCP's API to create a DHCP entry in the /var/lib/dhcpd/dhcpd.leases file """ 
     61            #Code from http://svn.osgdc.org/browse/kusu/kusu/trunk/src/kits/base/packages/kusu-base-installer/lib/kusu/nodefun.py?r=3025 
     62            fromchild, tochild = popen2.popen2("/usr/bin/omshell") 
     63            tochild.write("port %s\n" % port) 
     64            tochild.flush() 
     65            tochild.write("connect\n") 
     66            tochild.flush() 
     67            tochild.write("new host\n") 
     68            tochild.flush() 
     69            tochild.write('set name = \"%s\"\n' % host) 
     70            tochild.flush() 
     71            tochild.write("set ip-address = %s\n" % ip) 
     72            tochild.flush() 
     73            tochild.write("set hardware-address = %s\n" % mac) 
     74            tochild.flush() 
     75            tochild.write("set hardware-type = 1\n") 
     76            tochild.flush() 
     77            tochild.write("create\n") 
     78            tochild.flush() 
     79            tochild.close() 
     80            fromchild.close() 
     81           
     82    def removeDHCPLease(self,port,host): 
     83            """removeDHCPLease(port,host) 
     84            Use DHCP's API to delete a DHCP entry in the /var/lib/dhcpd/dhcpd.leases file """ 
     85            fromchild, tochild = popen2.popen2("/usr/bin/omshell") 
     86            tochild.write("port %s\n" % port) 
     87            tochild.flush() 
     88            tochild.write("connect\n") 
     89            tochild.flush() 
     90            tochild.write("new host\n") 
     91            tochild.flush() 
     92            tochild.write('set name = \"%s\"\n' % host) 
     93            tochild.flush() 
     94            tochild.write("open\n")   # opens register with host information 
     95            tochild.flush() 
     96            tochild.write("remove\n") 
     97            tochild.flush() 
     98            tochild.close() 
     99            fromchild.close() 
     100             
     101 
    56102    def write_dhcp_file(self): 
    57103        """ 
    58104        DHCP files are written when manage_dhcp is set in 
    class DHCPGen: 
    121167                    if ip is not None and ip != "": 
    122168                        systxt = systxt + "    fixed-address %s;\n" % ip 
    123169                    systxt = systxt + "}\n" 
     170                     
     171                    # If we have all values defined and we're using omapi, 
     172                    # we will just create entries dinamically into DHCPD 
     173                    # without requiring a restart (but file will be written 
     174                    # as usual for having it working after restart) 
     175                     
     176                    if ip is not None and ip != "": 
     177                      if mac is not None and mac != "": 
     178                        if host is not None and host != "": 
     179                          if self.settings.omapi and self.settings.omapi_port: 
     180                            self.removeDHCPLease(self.settings.omapi_port,host) 
     181                            self.writeDHCPLease(self.settings.omapi_port,host,ip,mac) 
     182                         
    124183 
    125184                else: 
    126185                    # dnsmasq.  don't have to write IP and other info here, but we do tag 
    class DHCPGen: 
    192251                if host is not None and host != "" and ip is not None and ip != "": 
    193252                    fh.write(ip + "\t" + host + "\n") 
    194253        fh.close() 
    195  
    196  
  • cobbler/settings.py

    diff --git a/cobbler/settings.py b/cobbler/settings.py
    index 40ed571..491de75 100644
    a b DEFAULTS = { 
    5858    "manage_dhcp"                 : 0, 
    5959    "manage_dhcp_mode"            : "isc", 
    6060    "next_server"                 : "127.0.0.1", 
     61    "omapi"                       : 1, 
     62    "omapi_port"                  : 647, 
    6163    "pxe_just_once"               : 0, 
    6264    "register_new_installs"       : 0, 
    6365    "run_install_triggers"        : 1, 
  • templates/dhcp.template

    diff --git a/templates/dhcp.template b/templates/dhcp.template
    index 705cc77..19afcad 100644
    a b ddns-update-style interim; 
    99 
    1010allow booting; 
    1111allow bootp; 
     12omapi-port 647; 
    1213 
    1314ignore client-updates; 
    1415set vendorclass = option vendor-class-identifier; 
  • triggers/restart-services.trigger

    diff --git a/triggers/restart-services.trigger b/triggers/restart-services.trigger
    index b65b825..6a0e320 100644
    a b bootapi = capi.BootAPI() 
    88settings = bootapi.settings() 
    99manage_dhcp = str(settings.manage_dhcp).lower() 
    1010manage_dhcp_mode = str(settings.manage_dhcp_mode).lower() 
     11omapi = settings.omapi 
     12omapi_port = settings.omapi_port 
     13 
     14 
     15 
     16# We're just going to restart DHCPD if using ISC and if not using OMAPI at all 
    1117 
    1218rc = 0 
    1319if manage_dhcp != "0": 
    1420    if manage_dhcp_mode == "isc": 
    15         rc = os.system("/sbin/service dhcpd restart") 
     21        if not omapi: 
     22          if not omapi_port: 
     23            rc = os.system("/sbin/service dhcpd restart") 
    1624    elif manage_dhcp_mode == "dnsmasq": 
    1725        rc = os.system("/sbin/service dnsmasq restart") 
    1826    else: