Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Fedora/Linux Management Tools (http://www.linux-archive.org/fedora-linux-management-tools/)
-   -   cobbler buildiso add --systems option and fix --profiles selection. (http://www.linux-archive.org/fedora-linux-management-tools/109020-cobbler-buildiso-add-systems-option-fix-profiles-selection.html)

Dave Hatton 06-18-2008 01:58 PM

cobbler buildiso add --systems option and fix --profiles selection.
 
The attached patch is for the "cobbler buildiso" command
1. It fixes the --profile option so that you can now *really* specify
which profiles you wish to include in the kickstart.iso
2. It adds a --systems option to allow you add specific systems to the
kickstart.iso


What is the process for having this reviewed and if suitable, merged
into cobbler?


Regards

Daveh
diff -Naur cobbler/modules/cli_misc.py.orig cobbler/modules/cli_misc.py
--- cobbler/modules/cli_misc.py.orig 2008-05-29 13:55:38.000000000 +0100
+++ cobbler/modules/cli_misc.py 2008-06-17 21:14:59.000000000 +0100
@@ -246,6 +246,7 @@
def add_options(self,p,args):
p.add_option("--iso", dest="isoname", help="(OPTIONAL) output ISO to this path")
p.add_option("--profiles", dest="profiles", help="(OPTIONAL) use these profiles only")
+ p.add_option("--systems", dest="systems", help="(OPTIONAL) use these systems only")
p.add_option("--tempdir", dest="tempdir", help="(OPTIONAL) working directory")

def help_me(self):
@@ -258,6 +259,7 @@
return self.api.build_iso(
iso=self.options.isoname,
profiles=self.options.profiles,
+ systems=self.options.systems,
tempdir=self.options.tempdir
)

diff -Naur cobbler/action_buildiso.py.orig cobbler/action_buildiso.py
--- cobbler/action_buildiso.py.orig 2008-05-29 10:56:25.000000000 +0100
+++ cobbler/action_buildiso.py 2008-06-18 14:08:51.000000000 +0100
@@ -58,6 +58,7 @@
self.api = config.api
self.distros = config.distros()
self.profiles = config.profiles()
+ self.systems = config.systems()
self.distmap = {}
self.distctr = 0

@@ -69,7 +70,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,syste ms=None):

# verify we can find isolinux.bin

@@ -107,7 +108,7 @@
raise CX(_("Required file not found: %s") % f)
utils.copyfile(f, os.path.join(isolinuxdir, os.path.basename(f)))

- print _("- copying kernels and initrds")
+ 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,18 +125,35 @@
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

+ print _("- generating profile list")
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:
+ if not x.name in which_profiles:
use_this = False
if use_this:
dist = x.get_conceptual_parent()
@@ -160,6 +178,37 @@
append_line = append_line + " %s
" % data["kernel_options"]
cfg.write(append_line)

+ print _("- generating system list")
+ for x in self.api.systems():
+ 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("
")
+ cfg.write("LABEL %s
" % x.name)
+ cfg.write(" MENU LABEL %s
" % x.name)
+ cfg.write(" kernel %s.krn
" % 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"]
+ cfg.write(append_line)
+
print _("- done writing config")
cfg.write("
")
cfg.write("MENU END
")
diff -Naur cobbler/api.py.orig cobbler/api.py
--- cobbler/api.py.orig 2008-05-29 15:13:28.000000000 +0100
+++ cobbler/api.py 2008-06-16 16:39:19.000000000 +0100
@@ -422,10 +422,10 @@
self.log("authorize",[user,resource,arg1,arg2,rc],debug=True)
return rc

- def build_iso(self,iso=None,profiles=None,tempdir=None ):
+ def build_iso(self,iso=None,profiles=None,systems=None ,tempdir=None):
builder = action_buildiso.BuildIso(self._config)
return builder.run(
- iso=iso, profiles=profiles, tempdir=tempdir
+ iso=iso, profiles=profiles, systems=systems, tempdir=tempdir
)

def replicate(self, cobbler_master = None):
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

Dave Hatton 06-25-2008 02:18 PM

cobbler buildiso add --systems option and fix --profiles selection.
 
Here is an updated patch for action_buildiso.py

I have run the diff against the original version of the program - would
it be better against the version in git?


Changes:
1. Captured Joesphs changes to clean up images placed in iso - but I've
left it to always include profiles and distros
2. I've changed "localboot 0/-1" option to use "KERNEL chain.32" with an
"APPEND"

3. Modified to make sure chain.c32 is added to the image
4. Added code to remove the buildiso directory if it exists to make sure
old files aren't kept around
5. Added a check and warning if APPEND line exceeds 250chars (think that
could be 254?)

6. Incorporated Joesphs IP address fixes
7. Added a MENU SEPARATOR when adding systems

I have a new chain.c32 and a replacement isolinux.bin file to go in
/var/lib/cobbler - should I send them to the ML?


Dave

diff -Naur cobbler/action_buildiso.py.orig cobbler/action_buildiso.py
--- cobbler/action_buildiso.py.orig 2008-05-29 10:56:25.000000000 +0100
+++ cobbler/action_buildiso.py 2008-06-25 13:58:30.000000000 +0100
@@ -40,7 +40,8 @@
LABEL local
MENU LABEL (local)
MENU DEFAULT
- LOCALBOOT -1
+ KERNEL chain.c32
+ APPEND hd0 0

"""

@@ -58,6 +59,7 @@
self.api = config.api
self.distros = config.distros()
self.profiles = config.profiles()
+ self.systems = config.systems()
self.distmap = {}
self.distctr = 0

@@ -69,23 +71,20 @@
self.distmap[distname] = str(self.distctr)
return str(self.distctr)

- def run(self,iso=None,tempdir=None,profiles=None):
-
- # verify we can find isolinux.bin
+ def run(self,iso=None,tempdir=None,profiles=None,syste ms=None):

+ # if iso is none, create it in . as "kickstart.iso"
if iso is None:
iso = "kickstart.iso"

- isolinuxbin = "/usr/lib/syslinux/isolinux.bin"
- if not os.path.exists(isolinuxbin):
- raise CX(_("Required file not found: %s") % isolinuxbin)
-
- # if iso is none, create it in . as "cobbler.iso"
if tempdir is None:
tempdir = os.path.join(os.getcwd(), "buildiso")
print _("- using/creating tempdir: %s") % tempdir
if not os.path.exists(tempdir):
os.makedirs(tempdir)
+ else:
+ shutil.rmtree(tempdir)
+ os.makedirs(tempdir)

# if base of tempdir does not exist, fail
# create all profiles unless filtered by "profiles"
@@ -99,66 +98,134 @@
os.makedirs(isolinuxdir)

print _("- copying miscellaneous files")
- utils.copyfile(isolinuxbin, os.path.join(isolinuxdir, "isolinux.bin"))
+ isolinuxbin = "/var/lib/cobbler/isolinux.bin"
menu = "/var/lib/cobbler/menu.c32"
- files = [ isolinuxbin, menu ]
+ chain = "/var/lib/cobbler/chain.c32"
+ files = [ isolinuxbin, menu, chain ]
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)))
+ raise CX(_("Required file not found: %s") % f)
+ else:
+ utils.copyfile(f, os.path.join(isolinuxdir, os.path.basename(f)))

- print _("- copying kernels and initrds")
+ print _("- copying kernels and initrds - for profiles")
# copy all images in included profiles to images dir
- for x in self.api.profiles():
+ for profile in self.api.profiles():
use_this = True
if profiles is not None:
which_profiles = profiles.split(",")
- if not use_this in which_profiles:
+ if not profile.name in which_profiles:
use_this = False
- dist = x.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))

- # generate isolinux.cfg
+ if use_this:
+ dist = profile.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))
+
+ if systems is not None:
+ print _("- copying kernels and initrds - for systems")
+ # copy all images in included profiles to images dir
+ for system in self.api.systems():
+ if system.name in systems:
+ profile = system.get_conceptual_parent()
+ dist = profile.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
+ print _("- generating profile list...")
+ for profile in self.api.profiles():
use_this = True
if profiles is not None:
which_profiles = profiles.split(",")
- if not use_this in which_profiles:
+ if not profile.name in which_profiles:
use_this = False
+
if use_this:
- dist = x.get_conceptual_parent()
+ dist = profile.get_conceptual_parent()
if dist.name.find("-xen") != -1:
continue
- data = utils.blender(self.api, True, x)
+ data = utils.blender(self.api, True, profile)
distname = self.make_shorter(dist.name)

cfg.write("
")
- cfg.write("LABEL %s
" % x.name)
- cfg.write(" MENU LABEL %s
" % x.name)
+ cfg.write("LABEL %s
" % profile.name)
+ cfg.write(" MENU LABEL %s
" % profile.name)
cfg.write(" kernel %s.krn
" % distname)

if data["kickstart"].startswith("/"):
data["kickstart"] = "http://%s/cblr/svc/op/ks/profile/%s" % (
data["server"],
- x.name
+ profile.name
)

append_line = " append initrd=%s.img" % distname
append_line = append_line + " ks=%s " % data["kickstart"]
append_line = append_line + " %s
" % data["kernel_options"]
+
+ length=len(append_line)
+ if length>250:
+ print _("WARNING - append line length is greater than 250 chars: (%s chars)") % length
+
cfg.write(append_line)
+
+ if systems is not None:
+ print _("- generating system list...")
+
+ cfg.write("
MENU SEPARATOR
")
+
+ for system in self.api.systems():
+ use_this = False
+ if systems is not None:
+ which_systems = systems.split(",")
+ if system.name in which_systems:
+ use_this = True
+
+ if use_this:
+ profile = system.get_conceptual_parent()
+ dist = profile.get_conceptual_parent()
+ if dist.name.find("-xen") != -1:
+ continue
+ data = utils.blender(self.api, True, system)
+ distname = self.make_shorter(dist.name)
+
+ cfg.write("
")
+ cfg.write("LABEL %s
" % system.name)
+ cfg.write(" MENU LABEL %s
" % system.name)
+ cfg.write(" kernel %s.krn
" % distname)
+
+ if data["kickstart"].startswith("/"):
+ data["kickstart"] = "http://%s/cblr/svc/op/ks/system/%s" % (
+ data["server"],
+ system.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
" % data["gateway_intf0"]
+
+ length=len(append_line)
+ if length>250:
+ print _("WARNING - append line length is greater than 250 chars: (%s chars)") % length
+
+ cfg.write(append_line)

print _("- done writing config")
cfg.write("
")

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools


All times are GMT. The time now is 01:26 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.