WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-tools

[Xen-tools] [PATCH] Add a --format parameter to xm list

To: Xen Tools <xen-tools@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-tools] [PATCH] Add a --format parameter to xm list
From: Anthony Liguori <aliguori@xxxxxxxxxx>
Date: Wed, 10 Aug 2005 17:21:07 -0500
Delivery-date: Wed, 10 Aug 2005 22:19:35 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-tools-request@lists.xensource.com?subject=help>
List-id: Xen control tools developers <xen-tools.lists.xensource.com>
List-post: <mailto:xen-tools@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-tools>, <mailto:xen-tools-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-tools>, <mailto:xen-tools-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-tools-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)
Howdy,

I'm not sure everyone will agree that this is the best way to do it but it's so simple.

It's very useful to be able to parse the output of xm list from a shell script (especially for automated Xend tests). In a balloon test I've written, to get the reservation I have to do this:

res=$(echo $(xm list $VM | tail -n 1 | cut -c21-29))

Very ugly.

The following patch adds a --format option to xm list which let's you specify a python formatting string to use. Since we're using named keys, it ends up working very nicely. The above can be done with:

res=`xm list -f "%(mem)d" $VM`

Which is considerably nicer and more robust against slight changes in the display format.

I did not add docs for it because it seems like it should be reserved as an expert option only (since it relies on internal naming).

Signed-off-by: Anthony Liguori

Regards,

Anthony Liguori
# HG changeset patch
# User Anthony Liguori <aliguori@xxxxxxxxxx>
# Node ID 8937fe723eef24375a0eae488443e1c5948c1a7a
# Parent  fcc272a4f74bfc51f9068867de02a3525b3121d1
Add -f,--format=FMT parameter that uses FMT as the format instead of one of the 
stock formats.  This is really useful for writing any sort of scripting 
interface to xm since you can force the output to look like whatever is easiest 
to parse

diff -r fcc272a4f74b -r 8937fe723eef tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Wed Aug 10 16:34:38 2005
+++ b/tools/python/xen/xm/main.py       Wed Aug 10 22:08:12 2005
@@ -200,7 +200,8 @@
 def xm_list(args):
     use_long = 0
     show_vcpus = 0
-    (options, params) = getopt(args, 'lv', ['long','vcpus'])
+    format = None
+    (options, params) = getopt(args, 'lvf:', ['long','vcpus','format='])
     
     n = len(params)
     for (k, v) in options:
@@ -208,6 +209,8 @@
             use_long = 1
         if k in ['-v', '--vcpus']:
             show_vcpus = 1
+        if k in ['-f', '--format']:
+            format = v
 
     domsinfo = []
     from xen.xend.XendClient import server
@@ -225,6 +228,9 @@
         PrettyPrint.prettyprint(info)
     elif show_vcpus:
         xm_show_vcpus(domsinfo)
+    elif format:
+        for dominfo in domsinfo:
+            print format % dominfo
     else:
         xm_brief_list(domsinfo)
 
_______________________________________________
Xen-tools mailing list
Xen-tools@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-tools
<Prev in Thread] Current Thread [Next in Thread>