aboutsummaryrefslogtreecommitdiffstats
path: root/tools/pygrub
diff options
context:
space:
mode:
authorIan Jackson <Ian.Jackson@eu.citrix.com>2010-07-14 16:36:23 +0100
committerIan Jackson <Ian.Jackson@eu.citrix.com>2010-07-14 16:36:23 +0100
commitdc04fe42de492095fa4900cde51e449fb280803e (patch)
treea2b89a9db755c4f78f75933813605c6e1d47f85d /tools/pygrub
parentc89747d2e9deeca490e445aa03503c193ea6303e (diff)
downloadxen-dc04fe42de492095fa4900cde51e449fb280803e.tar.gz
xen-dc04fe42de492095fa4900cde51e449fb280803e.tar.bz2
xen-dc04fe42de492095fa4900cde51e449fb280803e.zip
pygrub: introduce easier to parse output format
libxl would rather like to parse the output of pygrub. Rather than implement an SXP parser in libxl add a --output-format option to pygrub which can select an alternative, simpler to parse, format. Available formats are: sxp: current SXP output format; simple: simple key+value output with \n separating item ( for debugging). key and value are separated by a single space (and key therefore cannot contain a space); simple0: as simple but with \0 as a separator; Also add --output-directory to allow temporary files to be placed somewhere other than /var/run/xend/boot. Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools/pygrub')
-rw-r--r--tools/pygrub/src/pygrub57
1 files changed, 44 insertions, 13 deletions
diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
index 0c1619da5e..952b73f398 100644
--- a/tools/pygrub/src/pygrub
+++ b/tools/pygrub/src/pygrub
@@ -630,16 +630,34 @@ def sniff_netware(fs, cfg):
return cfg
+def format_sxp(kernel, ramdisk, args):
+ s = "linux (kernel %s)" % kernel
+ if ramdisk:
+ s += "(ramdisk %s)" % ramdisk
+ if args:
+ s += "(args \"%s\")" % args
+ return s
+
+def format_simple(kernel, ramdisk, args, sep):
+ s = ("kernel %s" % kernel) + sep
+ if ramdisk:
+ s += ("ramdisk %s" % ramdisk) + sep
+ if args:
+ s += ("args %s" % args) + sep
+ s += sep
+ return s
+
if __name__ == "__main__":
sel = None
def usage():
- print >> sys.stderr, "Usage: %s [-q|--quiet] [-i|--interactive] [-n|--not-really] [--output=] [--kernel=] [--ramdisk=] [--args=] [--entry=] <image>" %(sys.argv[0],)
+ print >> sys.stderr, "Usage: %s [-q|--quiet] [-i|--interactive] [-n|--not-really] [--output=] [--kernel=] [--ramdisk=] [--args=] [--entry=] [--output-directory=] [--output-format=sxp|simple|simple0] <image>" %(sys.argv[0],)
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], 'qinh::',
- ["quiet", "interactive", "not-really",
- "help", "output=", "entry=", "kernel=",
+ ["quiet", "interactive", "not-really", "help",
+ "output=", "output-format=", "output-directory=",
+ "entry=", "kernel=",
"ramdisk=", "args=", "isconfig"])
except getopt.GetoptError:
usage()
@@ -655,6 +673,8 @@ if __name__ == "__main__":
interactive = True
isconfig = False
not_really = False
+ output_format = "sxp"
+ output_directory = "/var/run/xend/boot"
# what was passed in
incfg = { "kernel": None, "ramdisk": None, "args": "" }
@@ -687,6 +707,14 @@ if __name__ == "__main__":
interactive = False
elif o in ("--isconfig",):
isconfig = True
+ elif o in ("--output-format",):
+ if a not in ["sxp", "simple", "simple0"]:
+ print "unkonwn output format %s" % a
+ usage()
+ sys.exit(1)
+ output_format = a
+ elif o in ("--output-directory",):
+ output_directory = a
if output is None or output == "-":
fd = sys.stdout.fileno()
@@ -723,7 +751,7 @@ if __name__ == "__main__":
else:
data = fs.open_file(chosencfg["kernel"]).read()
(tfd, bootcfg["kernel"]) = tempfile.mkstemp(prefix="boot_kernel.",
- dir="/var/run/xend/boot")
+ dir=output_directory)
os.write(tfd, data)
os.close(tfd)
@@ -733,26 +761,29 @@ if __name__ == "__main__":
else:
data = fs.open_file(chosencfg["ramdisk"],).read()
(tfd, bootcfg["ramdisk"]) = tempfile.mkstemp(
- prefix="boot_ramdisk.", dir="/var/run/xend/boot")
+ prefix="boot_ramdisk.", dir=output_directory)
os.write(tfd, data)
os.close(tfd)
else:
initrd = None
- sxp = "linux (kernel %s)" % bootcfg["kernel"]
- if bootcfg["ramdisk"]:
- sxp += "(ramdisk %s)" % bootcfg["ramdisk"]
+ args = None
if chosencfg["args"]:
zfsinfo = fsimage.getbootstring(fs)
- if zfsinfo is None:
- sxp += "(args \"%s\")" % chosencfg["args"]
- else:
+ if zfsinfo is not None:
e = re.compile("zfs-bootfs=[\w\-\.\:@/]+" )
(chosencfg["args"],count) = e.subn(zfsinfo, chosencfg["args"])
if count == 0:
chosencfg["args"] += " -B %s" % zfsinfo
- sxp += "(args \"%s\")" % (chosencfg["args"])
+ args = chosencfg["args"]
+
+ if output_format == "sxp":
+ ostring = format_sxp(bootcfg["kernel"], bootcfg["ramdisk"], args)
+ elif output_format == "simple":
+ ostring = format_simple(bootcfg["kernel"], bootcfg["ramdisk"], args, "\n")
+ elif output_format == "simple0":
+ ostring = format_simple(bootcfg["kernel"], bootcfg["ramdisk"], args, "\0")
sys.stdout.flush()
- os.write(fd, sxp)
+ os.write(fd, ostring)