diff options
-rw-r--r-- | cobbler/action_sync.py | 2 | ||||
-rw-r--r-- | cobbler/api.py | 15 | ||||
-rw-r--r-- | cobbler/dhcpgen.py | 106 | ||||
-rw-r--r-- | cobbler/settings.py | 2 | ||||
-rw-r--r-- | config/settings | 2 | ||||
-rw-r--r-- | templates/dhcp.template | 4 | ||||
-rw-r--r-- | tests/tests.py | 4 | ||||
-rw-r--r-- | triggers/restart-services.trigger | 4 |
8 files changed, 82 insertions, 57 deletions
diff --git a/cobbler/action_sync.py b/cobbler/action_sync.py index 98faa0c..53ef3a7 100644 --- a/cobbler/action_sync.py +++ b/cobbler/action_sync.py @@ -47,7 +47,7 @@ class BootSync: Handles conversion of internal state to the tftpboot tree layout """ - def __init__(self,config,verbose=False): + def __init__(self,config,verbose=False,dhcp=None,dns=None): """ Constructor """ diff --git a/cobbler/api.py b/cobbler/api.py index 7bcd4fa..29a854d 100644 --- a/cobbler/api.py +++ b/cobbler/api.py @@ -81,6 +81,16 @@ class BootAPI: "module", "authz_allowall" ) + self.dhcp = self.get_module_from_file( + "dhcp_management", + "module", + "dhcp_isc" + ) + self.dns = self.get_module_from_file( + "dns_management", + "module", + "dns_bind" + ) self.kickgen = kickgen.KickGen(self._config) self.logger.debug("API handle initialized") @@ -332,9 +342,12 @@ class BootAPI: saved with serialize() will NOT be synchronized with this command. """ self.log("sync") - sync = action_sync.BootSync(self._config) + sync = self.get_sync() return sync.run() + def get_sync(self): + return action_sync.BootSync(self._config,dhcp=self.dhcp,dns=self.dns) + def reposync(self, name=None): """ Take the contents of /var/lib/cobbler/repos and update them -- diff --git a/cobbler/dhcpgen.py b/cobbler/dhcpgen.py index cc6d410..5dd981c 100644 --- a/cobbler/dhcpgen.py +++ b/cobbler/dhcpgen.py @@ -60,44 +60,54 @@ class DHCPGen: """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() - + # FIXME: should use subprocess + try: + 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() + except IOError: + # FIXME: just catch 32 (broken pipe) and show a warning + pass + 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() + try: + 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() + except IOError: + # FIXME: convert this to subprocess. + # FIXME: catch specific errors only (32/broken pipe) + pass def write_dhcp_file(self): @@ -136,19 +146,17 @@ class DHCPGen: # 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@redhat.com) - if 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': - hostremove = item.get_token() - self.removeDHCPLease(self.settings.omapi_port,hostremove) - + if self.settings.omapi_enabled and self.settings.omapi_port: + if os.path.exists("/var/lib/dhcpd/dhcpd.leases"): + file = open('/var/lib/dhcpd/dhcpd.leases') + item = shlex(file) + while 1: + elem = item.get_token() + if not elem: + break + if elem == 'host': + hostremove = item.get_token() + self.removeDHCPLease(self.settings.omapi_port,hostremove) # we used to just loop through each system, but now we must loop # through each network interface of each system. @@ -195,7 +203,7 @@ class DHCPGen: 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: + if self.settings.omapi_enabled and self.settings.omapi_port: self.removeDHCPLease(self.settings.omapi_port,host) self.writeDHCPLease(self.settings.omapi_port,host,ip,mac) @@ -225,6 +233,8 @@ class DHCPGen: # we are now done with the looping through each interface of each system metadata = { + "omapi_enabled" : self.settings.omapi_enabled, + "omapi_port" : self.settings.omapi_port, "insert_cobbler_system_definitions" : system_definitions.get("default",""), "date" : time.asctime(time.gmtime()), "cobbler_server" : self.settings.server, diff --git a/cobbler/settings.py b/cobbler/settings.py index a661768..70b2ac8 100644 --- a/cobbler/settings.py +++ b/cobbler/settings.py @@ -62,7 +62,7 @@ DEFAULTS = { "manage_reverse_zones" : [], "named_conf" : "/etc/named.conf", "next_server" : "127.0.0.1", - "omapi" : 1, + "omapi_enabled" : 0, "omapi_port" : 647, "pxe_just_once" : 0, "register_new_installs" : 0, diff --git a/config/settings b/config/settings index 6f2aff6..8b39707 100644 --- a/config/settings +++ b/config/settings @@ -33,7 +33,7 @@ manage_dhcp: 0 manage_dhcp_mode: isc manage_dns: 0 next_server: '127.0.0.1' -omapi: 1 +omapi_enabled: 1 omapi_port: 647 pxe_just_once: 0 register_new_installs: 0 diff --git a/templates/dhcp.template b/templates/dhcp.template index 19afcad..344b108 100644 --- a/templates/dhcp.template +++ b/templates/dhcp.template @@ -9,7 +9,9 @@ ddns-update-style interim; allow booting; allow bootp; -omapi-port 647; +#if $omapi_enabled +omapi-port $omapi_port; +#end if ignore client-updates; set vendorclass = option vendor-class-identifier; diff --git a/tests/tests.py b/tests/tests.py index bb64dd1..02d53be 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -743,7 +743,7 @@ class SyncContents(BootTest): fh = open("/tftpboot/pxelinux.cfg/%s" % converted) data = fh.read() - self.assertTrue(data.find("op=ks") != -1) + self.assertTrue(data.find("/op/ks/") != -1) fh.close() # ensure that after sync is applied, the blender cache still allows @@ -753,7 +753,7 @@ class SyncContents(BootTest): self.api.sync() fh = open("/tftpboot/pxelinux.cfg/%s" % converted) data = fh.read() - self.assertTrue(data.find("op=ks") != -1) + self.assertTrue(data.find("/op/ks/") != -1) fh.close() diff --git a/triggers/restart-services.trigger b/triggers/restart-services.trigger index 24fc033..bc7c36e 100644 --- a/triggers/restart-services.trigger +++ b/triggers/restart-services.trigger @@ -9,7 +9,7 @@ settings = bootapi.settings() manage_dhcp = str(settings.manage_dhcp).lower() manage_dhcp_mode = str(settings.manage_dhcp_mode).lower() manage_dns = str(settings.manage_dns).lower() -omapi = settings.omapi +omapi_enabled = settings.omapi_enabled omapi_port = settings.omapi_port @@ -18,7 +18,7 @@ omapi_port = settings.omapi_port rc = 0 if manage_dhcp != "0": if manage_dhcp_mode == "isc": - if not omapi: + if not omapi_enabled: if not omapi_port: rc = os.system("/sbin/service dhcpd restart") elif manage_dhcp_mode == "dnsmasq": |