summaryrefslogtreecommitdiffstats
path: root/cobbler
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@mdehaan.rdu.redhat.com>2007-05-24 11:33:36 -0400
committerMichael DeHaan <mdehaan@mdehaan.rdu.redhat.com>2007-05-24 11:33:36 -0400
commitbeba5671e2b25aa86c32916484645129b10b676c (patch)
treeed8b1121eebdb2ffabc7d529b69a46d501da9cb8 /cobbler
parentc0d3d1770366dafa2cca9eead71833c4d39180b2 (diff)
downloadthird_party-cobbler-beba5671e2b25aa86c32916484645129b10b676c.tar.gz
third_party-cobbler-beba5671e2b25aa86c32916484645129b10b676c.tar.xz
third_party-cobbler-beba5671e2b25aa86c32916484645129b10b676c.zip
Add support for dnsmasq as an alternative to ISC dhcpd.
Also add --hostname option to "cobbler system add" for dnsmasq DNS control features.
Diffstat (limited to 'cobbler')
-rw-r--r--cobbler/action_check.py23
-rw-r--r--cobbler/action_import.py2
-rw-r--r--cobbler/action_sync.py79
-rwxr-xr-xcobbler/cobbler.py4
-rw-r--r--cobbler/cobbler_msg.py6
-rw-r--r--cobbler/item_system.py16
-rw-r--r--cobbler/settings.py3
7 files changed, 99 insertions, 34 deletions
diff --git a/cobbler/action_check.py b/cobbler/action_check.py
index f35b2a5..49ba174 100644
--- a/cobbler/action_check.py
+++ b/cobbler/action_check.py
@@ -35,12 +35,20 @@ class BootCheck:
"""
status = []
self.check_name(status)
- self.check_dhcpd_bin(status)
+ if self.settings.manage_dhcp:
+ mode = self.settings.manage_dhcp_mode.lower()
+ if mode == "isc":
+ self.check_dhcpd_bin(status)
+ self.check_dhcpd_conf(status)
+ elif mode == "dnsmasq":
+ self.check_dnsmasq_bin(status)
+ else:
+ status.append(cobbler_msg.lookup("dhcp_choice"))
+
self.check_bootloaders(status)
self.check_tftpd_bin(status)
self.check_tftpd_dir(status)
self.check_tftpd_conf(status)
- self.check_dhcpd_conf(status)
self.check_httpd(status)
return status
@@ -61,7 +69,7 @@ class BootCheck:
Check if Apache is installed.
"""
if not os.path.exists(self.settings.httpd_bin):
- status.append(cobbler_msg.lookup("no_httpd"))
+ status.append(cobbler_msg.lookup("no_httpd"))
def check_dhcpd_bin(self,status):
@@ -69,7 +77,14 @@ class BootCheck:
Check if dhcpd is installed
"""
if not os.path.exists(self.settings.dhcpd_bin):
- status.append(cobbler_msg.lookup("no_dhcpd"))
+ status.append(cobbler_msg.lookup("no_dhcpd"))
+
+ def check_dnsmasq_bin(self,status):
+ """
+ Check if dnsmasq is installed
+ """
+ if not os.path.exists(self.settings.dnsmasq_bin):
+ status.append(cobbler_msg.lookup("no_dnsmasq"))
def check_bootloaders(self,status):
"""
diff --git a/cobbler/action_import.py b/cobbler/action_import.py
index a01128d..cd623a0 100644
--- a/cobbler/action_import.py
+++ b/cobbler/action_import.py
@@ -270,7 +270,7 @@ class Importer:
def repo_scanner(self,distro,dirname,fnames):
for x in fnames:
- if x == "repodata" or x == "base":
+ if x == "base": # don't do "repodata"
self.process_comps_file(dirname, distro)
continue
diff --git a/cobbler/action_sync.py b/cobbler/action_sync.py
index 2af7dd1..e6225c7 100644
--- a/cobbler/action_sync.py
+++ b/cobbler/action_sync.py
@@ -67,6 +67,7 @@ class BootSync:
self.validate_kickstarts()
self.build_trees()
if self.settings.manage_dhcp:
+ # these functions DRT for ISC or dnsmasq
self.write_dhcp_file()
self.restart_dhcp()
self.make_pxe_menu()
@@ -75,14 +76,19 @@ class BootSync:
def restart_dhcp(self):
"""
DHCP restarts need to be made when the config file is
- changed.
+ changed. ISC or DNSMASQ. Support for ISC omshell not
+ yet available (adding dynamically w/o restart).
"""
try:
- retcode = self.service("dhcpd", "restart")
+ mode = self.settings.manage_dhcp_mode.lower()
+ service = "dhcpd"
+ if mode == "dnsmasq":
+ service = "dnsmasq"
+ retcode = self.service(service, "restart")
if retcode != 0:
- print >>sys.stderr, "Warning: dhcpd restart failed"
+ print >>sys.stderr, "Warning: %s restart failed" % service
except OSError, e:
- print >>sys.stderr, "Warning: dhcpd restart failed: ", e
+ print >>sys.stderr, "Warning: %s restart failed: " % service, e
def copy_koan(self):
"""
@@ -111,25 +117,35 @@ class BootSync:
self.copyfile(path, destpath)
self.copyfile("/var/lib/cobbler/menu.c32", os.path.join(self.settings.tftpboot, "menu.c32"))
-
def write_dhcp_file(self):
"""
DHCP files are written when manage_dhcp is set in
/var/lib/cobbler/settings.
"""
+
+ settings_file = self.settings.dhcpd_conf
+ template_file = "/etc/cobbler/dhcp.template"
+ mode = self.settings.manage_dhcp_mode.lower()
+ # print "my mode is: %s" % mode
+ if mode == "dnsmasq":
+ settings_file = self.settings.dnsmasq_conf
+ template_file = "/etc/cobbler/dnsmasq.template"
+
try:
- f2 = open("/etc/cobbler/dhcp.template","r")
+ f2 = open(template_file,"r")
except:
- raise cexceptions.CobblerException("exc_no_template")
+ raise cexceptions.CobblerException("exc_no_template",template_file)
template_data = ""
- #f1 = self.open_file("/etc/dhcpd.conf","w+")
template_data = f2.read()
f2.close()
# build each per-system definition
+ # as configured, this only works for ISC, patches accepted
+ # from those that care about Itanium.
+ elilo = os.path.basename(self.settings.bootloaders["ia64"])
+
system_definitions = ""
counter = 0
- elilo = os.path.basename(self.settings.bootloaders["ia64"])
for system in self.systems:
if not utils.is_mac(system.name):
# can't do per-system dhcp features if the system
@@ -138,19 +154,35 @@ class BootSync:
# if you want to PXE IA64 boxes, you need to use
# the MAC as the system name.
continue
- systxt = ""
+
+
counter = counter + 1
- systxt = "\nhost label%d {\n" % counter
- profile = self.profiles.find(system.profile)
- distro = self.distros.find(profile.distro)
- if distro.arch == "ia64":
- # can't use pxelinux.0 anymore
- systxt = systxt + " filename \"/%s\";\n" % elilo
- systxt = systxt + " hardware ethernet %s;\n" % system.name
- if system.pxe_address != "":
- systxt = systxt + " fixed-address %s;\n" % system.pxe_address
- systxt = systxt + " next-server %s;\n" % self.settings.next_server
- systxt = systxt + "}\n"
+ systxt = ""
+ if mode == "isc":
+
+ systxt = "\nhost label%d {\n" % counter
+ profile = self.profiles.find(system.profile)
+ distro = self.distros.find(profile.distro)
+ if distro.arch == "ia64":
+ # can't use pxelinux.0 anymore
+ systxt = systxt + " filename \"/%s\";\n" % elilo
+ systxt = systxt + " hardware ethernet %s;\n" % system.name
+ if system.pxe_address != "":
+ systxt = systxt + " fixed-address %s;\n" % system.pxe_address
+ systxt = systxt + " next-server %s;\n" % self.settings.next_server
+ systxt = systxt + "}\n"
+ system_definitions = system_definitions + systxt
+
+ else:
+ # dnsmasq. dnsmasq also allows for setting hostnames. Neat.
+
+ systxt = systxt + "dhcp-host=" + system.name
+ if system.pxe_address != "":
+ systxt = systxt + "," + system.pxe_address
+ if system.hostname != "":
+ systxt = systxt + "," + system.hostname + ",infinite"
+ systxt = systxt + "\n"
+
system_definitions = system_definitions + systxt
metadata = {
@@ -158,9 +190,8 @@ class BootSync:
"date" : time.asctime(time.gmtime()),
"next_server" : self.settings.next_server
}
- self.apply_template(template_data, metadata, "/etc/dhcpd.conf")
- #self.tee(f1,template_data)
- #self.close_file(f1)
+ # print "writing to: %s" % settings_file
+ self.apply_template(template_data, metadata, settings_file)
def templatify(self, data, metadata, outfile):
for x in metadata.keys():
diff --git a/cobbler/cobbler.py b/cobbler/cobbler.py
index f8d3f53..77e8a81 100755
--- a/cobbler/cobbler.py
+++ b/cobbler/cobbler.py
@@ -448,7 +448,9 @@ class BootCLI:
'--profile' : lambda(a) : sys.set_profile(a),
'--kopts' : lambda(a) : sys.set_kernel_options(a),
'--ksmeta' : lambda(a) : sys.set_ksmeta(a),
- '--pxe-address' : lambda(a) : sys.set_pxe_address(a)
+ '--hostname' : lambda(a) : sys.set_hostname(a),
+ '--pxe-address' : lambda(a) : sys.set_ip_address(a),
+ '--ip-address' : lambda(a) : sys.set_ip_address(a)
}
def on_ok():
self.api.systems().add(sys, with_copy=self.api.sync_flag)
diff --git a/cobbler/cobbler_msg.py b/cobbler/cobbler_msg.py
index 121d70e..d9f3183 100644
--- a/cobbler/cobbler_msg.py
+++ b/cobbler/cobbler_msg.py
@@ -78,8 +78,10 @@ _msg_table = {
"need_perms" : "cobbler could not access %s",
"need_perms2" : "cobbler could not copy %s to %s",
"no_dhcpd" : "cobbler couldn't find dhcpd, try 'yum install dhcp'",
+ "no_dnsmasq" : "cobbler couldn't find dnsmasq, try 'yum install dnsmasq'",
+ "dhcp_choice" : "manage_dhcp_mode in /var/lib/cobbler/settings should be 'isc' or 'dnsmasq'",
"no_bootloader" : "missing 1 or more bootloader files listed in /var/lib/cobbler/settings",
- "no_tftpd" : "cobbler couldn't find tftpd, try 'yum install tftpd'",
+ "no_tftpd" : "cobbler couldn't find tftpd, try 'yum install tftpd-server'",
"no_dir" : "cobbler couldn't find %s, please create it",
"no_mirror" : "mirror URL is not valid",
"chg_attrib" : "need to change field '%s' value to '%s' in file '%s'",
@@ -124,7 +126,7 @@ _msg_table = {
"exc_profile" : "invalid profile name",
"exc_profile2" : "profile name not set",
"exc_pxe_arch" : "valid PXE architectures: standard or ia64",
- "exc_no_template" : "can't read /etc/cobbler/dhcp.template",
+ "exc_no_template" : "can't read template file (%s)",
"exc_dhcp_nomac" : "when cobbler is managing dhcpd.conf, all system names must be MAC addresses. Aborting.",
"exc_ia64_noip" : "due to an IA64 bootloader limitation, system (%s) must define a pxe-address value (which is an IP address)",
"exc_kopts" : "Kernel options should be a space delimited list of values and key=value pairs",
diff --git a/cobbler/item_system.py b/cobbler/item_system.py
index 53cc979..e481097 100644
--- a/cobbler/item_system.py
+++ b/cobbler/item_system.py
@@ -35,6 +35,7 @@ class System(item.Item):
self.ks_meta = {}
self.pxe_address = ""
self.netboot_enabled = 1
+ self.hostname = ""
def from_datastruct(self,seed_data):
self.name = self.load_item(seed_data, 'name')
@@ -43,6 +44,7 @@ class System(item.Item):
self.ks_meta = self.load_item(seed_data, 'ks_meta')
self.pxe_address = self.load_item(seed_data, 'pxe_address')
self.netboot_enabled = self.load_item(seed_data, 'netboot_enabled', 1)
+ self.hostname = self.load_item(seed_data, 'hostname')
# backwards compatibility -- convert string entries to dicts for storage
if type(self.kernel_options) != dict:
@@ -67,6 +69,14 @@ class System(item.Item):
self.name = name # we check it add time, but store the original value.
return True
+ def set_hostname(self,hostname):
+ self.hostname = hostname
+ return True
+
+ def set_ip_address(self,address):
+ # allow function to use more sensical name
+ return self.set_pxe_address(address)
+
def set_pxe_address(self,address):
"""
Assign a IP or hostname in DHCP when this MAC boots.
@@ -128,7 +138,8 @@ class System(item.Item):
'kernel_options' : self.kernel_options,
'ks_meta' : self.ks_meta,
'pxe_address' : self.pxe_address,
- 'netboot_enabled' : self.netboot_enabled
+ 'netboot_enabled' : self.netboot_enabled,
+ 'hostname' : self.hostname,
}
def printable(self):
@@ -136,6 +147,7 @@ class System(item.Item):
buf = buf + "profile : %s\n" % self.profile
buf = buf + "kernel options : %s\n" % self.kernel_options
buf = buf + "ks metadata : %s\n" % self.ks_meta
- buf = buf + "pxe address : %s\n" % self.pxe_address
+ buf = buf + "ip address : %s\n" % self.pxe_address
+ buf = buf + "hostname : %s\n" % self.hostname
return buf
diff --git a/cobbler/settings.py b/cobbler/settings.py
index 2aa421b..58995a4 100644
--- a/cobbler/settings.py
+++ b/cobbler/settings.py
@@ -20,10 +20,12 @@ TESTMODE = False
DEFAULTS = {
"httpd_bin" : "/usr/sbin/httpd",
"dhcpd_conf" : "/etc/dhcpd.conf",
+ "dnsmasq_conf" : "/etc/dnsmasq.conf",
"tftpd_bin" : "/usr/sbin/in.tftpd",
"server" : "127.0.0.1",
"next_server" : "127.0.0.1",
"dhcpd_bin" : "/usr/sbin/dhcpd",
+ "dnsmasq_bin" : "/usr/sbin/dnsmasq",
"kernel_options" : {
"lang" : " ",
"text" : None,
@@ -34,6 +36,7 @@ DEFAULTS = {
"webdir" : "/var/www/cobbler",
"default_kickstart" : "/etc/cobbler/default.ks",
"manage_dhcp" : 0,
+ "manage_dhcp_mode" : "isc",
"koan_path" : "",
"bootloaders" : {
"standard" : "/usr/lib/syslinux/pxelinux.0",