From 54dd6308a2217d8bfa499982b43459a7a3f04520 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 15 Feb 2007 12:05:06 -0500 Subject: More work on PXE menus. Getting there, just need timeout logic to work. --- cobbler/action_sync.py | 78 +++++++++++++++++++++---------------------------- cobbler/item_profile.py | 9 +----- 2 files changed, 35 insertions(+), 52 deletions(-) diff --git a/cobbler/action_sync.py b/cobbler/action_sync.py index 56d4538..502c879 100644 --- a/cobbler/action_sync.py +++ b/cobbler/action_sync.py @@ -70,7 +70,7 @@ class BootSync: if self.settings.manage_dhcp: self.write_dhcp_file() self.restart_dhcp() - self.make_tftp_menu() + self.make_pxe_menu() return True def restart_dhcp(self): @@ -110,6 +110,8 @@ class BootSync: newname = os.path.basename(path) destpath = os.path.join(self.settings.tftpboot, newname) self.copyfile(path, destpath) + self.copyfile("/usr/lib/syslinux/menu.c32", os.path.join(self.settings.tftpboot, "menu.c32")) + def write_dhcp_file(self): """ @@ -121,7 +123,7 @@ class BootSync: except: raise cexceptions.CobblerException("exc_no_template") template_data = "" - f1 = self.open_file("/etc/dhcpd.conf","w+") + #f1 = self.open_file("/etc/dhcpd.conf","w+") template_data = f2.read() f2.close() @@ -157,9 +159,9 @@ class BootSync: "date" : time.asctime(time.gmtime()), "next_server" : self.settings.next_server } - self.apply_template(template_data, metadata, f1) - self.tee(f1,template_data) - self.close_file(f1) + self.apply_template(template_data, metadata, "/etc/dhcpd.conf") + #self.tee(f1,template_data) + #self.close_file(f1) def templatify(self, data, metadata, outfile): for x in metadata.keys(): @@ -448,7 +450,7 @@ class BootSync: Take filesystem file kickstart_input, apply metadata using Cheetah and save as out_path. """ - if type(data_input) != "str": + if type(data_input) != str: data = data_input.read() else: data = data_input @@ -461,9 +463,6 @@ class BootSync: t = Template(source=data, searchList=metadata) data_out = str(t) - #for x in metadata.keys(): - # if x != "": - # data = data.replace("TEMPLATE::%s" % x, metadata[x]) self.mkdir(os.path.basename(out_path)) fd = open(out_path, "w+") fd.write(data_out) @@ -562,7 +561,7 @@ class BootSync: else: raise cexceptions.CobblerException("err_resolv", name) - def make_tftp_menu(self): + def make_pxe_menu(self): # only do this if there is NOT a system named default. default = self.systems.find("default") if default is not None: @@ -570,47 +569,36 @@ class BootSync: # generate the defaults file: fname = os.path.join(self.settings.tftpboot, "pxelinux.cfg", "default") - # get menu categories - categories = {} - for profile in self.profiles: - categories[profile.pxe_category] = 1 - categories = categories.keys() - defaults = open(fname, "w") - defaults.write("default local\n") - defaults.write("timeout 60\n") - defaults.write("prompt 1\n") + defaults.write("DEFAULT menu.c32\n") + defaults.write("PROMPT 0\n") + defaults.write("MENU TITLE Cobbler | http://cobbler.et.redhat.com\n") + defaults.write("TIMEOUT 200\n") + defaults.write("TOTALTIMEOUT 600\n") + defaults.write("ONTIMEOUT local\n") defaults.write("\n") - defaults.write("label local\n") + defaults.write("LABEL local\n") + defaults.write("\tMENU LABEL (local)\n") + defaults.write("\tMENU DEFAULT\n") defaults.write("\tLOCALBOOT 0\n") defaults.write("\n") - categories.sort() + profile_list = [profile for profile in self.profiles] + def sort_name(a,b): + return cmp(a.name,b.name) + profile_list.sort(sort_name) - for category in categories: - defaults.write("label %s\n" % category) - defaults.write("\tkernel menu.c32\n") - defaults.write("\tappend menu_%s\n" % category) - defaults.write("\n") - - catfile = open(os.path.join(self.settings.tftpboot, "pxelinux.cfg", "menu_%s" % category), "w") - profile_list = [profile for profile in self.profiles] - def sort_name(a,b): - return cmp(a.name,b.name) - profile_list.sort(sort_name) - for profile in profile_list: + for profile in profile_list: - if profile.pxe_category == category: - catfile.write("label %s\n" % profile.name) - - # a evil invocation of the pxe file creation tool that only generates bits and pieces - # without a filename to write to, and without system interpolation, so it's basically just - # bits and pieces relevant to the profile. - distro = self.distros.find(profile.distro) - contents = self.write_pxe_file(None,None,profile,distro,False,include_header=False) - catfile.write(contents + "\n") - catfile.write("\n") - catfile.close() + defaults.write("LABEL %s\n" % profile.name) + # a evil invocation of the pxe file creation tool that only generates bits and pieces + # without a filename to write to, and without system interpolation, so it's basically just + # bits and pieces relevant to the profile. + distro = self.distros.find(profile.distro) + contents = self.write_pxe_file(None,None,profile,distro,False,include_header=False) + defaults.write(contents + "\n") + defaults.write("\n") + defaults.close() def write_pxe_file(self,filename,system,profile,distro,is_ia64, include_header=True): @@ -687,6 +675,8 @@ class BootSync: # now to add the append line to the file if not is_ia64: + if system is None: + buffer = buffer + "\tMENU LABEL %s\n" % profile.name # pxelinux.cfg syntax buffer = buffer + "\tappend %s" % append_line else: diff --git a/cobbler/item_profile.py b/cobbler/item_profile.py index badd5ff..c6cb13a 100644 --- a/cobbler/item_profile.py +++ b/cobbler/item_profile.py @@ -40,7 +40,6 @@ class Profile(item.Item): self.virt_ram = 512 # MB. Install with 256 not likely to pass self.virt_paravirt = True # hvm support is *NOT* in Koan (now) self.repos = "" # names of cobbler repo definitions - self.pxe_category = "misc" def from_datastruct(self,seed_data): """ @@ -53,7 +52,6 @@ class Profile(item.Item): self.kernel_options = self.load_item(seed_data,'kernel_options') self.ks_meta = self.load_item(seed_data,'ks_meta') self.repos = self.load_item(seed_data,'repos', []) - self.pxe_category = self.load_item(seed_data,'pxe_category', 'misc') # backwards compatibility if type(self.repos) != list: @@ -167,10 +165,6 @@ class Profile(item.Item): except: return cexceptions.CobblerException("exc_virt_ram") - def set_pxe_category(self, category): - self.pxe_category = category - return True - def set_virt_paravirt(self,truthiness): """ For Virt only. @@ -217,8 +211,7 @@ class Profile(item.Item): 'virt_ram' : self.virt_ram, 'virt_paravirt' : self.virt_paravirt, 'ks_meta' : self.ks_meta, - 'repos' : self.repos, - 'pxe_category' : self.pxe_category + 'repos' : self.repos } def printable(self): -- cgit