--- action_buildiso.py	2008-07-03 16:30:59.000000000 -0400
+++ buildiso.py	2008-07-24 11:21:09.000000000 -0400
@@ -29,27 +29,34 @@
 # FIXME: lots of overlap with pxegen.py, should consolidate
 # FIXME: disable timeouts and remove local boot for this?
 HEADER = """
-
-DEFAULT menu
+MENU COLOR HOTSEL       0;7;37;40 #cf101010 #20ff8000
+MENU MARGIN 10
+MENU ROWS 12
+MENU CMDLINEROW 15
+MENU ENDROW 19
+MENU VSHIFT 11
+MENU ROWS 9
+MENU TABMSGROW 16
+MENU TIMEOUTROW 17
+MENU TITLE LINUX Staging Menu
+DEFAULT menu.c32
 PROMPT 0
-MENU TITLE Cobbler | http://cobbler.et.redhat.com
 TIMEOUT 200
 TOTALTIMEOUT 6000
-ONTIMEOUT local
-
-LABEL local
-        MENU LABEL (local)
-        MENU DEFAULT
-        LOCALBOOT -1
+ONTIMEOUT localdisk
 
+LABEL localdisk
+        menu label ^1  Boot to localdisk
+        kernel chain.c32
+        append hd0 0
 """
 
 class BuildIso:
-    """
-    Handles conversion of internal state to the tftpboot tree layout
-    """
+  """
+  Handles conversion of internal state to the tftpboot tree layout
+  """
 
-    def __init__(self,config,verbose=False):
+  def __init__(self,config,verbose=False):
         """
         Constructor
         """
@@ -58,10 +65,11 @@
         self.api         = config.api
         self.distros     = config.distros()
         self.profiles    = config.profiles()
+        self.systems     = config.systems()
         self.distmap     = {}
         self.distctr     = 0
 
-    def make_shorter(self,distname):
+  def make_shorter(self,distname):
         if self.distmap.has_key(distname):
             return self.distmap[distname]
         else:
@@ -69,7 +77,7 @@
             self.distmap[distname] = str(self.distctr)
             return str(self.distctr)
 
-    def run(self,iso=None,tempdir=None,profiles=None):
+  def run(self,iso=None,tempdir=None,profiles=None,systems=None):
 
         # verify we can find isolinux.bin
 
@@ -101,13 +109,14 @@
         print _("- copying miscellaneous files")
         utils.copyfile(isolinuxbin, os.path.join(isolinuxdir, "isolinux.bin"))
         menu = "/var/lib/cobbler/menu.c32"
-        files = [ isolinuxbin, menu ]
+        chain = "/var/lib/cobbler/chain.c32"
+        files = [ isolinuxbin, menu, chain, menu ]
         for f in files:
             if not os.path.exists(f):
                 raise CX(_("Required file not found: %s") % f)
-        utils.copyfile(f, os.path.join(isolinuxdir, os.path.basename(f)))
- 
-        print _("- copying kernels and initrds")
+            utils.copyfile(f, os.path.join(isolinuxdir, os.path.basename(f)))
+
+        print _("- copying kernels and initrds - for profiles")
         # copy all images in included profiles to images dir
         for x in self.api.profiles():
            use_this = True
@@ -124,41 +133,154 @@
            shutil.copyfile(dist.kernel, os.path.join(isolinuxdir, "%s.krn" % distname))
            shutil.copyfile(dist.initrd, os.path.join(isolinuxdir, "%s.img" % distname))
 
-        # generate isolinux.cfg
+        print _("- copying kernels and initrds - for systems")
+        # copy all images in included profiles to images dir
+        for x in self.api.systems():
+           use_this = False
+           if systems is not None:
+              which_systems = systems.split(",")
+              if use_this in which_systems:
+                 use_this = True
+           y = x.get_conceptual_parent()
+           dist = y.get_conceptual_parent()
+           if dist.name.find("-xen") != -1:
+               continue
+           distname = self.make_shorter(dist.name)
+           # tempdir/isolinux/$distro/vmlinuz, initrd.img
+           # FIXME: this will likely crash on non-Linux breeds
+           shutil.copyfile(dist.kernel, os.path.join(isolinuxdir, "%s.krn" % distname))
+           shutil.copyfile(dist.initrd, os.path.join(isolinuxdir, "%s.img" % distname))
+
         print _("- generating a isolinux.cfg")
         isolinuxcfg = os.path.join(isolinuxdir, "isolinux.cfg")
         cfg = open(isolinuxcfg, "w+")
         cfg.write(HEADER) # fixme, use template
-        
-        for x in self.api.profiles():
-            # FIXME
-            use_this = True
-            if profiles is not None:
-                which_profiles = profiles.split(",")
-                if not use_this in which_profiles:
-                    use_this = False
-            if use_this:
-                dist = x.get_conceptual_parent()
-                if dist.name.find("-xen") != -1:
-                    continue
-                data = utils.blender(self.api, True, x)
-                distname = self.make_shorter(dist.name)
-
-                cfg.write("\n")
-                cfg.write("LABEL %s\n" % x.name)
-                cfg.write("  MENU LABEL %s\n" % x.name)
-                cfg.write("  kernel %s.krn\n" % distname)
-
-                if data["kickstart"].startswith("/"):
-                    data["kickstart"] = "http://%s/cblr/svc/op/ks/profile/%s" % (
-                        data["server"],
-                        x.name
-                    )
-
-                append_line = "  append initrd=%s.img" % distname
-                append_line = append_line + " ks=%s " % data["kickstart"]
-                append_line = append_line + " %s\n" % data["kernel_options"]
-                cfg.write(append_line)
+       
+	if systems is not None: 
+          print _("- generating system list")
+          for x in self.api.systems():
+            if systems is not None:
+              use_this = False
+              if systems is not None:
+                  which_systems = systems.split(",")
+                  if x.name in which_systems:
+                      use_this = True
+              if use_this:
+                  y = x.get_conceptual_parent()
+                  dist = y.get_conceptual_parent()
+                  if dist.name.find("-xen") != -1:
+                      continue
+                  data = utils.blender(self.api, True, x)
+                  distname = self.make_shorter(dist.name)
+
+                  cfg.write("\n")
+                  cfg.write("LABEL %s\n" % x.name)
+                  cfg.write("  MENU LABEL ^2  Install Linux: %s\n" % x.name)
+                  cfg.write("  kernel %s.krn\n" % distname)
+
+                  if data["kickstart"].startswith("/"):
+                       data["kickstart"] = "http://%s/cblr/svc/op/ks/system/%s" % (
+                           data["server"],
+                           x.name
+                       )	
+
+                  append_line = "  append initrd=%s.img" % distname
+                  append_line = append_line + " ks=%s" % data["kickstart"]
+                  append_line = append_line + " %s" % data["kernel_options"]
+                  append_line = append_line + "ip=%s" % data["ip_address_intf0"]
+                  append_line = append_line + " netmask=%s" % data["subnet_intf0"]
+                  append_line = append_line + " gateway=%s\n" % data["gateway_intf0"]
+                  cfg.write(append_line)
+
+                  cfg.write("\n")
+                  cfg.write("LABEL %s-serial\n" % x.name)
+                  cfg.write("  MENU LABEL ^3  Install Linux via serial console: %s\n" % x.name)
+                  cfg.write("  kernel %s.krn\n" % distname)
+
+                  if data["kickstart"].startswith("/"):
+                       data["kickstart"] = "http://%s/cblr/svc/op/ks/system/%s" % (
+                           data["server"],
+                           x.name
+                       )
+
+                  append_line = "  append initrd=%s.img" % distname
+                  append_line = append_line + " ks=%s" % data["kickstart"]
+                  append_line = append_line + " %s" % data["kernel_options"]
+                  append_line = append_line + "console=ttyS0,11520"
+                  append_line = append_line + " ip=%s" % data["ip_address_intf0"]
+                  append_line = append_line + " netmask=%s" % data["subnet_intf0"]
+                  append_line = append_line + " gateway=%s\n" % data["gateway_intf0"]
+                  cfg.write(append_line)
+
+		  cfg.write("\n")
+                  cfg.write("LABEL %s-rescue\n" % x.name)
+                  cfg.write("  MENU LABEL ^4  Rescue Boot: %s\n" % x.name)
+                  cfg.write("  kernel %s.krn\n" % distname)
+
+                  if data["kickstart"].startswith("/"):
+                       data["kickstart"] = "http://%s/cblr/svc/op/ks/system/%s" % (
+                           data["server"],
+                           x.name
+                       )
+
+                  append_line = "  append initrd=%s.img" % distname
+                  append_line = append_line + " ks=%s" % data["kickstart"]
+                  append_line = append_line + " %s" % data["kernel_options"]
+                  append_line = append_line + "rescue"
+                  append_line = append_line + " ip=%s" % data["ip_address_intf0"]
+                  append_line = append_line + " netmask=%s" % data["subnet_intf0"]
+                  append_line = append_line + " gateway=%s\n" % data["gateway_intf0"]
+                  cfg.write(append_line)
+
+                  cfg.write("\n")
+                  cfg.write("LABEL %s-rescue-serial\n" % x.name)
+                  cfg.write("  MENU LABEL ^5  Rescue Boot via serial console: %s\n" % x.name)
+                  cfg.write("  kernel %s.krn\n" % distname)
+
+                  if data["kickstart"].startswith("/"):
+                       data["kickstart"] = "http://%s/cblr/svc/op/ks/system/%s" % (
+                           data["server"],
+                           x.name
+                       )
+
+                  append_line = "  append initrd=%s.img" % distname
+                  append_line = append_line + " ks=%s" % data["kickstart"]
+                  append_line = append_line + " %s" % data["kernel_options"]
+                  append_line = append_line + "rescue console=ttyS0,115200"
+                  append_line = append_line + " ip=%s" % data["ip_address_intf0"]
+                  append_line = append_line + " netmask=%s" % data["subnet_intf0"]
+                  append_line = append_line + " gateway=%s\n" % data["gateway_intf0"]
+                  cfg.write(append_line)	
+        else:
+          print _("- generating profile list")
+          for x in self.api.profiles():
+              use_this = True
+              if profiles is not None:
+                  which_profiles = profiles.split(",")
+                  if not x.name in which_profiles:
+                      use_this = False
+              if use_this:
+                  dist = x.get_conceptual_parent()
+                  if dist.name.find("-xen") != -1:
+                      continue
+                  data = utils.blender(self.api, True, x)
+                  distname = self.make_shorter(dist.name)
+
+                  cfg.write("\n")
+                  cfg.write("LABEL %s\n" % x.name)
+                  cfg.write("  MENU LABEL %s\n" % x.name)
+                  cfg.write("  kernel %s.krn\n" % distname)
+
+                  if data["kickstart"].startswith("/"):
+                      data["kickstart"] = "http://%s/cblr/svc/op/ks/profile/%s" % (
+                          data["server"],
+                          x.name
+                      )
+
+                  append_line = "  append initrd=%s.img" % distname
+                  append_line = append_line + " ks=%s " % data["kickstart"]
+                  append_line = append_line + " %s\n" % data["kernel_options"]
+                  cfg.write(append_line)
 
         print _("- done writing config")        
         cfg.write("\n")
