ia64/xen-unstable

changeset 8888:34f6a1efe52d

This patch displays the network-list/block-list/vtpm-list using the 'xm'
command. It supports the '--long' option.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author emellor@leeni.uk.xensource.com
date Fri Feb 17 19:35:38 2006 +0100 (2006-02-17)
parents aeeeedc6c9b7
children eb6d2472ea1a
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Fri Feb 17 18:22:23 2006 +0100
     1.2 +++ b/tools/python/xen/xm/main.py	Fri Feb 17 19:35:38 2006 +0100
     1.3 @@ -90,18 +90,18 @@ block_detach_help = """block-detach  <Do
     1.4                                      where <DevId> may either be the device ID
     1.5                                      or the device name as mounted in the guest"""
     1.6  
     1.7 -block_list_help = "block-list <DomId>               List virtual block devices for a domain"
     1.8 +block_list_help = "block-list <DomId> [--long]      List virtual block devices for a domain"
     1.9  network_attach_help = """network-attach  <DomID> [script=<script>] [ip=<ip>] [mac=<mac>]
    1.10                             [bridge=<bridge>] [backend=<backDomID>]
    1.11                                      Create a new virtual network device """
    1.12  network_detach_help = """network-detach  <DomId> <DevId>  Destroy a domain's virtual network
    1.13                                      device, where <DevId> is the device ID."""
    1.14  
    1.15 -network_list_help = "network-list <DomId>             List virtual network interfaces for a domain"
    1.16 +network_list_help = "network-list <DomId> [--long]    List virtual network interfaces for a domain"
    1.17  vnet_list_help = "vnet-list [-l|--long]            list vnets"
    1.18  vnet_create_help = "vnet-create <config>             create a vnet from a config file"
    1.19  vnet_delete_help = "vnet-delete <vnetid>             delete a vnet"
    1.20 -vtpm_list_help = "vtpm-list <DomId>                list virtual TPM devices"
    1.21 +vtpm_list_help = "vtpm-list <DomId> [--long]       list virtual TPM devices"
    1.22  
    1.23  short_command_list = [
    1.24      "console",
    1.25 @@ -684,29 +684,133 @@ def xm_log(args):
    1.26      from xen.xend.XendClient import server
    1.27      print server.xend_node_log()
    1.28  
    1.29 +def parse_dev_info(info):
    1.30 +    def get_info(n, t, d):
    1.31 +        i = 0
    1.32 +        while i < len(info):
    1.33 +            if (info[i][0] == n):
    1.34 +                return t(info[i][1])
    1.35 +            i = i + 1
    1.36 +        return t(d)
    1.37 +    return {
    1.38 +        #common
    1.39 +        'backend-id' : get_info('backend-id',   int,   -1),
    1.40 +        'handle'     : get_info('handle',       int,    0),
    1.41 +        'state'      : get_info('state',        int,   -1),
    1.42 +        'be-path'    : get_info('backend',      str,   '??'),
    1.43 +        'event-ch'   : get_info('event-channel',int,   -1),
    1.44 +        #network specific
    1.45 +        'virtual-device' : get_info('virtual-device', str, '??'),
    1.46 +        'tx-ring-ref': get_info('tx-ring-ref',  int,   -1),
    1.47 +        'rx-ring-ref': get_info('rx-ring-ref',  int,   -1),
    1.48 +        'mac'        : get_info('mac',          str,   '??'),
    1.49 +        #block-device specific
    1.50 +        'ring-ref'   : get_info('ring-ref',     int,   -1),
    1.51 +        }
    1.52 +
    1.53 +def has_long_option(args):
    1.54 +    use_long = 0
    1.55 +    try:
    1.56 +        (options, params) = getopt.gnu_getopt(args, 'l', ['long'])
    1.57 +    except getopt.GetoptError, opterr:
    1.58 +        err(opterr)
    1.59 +        sys.exit(1)
    1.60 +
    1.61 +    for (k, v) in options:
    1.62 +        if k in ['-l', '--long']:
    1.63 +            use_long = 1
    1.64 +    return (use_long, params)
    1.65 +
    1.66  def xm_network_list(args):
    1.67 -    arg_check(args, "network-list", 1)
    1.68 -    dom = args[0]
    1.69 +    arg_check(args, "network-list", 1, 2)
    1.70 +
    1.71 +    (use_long, params) = has_long_option(args)
    1.72 +
    1.73 +    if len(params) == 0:
    1.74 +        print 'No domain parameter given'
    1.75 +        sys.exit(1)
    1.76 +    dom = params[0]
    1.77      from xen.xend.XendClient import server
    1.78 -    for x in server.xend_domain_devices(dom, 'vif'):
    1.79 -        sxp.show(x)
    1.80 -        print
    1.81 +    if use_long:
    1.82 +        devs = server.xend_domain_devices(dom, 'vif')
    1.83 +        map(PrettyPrint.prettyprint, devs)
    1.84 +    else:
    1.85 +        hdr = 0
    1.86 +        for x in server.xend_domain_devices(dom, 'vif'):
    1.87 +            if hdr == 0:
    1.88 +                print 'Idx BE     MAC Addr.     handle state evt-ch tx-/rx-ring-ref BE-path'
    1.89 +                hdr = 1
    1.90 +            ni = parse_dev_info(x[1])
    1.91 +            ni['idx'] = int(x[0])
    1.92 +            print ("%(idx)-3d "
    1.93 +                   "%(backend-id)-3d"
    1.94 +                   "%(mac)-17s    "
    1.95 +                   "%(handle)-3d   "
    1.96 +                   "%(state)-3d    "
    1.97 +                   "%(event-ch)-3d   "
    1.98 +                   "%(tx-ring-ref)-5d/%(rx-ring-ref)-5d   "
    1.99 +                   "%(be-path)-30s  "
   1.100 +                   % ni)
   1.101  
   1.102  def xm_block_list(args):
   1.103 -    arg_check(args, "block-list", 1)
   1.104 -    dom = args[0]
   1.105 +    arg_check(args, "block-list", 1, 2)
   1.106 +
   1.107 +    (use_long, params) = has_long_option(args)
   1.108 +
   1.109 +    if len(params) == 0:
   1.110 +        print 'No domain parameter given'
   1.111 +        sys.exit(1)
   1.112 +    dom = params[0]
   1.113      from xen.xend.XendClient import server
   1.114 -    for x in server.xend_domain_devices(dom, 'vbd'):
   1.115 -        sxp.show(x)
   1.116 -        print
   1.117 +    if use_long:
   1.118 +        devs = server.xend_domain_devices(dom, 'vbd')
   1.119 +        map(PrettyPrint.prettyprint, devs)
   1.120 +    else:
   1.121 +        hdr = 0
   1.122 +        for x in server.xend_domain_devices(dom, 'vbd'):
   1.123 +            if hdr == 0:
   1.124 +                print 'Vdev  BE handle state evt-ch ring-ref BE-path'
   1.125 +                hdr = 1
   1.126 +            ni = parse_dev_info(x[1])
   1.127 +            ni['idx'] = int(x[0])
   1.128 +            print ("%(idx)-3d    "
   1.129 +                   "%(backend-id)-3d  "
   1.130 +                   "%(handle)-3d   "
   1.131 +                   "%(state)-3d    "
   1.132 +                   "%(event-ch)-3d    "
   1.133 +                   "%(ring-ref)-5d "
   1.134 +                   "%(be-path)-30s  "
   1.135 +                   % ni)
   1.136  
   1.137  def xm_vtpm_list(args):
   1.138 -    arg_check(args, "vtpm-list", 1)
   1.139 -    dom = args[0]
   1.140 +    arg_check(args, "vtpm-list", 1, 2)
   1.141 +
   1.142 +    (use_long, params) = has_long_option(args)
   1.143 +
   1.144 +    if len(params) == 0:
   1.145 +        print 'No domain parameter given'
   1.146 +        sys.exit(1)
   1.147 +    dom = params[0]
   1.148      from xen.xend.XendClient import server
   1.149 -    for x in server.xend_domain_devices(dom, 'vtpm'):
   1.150 -        sxp.show(x)
   1.151 -        print
   1.152 +    if use_long:
   1.153 +        devs = server.xend_domain_devices(dom, 'vtpm')
   1.154 +        map(PrettyPrint.prettyprint, devs)
   1.155 +    else:
   1.156 +        hdr = 0
   1.157 +        for x in server.xend_domain_devices(dom, 'vtpm'):
   1.158 +            if hdr == 0:
   1.159 +                print 'Idx  BE handle state evt-ch ring-ref BE-path'
   1.160 +                hdr = 1
   1.161 +            ni = parse_dev_info(x[1])
   1.162 +            ni['idx'] = int(x[0])
   1.163 +            print ("%(idx)-3d   "
   1.164 +                   "%(backend-id)-3d  "
   1.165 +                   "%(handle)-3d   "
   1.166 +                   "%(state)-3d    "
   1.167 +                   "%(event-ch)-3d    "
   1.168 +                   "%(ring-ref)-5d "
   1.169 +                   "%(be-path)-30s  "
   1.170 +                   % ni)
   1.171  
   1.172  def xm_block_attach(args):
   1.173      arg_check(args, 'block-attach', 4, 5)