From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 1 of 9] pygrub: introduce easier to parse output format
Date: Mon, 12 Jul 2010 15:01:37 +0100 [thread overview]
Message-ID: <988cf8dff1c04dda692d.1278943297@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1278943296@localhost.localdomain>
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>
diff -r 4f194a196734 -r 988cf8dff1c0 tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub Mon Jul 12 11:40:17 2010 +0100
+++ b/tools/pygrub/src/pygrub Mon Jul 12 14:56:37 2010 +0100
@@ -630,16 +630,34 @@
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 @@
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 @@
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 @@
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 @@
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)
next prev parent reply other threads:[~2010-07-12 14:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-12 14:01 [PATCH 0 of 9] libxl/xl: support for domain 0 bootloader (e.g. pygrub) Ian Campbell
2010-07-12 14:01 ` Ian Campbell [this message]
2010-07-12 14:01 ` [PATCH 2 of 9] xenconsole: do not exit if a pty device is missing Ian Campbell
2010-07-12 14:01 ` [PATCH 3 of 9] libxl: add printf attribute to libxl_xs_write and fixup resulting warnings Ian Campbell
2010-07-12 14:01 ` [PATCH 4 of 9] libxl: add libxl_strdup convenience function Ian Campbell
2010-07-12 14:01 ` [PATCH 5 of 9] libxl: fix typo Ian Campbell
2010-07-12 14:01 ` [PATCH 6 of 9] libxl/xl: exec xenconsole in current process, defer decision to fork to caller Ian Campbell
2010-07-12 14:01 ` [PATCH 7 of 9] libxl: support mapping files rather than carrying paths around Ian Campbell
2010-07-12 14:01 ` [PATCH 8 of 9] libxl: add function to attach/detach a disk to/from the local VM Ian Campbell
2010-07-12 14:01 ` [PATCH 9 of 9] libxl/xl: support running bootloader (e.g. pygrub) in domain 0 Ian Campbell
2010-07-13 18:23 ` [PATCH 0 of 9] libxl/xl: support for domain 0 bootloader (e.g. pygrub) Ian Jackson
2010-07-14 1:24 ` Zhigang Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=988cf8dff1c04dda692d.1278943297@localhost.localdomain \
--to=ian.campbell@citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).