All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: Stefan Berger <stefanb@us.ibm.com>
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH] Even prettier printing of xm	network-list/block-list/vtpm-list
Date: Fri, 10 Feb 2006 17:39:34 -0600	[thread overview]
Message-ID: <43ED2436.7060707@us.ibm.com> (raw)
In-Reply-To: <1139604485.4101.1.camel@941e-2.watson.ibm.com>

Thanks Stefan!

I had this on my TODO list too so I'm glad you got to it before I did :-)

Regards,

Anthony Liguori

Stefan Berger wrote:
> This patch now also supports the --long option.
>
> Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
>
>   
> ------------------------------------------------------------------------
>
> Index: xen/xen-unstable.hg/tools/python/xen/xm/main.py
> ===================================================================
> --- xen.orig/xen-unstable.hg/tools/python/xen/xm/main.py
> +++ xen/xen-unstable.hg/tools/python/xen/xm/main.py
> @@ -684,29 +684,127 @@ def xm_log(args):
>      from xen.xend.XendClient import server
>      print server.xend_node_log()
>  
> +def parse_dev_info(info):
> +    def get_info(n, t, d):
> +        i = 0
> +        while i < len(info):
> +            if (info[i][0] == n):
> +                return t(info[i][1])
> +            i = i + 1
> +        return t(d)
> +    return {
> +        #common
> +        'backend-id' : get_info('backend-id',   int,   -1),
> +        'handle'     : get_info('handle',       int,    0),
> +        'state'      : get_info('state',        int,   -1),
> +        'be-path'    : get_info('backend',      str,   '??'),
> +        'event-ch'   : get_info('event-channel',int,   -1),
> +        #network specific
> +        'virtual-device' : get_info('virtual-device', str, '??'),
> +        'tx-ring-ref': get_info('tx-ring-ref',  int,   -1),
> +        'rx-ring-ref': get_info('rx-ring-ref',  int,   -1),
> +        'mac'        : get_info('mac',          str,   '??'),
> +        #block-device specific
> +        'ring-ref'   : get_info('ring-ref',     int,   -1),
> +        }
> +
> +def has_long_option(args):
> +    use_long = 0
> +    try:
> +        (options, params) = getopt.gnu_getopt(args, 'l', ['long'])
> +    except getopt.GetoptError, opterr:
> +        err(opterr)
> +        sys.exit(1)
> +
> +    for (k, v) in options:
> +        if k in ['-l', '--long']:
> +            use_long = 1
> +    return (use_long, params)
> +
>  def xm_network_list(args):
> -    arg_check(args, "network-list", 1)
> -    dom = args[0]
> +    arg_check(args, "network-list", 1, 2)
> +
> +    (use_long, params) = has_long_option(args)
> +
> +    dom = params[0]
>      from xen.xend.XendClient import server
> -    for x in server.xend_domain_devices(dom, 'vif'):
> -        sxp.show(x)
> -        print
> +    if use_long:
> +        devs = server.xend_domain_devices(dom, 'vif')
> +        map(PrettyPrint.prettyprint, devs)
> +    else:
> +        hdr = 0
> +        for x in server.xend_domain_devices(dom, 'vif'):
> +            if hdr == 0:
> +                print 'Attached network devices:'
> +                print 'Idx BE     MAC Addr.     handle state evt-ch tx-/rx-ring-ref BE-path'
> +                hdr = 1
> +            ni = parse_dev_info(x[1])
> +            ni['idx'] = int(x[0])
> +            print ("%(idx)-3d "
> +                   "%(backend-id)-3d"
> +                   "%(mac)-17s    "
> +                   "%(handle)-3d   "
> +                   "%(state)-3d    "
> +                   "%(event-ch)-3d   "
> +                   "%(tx-ring-ref)-5d/%(rx-ring-ref)-5d   "
> +                   "%(be-path)-30s  "
> +                   % ni)
>  
>  def xm_block_list(args):
> -    arg_check(args, "block-list", 1)
> -    dom = args[0]
> +    arg_check(args, "block-list", 1, 2)
> +
> +    (use_long, params) = has_long_option(args)
> +
> +    dom = params[0]
>      from xen.xend.XendClient import server
> -    for x in server.xend_domain_devices(dom, 'vbd'):
> -        sxp.show(x)
> -        print
> +    if use_long:
> +        devs = server.xend_domain_devices(dom, 'vbd')
> +        map(PrettyPrint.prettyprint, devs)
> +    else:
> +        hdr = 0
> +        for x in server.xend_domain_devices(dom, 'vbd'):
> +            if hdr == 0:
> +                print 'Attached block devices:'
> +                print 'Vdev  BE handle state evt-ch ring-ref BE-path'
> +                hdr = 1
> +            ni = parse_dev_info(x[1])
> +            ni['idx'] = int(x[0])
> +            print ("%(idx)-3d    "
> +                   "%(backend-id)-3d  "
> +                   "%(handle)-3d   "
> +                   "%(state)-3d    "
> +                   "%(event-ch)-3d    "
> +                   "%(ring-ref)-5d "
> +                   "%(be-path)-30s  "
> +                   % ni)
>  
>  def xm_vtpm_list(args):
> -    arg_check(args, "vtpm-list", 1)
> -    dom = args[0]
> +    arg_check(args, "vtpm-list", 1, 2)
> +
> +    (use_long, params) = has_long_option(args)
> +
> +    dom = params[0]
>      from xen.xend.XendClient import server
> -    for x in server.xend_domain_devices(dom, 'vtpm'):
> -        sxp.show(x)
> -        print
> +    if use_long:
> +        devs = server.xend_domain_devices(dom, 'vtpm')
> +        map(PrettyPrint.prettyprint, devs)
> +    else:
> +        hdr = 0
> +        for x in server.xend_domain_devices(dom, 'vtpm'):
> +            if hdr == 0:
> +                print 'Attached virtual TPM devices:'
> +                print 'Idx  BE handle state evt-ch ring-ref BE-path'
> +                hdr = 1
> +            ni = parse_dev_info(x[1])
> +            ni['idx'] = int(x[0])
> +            print ("%(idx)-3d   "
> +                   "%(backend-id)-3d  "
> +                   "%(handle)-3d   "
> +                   "%(state)-3d    "
> +                   "%(event-ch)-3d    "
> +                   "%(ring-ref)-5d "
> +                   "%(be-path)-30s  "
> +                   % ni)
>  
>  def xm_block_attach(args):
>      arg_check(args, 'block-attach', 4, 5)
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>   

      reply	other threads:[~2006-02-10 23:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-10 20:48 [PATCH] Even prettier printing of xm network-list/block-list/vtpm-list Stefan Berger
2006-02-10 23:39 ` Anthony Liguori [this message]

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=43ED2436.7060707@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=stefanb@us.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.