ia64/xen-unstable

changeset 19676:02cee9e4363e

xm: Unify the output of pci-list

This is another attempt at having pci-list produce consistent output.
Without this change there differences in the output of both vslots
and domain occur for domains that have never been started and domains
that have been started.

In order to address this I have taken the approach of
using integers where possible and explicitly formating them,
rather than relying on string representations that are present in
data structures.

I have also re-used the common part of the format, to try
and mitigate. the possibility of future inconsistencies there.

This patch also:
* Removes trailing whitespace
* Removes unnecessary brackets and whitespace from print invocations
* Prints the header outside of the loop to avoid having
to maintain a state variable

Signed-off-by: Simon Horman <horms@verge.net.au>
author Keir Fraser <keir.fraser@citrix.com>
date Fri May 29 09:27:31 2009 +0100 (2009-05-29)
parents ae5bd69227d1
children 50e048b77ad1
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Fri May 29 09:26:49 2009 +0100
     1.2 +++ b/tools/python/xen/xm/main.py	Fri May 29 09:27:31 2009 +0100
     1.3 @@ -2183,43 +2183,45 @@ def xm_pci_list(args):
     1.4              ppci_ref = server.xenapi.DPCI.get_PPCI(dpci_ref)
     1.5              ppci_record = server.xenapi.PPCI.get_record(ppci_ref)
     1.6              dev = {
     1.7 -                "domain":   "0x%04x" % int(ppci_record["domain"]),
     1.8 -                "bus":      "0x%02x" % int(ppci_record["bus"]),
     1.9 -                "slot":     "0x%02x" % int(ppci_record["slot"]),
    1.10 -                "func":     "0x%01x" % int(ppci_record["func"]),
    1.11 -                "vslot":    "0x%02x" % \
    1.12 -                            int(server.xenapi.DPCI.get_hotplug_slot(dpci_ref))
    1.13 +                "domain":   int(ppci_record["domain"]),
    1.14 +                "bus":      int(ppci_record["bus"]),
    1.15 +                "slot":     int(ppci_record["slot"]),
    1.16 +                "func":     int(ppci_record["func"]),
    1.17 +                "vslot":    int(server.xenapi.DPCI.get_hotplug_slot(dpci_ref))
    1.18              }
    1.19              devs.append(dev)
    1.20  
    1.21      else:
    1.22 -        devs = server.xend.domain.getDeviceSxprs(dom, 'pci')
    1.23 +        for x in server.xend.domain.getDeviceSxprs(dom, 'pci'):
    1.24 +            dev = {
    1.25 +                "domain":   int(x["domain"], 16),
    1.26 +                "bus":      int(x["bus"], 16),
    1.27 +                "slot":     int(x["slot"], 16),
    1.28 +                "func":     int(x["func"], 16),
    1.29 +                "vslot":    int(assigned_or_requested_vslot(x), 16)
    1.30 +            }
    1.31 +            devs.append(dev)
    1.32  
    1.33      if len(devs) == 0:
    1.34          return
    1.35  
    1.36      has_vslot = False
    1.37      for x in devs:
    1.38 -        vslot = assigned_or_requested_vslot(x)
    1.39 -        if int(vslot, 16) == AUTO_PHP_SLOT:
    1.40 -            x['vslot'] = '-'
    1.41 +        if x['vslot'] == AUTO_PHP_SLOT:
    1.42 +            x['show_vslot'] = '-'
    1.43          else:
    1.44 -            x['vslot'] = vslot
    1.45 +            x['show_vslot'] = "0x%02x" % x['vslot']
    1.46              has_vslot = True
    1.47  
    1.48 +    hdr_str = 'domain bus  slot func'
    1.49 +    fmt_str = '0x%(domain)04x 0x%(bus)02x 0x%(slot)02x 0x%(func)x'
    1.50      if has_vslot:
    1.51 -        hdr_str = 'VSlt domain   bus   slot   func'
    1.52 -        fmt_str =  "%(vslot)-4s %(domain)-6s   %(bus)-4s  %(slot)-4s   %(func)-3s    "
    1.53 -    else:
    1.54 -        hdr_str = 'domain   bus   slot   func'
    1.55 -        fmt_str =  "%(domain)-6s   %(bus)-4s  %(slot)-4s   %(func)-3s    "
    1.56 -    hdr = 0
    1.57 -
    1.58 +        hdr_str = 'VSlt ' + hdr_str
    1.59 +        fmt_str = '%(show_vslot)-4s ' + fmt_str
    1.60 +
    1.61 +    print hdr_str
    1.62      for x in devs:
    1.63 -        if hdr == 0:
    1.64 -            print (hdr_str)
    1.65 -            hdr = 1
    1.66 -        print ( fmt_str % x )
    1.67 +        print fmt_str % x
    1.68  
    1.69  
    1.70  def parse_pci_info(info):