summaryrefslogtreecommitdiffstats
path: root/cobbler
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2008-05-02 12:41:20 -0400
committerMichael DeHaan <mdehaan@redhat.com>2008-05-02 12:41:20 -0400
commit13eff0d1bb7e36569a00bcd291d73781ab2351e4 (patch)
tree7db31b5904982b39d8ee39a192dbe037345f21c8 /cobbler
parent82f4bb814835a8aadcfe5cbba8bfbc4359c34b39 (diff)
downloadthird_party-cobbler-13eff0d1bb7e36569a00bcd291d73781ab2351e4.tar.gz
third_party-cobbler-13eff0d1bb7e36569a00bcd291d73781ab2351e4.tar.xz
third_party-cobbler-13eff0d1bb7e36569a00bcd291d73781ab2351e4.zip
Adjusting the dhcp patch some, prior to moving it all into modules/
Diffstat (limited to 'cobbler')
-rw-r--r--cobbler/action_sync.py2
-rw-r--r--cobbler/api.py15
-rw-r--r--cobbler/dhcpgen.py106
-rw-r--r--cobbler/settings.py2
4 files changed, 74 insertions, 51 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,