[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] Merge Jeremy's pygrub bootloader patch.
ChangeSet 1.1327.2.13, 2005/04/28 13:27:47+01:00, mjw@xxxxxxxxxxxxxxxxxxx Merge Jeremy's pygrub bootloader patch. Signed-off-by: Jeremy Katz <katzj@xxxxxxxxxx> Signed-off-by: Mike Wray <mike.wray@xxxxxx> Makefile | 1 pygrub/Makefile | 18 ++ pygrub/setup.py | 25 ++ pygrub/src/GrubConf.py | 229 ++++++++++++++++++++++++++ pygrub/src/fsys/__init__.py | 61 ++++++ pygrub/src/fsys/ext2/__init__.py | 38 ++++ pygrub/src/fsys/ext2/ext2module.c | 332 ++++++++++++++++++++++++++++++++++++++ pygrub/src/fsys/ext2/test.py | 15 + pygrub/src/pygrub | 270 ++++++++++++++++++++++++++++++ python/xen/xend/XendBootloader.py | 94 ++++++++++ python/xen/xend/XendDomainInfo.py | 40 ++++ python/xen/xend/server/blkif.py | 9 + python/xen/xm/create.py | 61 +++++- xfrd/xfrd.c | 4 14 files changed, 1180 insertions(+), 17 deletions(-) diff -Nru a/tools/Makefile b/tools/Makefile --- a/tools/Makefile 2005-05-13 16:04:53 -04:00 +++ b/tools/Makefile 2005-05-13 16:04:53 -04:00 @@ -11,6 +11,7 @@ SUBDIRS += xfrd SUBDIRS += xcs SUBDIRS += ioemu +SUBDIRS += pygrub .PHONY: all install clean check check_clean diff -Nru a/tools/pygrub/Makefile b/tools/pygrub/Makefile --- /dev/null Wed Dec 31 16:00:00 196900 +++ b/tools/pygrub/Makefile 2005-05-13 16:04:53 -04:00 @@ -0,0 +1,18 @@ + +XEN_ROOT = ../.. +include $(XEN_ROOT)/tools/Rules.mk + +all: build +build: + CFLAGS="$(CFLAGS)" python setup.py build + +ifndef XEN_PYTHON_NATIVE_INSTALL +install: all + CFLAGS="$(CFLAGS)" python setup.py install --home="$(DESTDIR)/usr" +else +install: all + CFLAGS="$(CFLAGS)" python setup.py install --root="$(DESTDIR)" +endif + +clean: + rm -rf build *.pyc *.pyo *.o *.a *~ diff -Nru a/tools/pygrub/setup.py b/tools/pygrub/setup.py --- /dev/null Wed Dec 31 16:00:00 196900 +++ b/tools/pygrub/setup.py 2005-05-13 16:04:53 -04:00 @@ -0,0 +1,25 @@ +from distutils.core import setup, Extension +import os + +extra_compile_args = [ "-fno-strict-aliasing", "-Wall", "-Werror" ] + +# in a perfect world, we'd figure out the fsys modules dynamically +ext2 = Extension("grub.fsys.ext2._pyext2", + extra_compile_args = extra_compile_args, + libraries = ["ext2fs"], + sources = ["src/fsys/ext2/ext2module.c"]) + +setup(name='pygrub', + version='0.1', + description='Boot loader that looks a lot like grub for Xen', + author='Jeremy Katz', + author_email='katzj@xxxxxxxxxx', + license='GPL', + package_dir={'grub': 'src'}, + scripts = ["src/pygrub"], + packages=['grub', + 'grub.fsys', + 'grub.fsys.ext2'], + ext_modules = [ext2] + ) + diff -Nru a/tools/pygrub/src/GrubConf.py b/tools/pygrub/src/GrubConf.py --- /dev/null Wed Dec 31 16:00:00 196900 +++ b/tools/pygrub/src/GrubConf.py 2005-05-13 16:04:53 -04:00 @@ -0,0 +1,229 @@ +# +# GrubConf.py - Simple grub.conf parsing +# +# Copyright 2005 Red Hat, Inc. +# Jeremy Katz <katzj@xxxxxxxxxx> +# +# This software may be freely redistributed under the terms of the GNU +# general public license. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +import os, sys +import logging + +def grub_split(s, maxsplit = -1): + """Split a grub option screen separated with either '=' or whitespace.""" + eq = s.find('=') + if eq == -1: + return s.split(None, maxsplit) + + # see which of a space or tab is first + sp = s.find(' ') + tab = s.find('\t') + if (tab != -1 and tab < sp) or (tab != -1 and sp == -1): + sp = tab + + if eq != -1 and eq < sp or (eq != -1 and sp == -1): + return s.split('=', maxsplit) + else: + return s.split(None, maxsplit) + +def get_path(s): + """Returns a tuple of (GrubDiskPart, path) corresponding to string.""" + if not s.startswith('('): + return (None, s) + idx = s.find(')') + if idx == -1: + raise ValueError, "Unable to find matching ')'" + d = s[:idx] + return (GrubDiskPart(d), s[idx + 1:]) + +class GrubDiskPart(object): + def __init__(self, str): + if str.find(',') != -1: + (self.disk, self.part) = str.split(",", 2) + else: + self.disk = str + self.part = None + + def __repr__(self): + if self.part is not None: + return "d%dp%d" %(self.disk, self.part) + else: + return "d%d" %(self,disk,) + + def get_disk(self): + return self._disk + def set_disk(self, val): + val = val.replace("(", "").replace(")", "") + self._disk = int(val[2:]) + disk = property(get_disk, set_disk) + + def get_part(self): + return self._part + def set_part(self, val): + if val is None: + self._part = val + return + val = val.replace("(", "").replace(")", "") + self._part = int(val) + part = property(get_part, set_part) + +class GrubImage(object): + def __init__(self, lines): + self._root = self._initrd = self._kernel = self._args = None + for l in lines: + (com, arg) = grub_split(l, 1) + + if self.commands.has_key(com): + if self.commands[com] is not None: + exec("%s = r\"%s\"" %(self.commands[com], arg.strip())) + else: + logging.info("Ignored image directive %s" %(com,)) + else: + logging.warning("Unknown image directive %s" %(com,)) + + def __repr__(self): + return ("title: %s\n" + " root: %s\n" + " kernel: %s\n" + " args: %s\n" + " initrd: %s" %(self.title, self.root, self.kernel, + self.args, self.initrd)) + + def set_root(self, val): + self._root = GrubDiskPart(val) + def get_root(self): + return self._root + root = property(get_root, set_root) + + def set_kernel(self, val): + if val.find(" ") == -1: + self._kernel = get_path(val) + self._args = None + return + (kernel, args) = val.split(None, 1) + self._kernel = get_path(kernel) + self._args = args + def get_kernel(self): + return self._kernel + def get_args(self): + return self._args + kernel = property(get_kernel, set_kernel) + args = property(get_args) + + def set_initrd(self, val): + self._initrd = get_path(val) + def get_initrd(self): + return self._initrd + initrd = property(get_initrd, set_initrd) + + # set up command handlers + commands = { "title": "self.title", + "root": "self.root", + "rootnoverify": "self.root", + "kernel": "self.kernel", + "initrd": "self.initrd", + "chainloader": None, + "module": None} + + +class GrubConfigFile(object): + def __init__(self, fn = None): + self.filename = fn + self.images = [] + self.timeout = -1 + + if fn is not None: + self.parse() + + def parse(self, buf = None): + if buf is None: + if self.filename is None: + raise ValueError, "No config file defined to parse!" + + f = open(self.filename, 'r') + lines = f.readlines() + f.close() + else: + lines = buf.split("\n") + + img = [] + for l in lines: + l = l.strip() + # skip blank lines + if len(l) == 0: + continue + # skip comments + if l.startswith('#'): + continue + # new image + if l.startswith("title"): + if len(img) > 0: + self.images.append(GrubImage(img)) + img = [l] + continue + + if len(img) > 0: + img.append(l) + continue + + try: + (com, arg) = grub_split(l, 1) + except ValueError: + com = l + arg = "" + + if self.commands.has_key(com): + if self.commands[com] is not None: + exec("%s = r\"%s\"" %(self.commands[com], arg.strip())) + else: _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |