ia64/xen-unstable

changeset 10530:e236794915cc

[TOOLS] Fix cm argument processing some more:
1. Remove has_long_option() and add arg_check_for_resource_list()
instead.
2. 'args' tells 'options' from 'params' by using gnu_getopt().
3. 'options' checks whether -l/--long option is specified.
4. If 'params' not given, print out 'No domain parameter given'
and usage.
5. If 'params' given multiple domains, print out
'No multiple domain parameters allowed' and usage.
6. Then it displays the resources as usual.

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Jun 27 11:05:39 2006 +0100 (2006-06-27)
parents 6604238412be
children 533b0709a68f
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Tue Jun 27 10:44:33 2006 +0100
     1.2 +++ b/tools/python/xen/xm/main.py	Tue Jun 27 11:05:39 2006 +0100
     1.3 @@ -887,7 +887,7 @@ def parse_dev_info(info):
     1.4          'ring-ref'   : get_info('ring-ref',     int,   -1),
     1.5          }
     1.6  
     1.7 -def has_long_option(args):
     1.8 +def arg_check_for_resource_list(args, name):
     1.9      use_long = 0
    1.10      try:
    1.11          (options, params) = getopt.gnu_getopt(args, 'l', ['long'])
    1.12 @@ -898,16 +898,19 @@ def has_long_option(args):
    1.13      for (k, v) in options:
    1.14          if k in ['-l', '--long']:
    1.15              use_long = 1
    1.16 +
    1.17 +    if len(params) == 0:
    1.18 +        print 'No domain parameter given'
    1.19 +        usage(name)
    1.20 +    if len(params) > 1:
    1.21 +        print 'No multiple domain parameters allowed'
    1.22 +        usage(name)
    1.23 +    
    1.24      return (use_long, params)
    1.25  
    1.26  def xm_network_list(args):
    1.27 -    arg_check(args, "network-list", 1, 2)
    1.28 +    (use_long, params) = arg_check_for_resource_list(args, "network-list")
    1.29  
    1.30 -    (use_long, params) = has_long_option(args)
    1.31 -
    1.32 -    if len(params) == 0:
    1.33 -        print 'No domain parameter given'
    1.34 -        sys.exit(1)
    1.35      dom = params[0]
    1.36      if use_long:
    1.37          devs = server.xend.domain.getDeviceSxprs(dom, 'vif')
    1.38 @@ -931,13 +934,8 @@ def xm_network_list(args):
    1.39                     % ni)
    1.40  
    1.41  def xm_block_list(args):
    1.42 -    arg_check(args, "block-list", 1, 2)
    1.43 +    (use_long, params) = arg_check_for_resource_list(args, "block-list")
    1.44  
    1.45 -    (use_long, params) = has_long_option(args)
    1.46 -
    1.47 -    if len(params) == 0:
    1.48 -        print 'No domain parameter given'
    1.49 -        sys.exit(1)
    1.50      dom = params[0]
    1.51      if use_long:
    1.52          devs = server.xend.domain.getDeviceSxprs(dom, 'vbd')
    1.53 @@ -960,13 +958,8 @@ def xm_block_list(args):
    1.54                     % ni)
    1.55  
    1.56  def xm_vtpm_list(args):
    1.57 -    arg_check(args, "vtpm-list", 1, 2)
    1.58 +    (use_long, params) = arg_check_for_resource_list(args, "vtpm-list")
    1.59  
    1.60 -    (use_long, params) = has_long_option(args)
    1.61 -
    1.62 -    if len(params) == 0:
    1.63 -        print 'No domain parameter given'
    1.64 -        sys.exit(1)
    1.65      dom = params[0]
    1.66      if use_long:
    1.67          devs = server.xend.domain.getDeviceSxprs(dom, 'vtpm')