ia64/xen-unstable

changeset 13316:d898b5990ed7

merge
author Emmanuel Ackaouy <ack@xensource.com>
date Fri Jan 05 17:51:51 2007 +0000 (2007-01-05)
parents 23dcc167b97e cb1f71890c93
children b648a579b0b4
files
line diff
     1.1 --- a/tools/python/scripts/xapi.py	Fri Jan 05 17:51:07 2007 +0000
     1.2 +++ b/tools/python/scripts/xapi.py	Fri Jan 05 17:51:51 2007 +0000
     1.3 @@ -41,6 +41,7 @@ VBD_LIST_FORMAT = '%(name_label)-18s %(u
     1.4  COMMANDS = {
     1.5      'host-info': ('', 'Get Xen Host Info'),
     1.6      'host-set-name': ('', 'Set host name'),
     1.7 +    'pif-list': ('', 'List all PIFs'),
     1.8      'sr-list':   ('', 'List all SRs'),
     1.9      'vbd-list':  ('', 'List all VBDs'),
    1.10      'vbd-create': ('<domname> <pycfg> [opts]',
    1.11 @@ -63,6 +64,15 @@ COMMANDS = {
    1.12  }
    1.13  
    1.14  OPTIONS = {
    1.15 +    'sr-list': [(('-l', '--long'),
    1.16 +                 {'action':'store_true',
    1.17 +                  'help':'List all properties of SR'})
    1.18 +               ],
    1.19 +
    1.20 +    'vdi-list': [(('-l', '--long'),
    1.21 +                  {'action':'store_true',
    1.22 +                   'help':'List all properties of VDI'})
    1.23 +               ],        
    1.24      'vm-list': [(('-l', '--long'),
    1.25                   {'action':'store_true',
    1.26                    'help':'List all properties of VMs'})
    1.27 @@ -145,7 +155,7 @@ def execute(fn, *args):
    1.28  def _connect(*args):
    1.29      global _server, _session, _initialised
    1.30      if not _initialised:
    1.31 -        _server = ServerProxy('httpu:///var/run/xend/xmlrpc.sock')
    1.32 +        _server = ServerProxy('httpu:///var/run/xend/xen-api.sock')
    1.33          login = raw_input("Login: ")
    1.34          password = getpass()
    1.35          creds = (login, password)
    1.36 @@ -361,29 +371,53 @@ def xapi_vbd_list(*args):
    1.37          print VBD_LIST_FORMAT % vbd_struct
    1.38  
    1.39  def xapi_vdi_list(*args):
    1.40 +    opts, args = parse_args('vdi-list', args, set_defaults = True)
    1.41 +    is_long = opts and opts.long
    1.42 +
    1.43      server, session = _connect()
    1.44      vdis = execute(server.VDI.get_all, session)
    1.45  
    1.46 -    print VDI_LIST_FORMAT % {'name_label': 'VDI Label',
    1.47 -                             'uuid' : 'UUID',
    1.48 -                             'virtual_size': 'Sectors',
    1.49 -                             'sector_size': 'Sector Size'}
    1.50 -    
    1.51 -    for vdi in vdis:
    1.52 -        vdi_struct = execute(server.VDI.get_record, session, vdi)
    1.53 -        print VDI_LIST_FORMAT % vdi_struct
    1.54 +    if not is_long:
    1.55 +        print VDI_LIST_FORMAT % {'name_label': 'VDI Label',
    1.56 +                                 'uuid' : 'UUID',
    1.57 +                                 'virtual_size': 'Sectors',
    1.58 +                                 'sector_size': 'Sector Size'}
    1.59 +        
    1.60 +        for vdi in vdis:
    1.61 +            vdi_struct = execute(server.VDI.get_record, session, vdi)
    1.62 +            print VDI_LIST_FORMAT % vdi_struct
    1.63 +
    1.64 +    else:
    1.65 +
    1.66 +        for vdi in vdis:
    1.67 +            vdi_struct = execute(server.VDI.get_record, session, vdi)
    1.68 +            pprint(vdi_struct)
    1.69  
    1.70  def xapi_sr_list(*args):
    1.71 +    opts, args = parse_args('sr-list', args, set_defaults = True)
    1.72 +    is_long = opts and opts.long
    1.73 +    
    1.74      server, session = _connect()
    1.75      srs = execute(server.SR.get_all, session)
    1.76 -    print SR_LIST_FORMAT % {'name_label': 'SR Label',
    1.77 -                            'uuid' : 'UUID',
    1.78 -                            'physical_size': 'Size',
    1.79 -                            'type': 'Type'}
    1.80 -    for sr in srs:
    1.81 -        sr_struct = execute(server.SR.get_record, session, sr)
    1.82 -        sr_struct['physical_size'] = int(sr_struct['physical_size'])/MB
    1.83 -        print SR_LIST_FORMAT % sr_struct
    1.84 +    if not is_long:
    1.85 +        print SR_LIST_FORMAT % {'name_label': 'SR Label',
    1.86 +                                'uuid' : 'UUID',
    1.87 +                                'physical_size': 'Size (MB)',
    1.88 +                                'type': 'Type'}
    1.89 +        
    1.90 +        for sr in srs:
    1.91 +            sr_struct = execute(server.SR.get_record, session, sr)
    1.92 +            sr_struct['physical_size'] = int(sr_struct['physical_size'])/MB
    1.93 +            print SR_LIST_FORMAT % sr_struct
    1.94 +    else:
    1.95 +        for sr in srs:
    1.96 +            sr_struct = execute(server.SR.get_record, session, sr)        
    1.97 +            pprint(sr_struct)
    1.98 +
    1.99 +def xapi_sr_rename(*args):
   1.100 +    server, session = _connect()
   1.101 +    sr = execute(server.SR.get_by_name_label, session, args[0])
   1.102 +    execute(server.SR.set_name_label, session, sr[0], args[1])
   1.103  
   1.104  def xapi_vdi_create(*args):
   1.105      opts, args = parse_args('vdi-create', args)
   1.106 @@ -421,10 +455,11 @@ def xapi_vdi_rename(*args):
   1.107      if len(args) < 2:
   1.108          raise OptionError('Not enough arguments')
   1.109  
   1.110 -    vdi_uuid = args[0]
   1.111 +    vdi_uuid = execute(server.VDI.get_by_name_label, session, args[0])
   1.112      vdi_name = args[1]
   1.113 -    print 'Renaming VDI %s to %s' % (vdi_uuid, vdi_name)
   1.114 -    result = execute(server.VDI.set_name_label, session, vdi_uuid, vdi_name)
   1.115 +    
   1.116 +    print 'Renaming VDI %s to %s' % (vdi_uuid[0], vdi_name)
   1.117 +    result = execute(server.VDI.set_name_label, session, vdi_uuid[0], vdi_name)
   1.118      print 'Done.'
   1.119  
   1.120  
   1.121 @@ -448,6 +483,14 @@ def xapi_vtpm_create(*args):
   1.122      print "Has vtpm record '%s'" % vtpm_rec
   1.123  
   1.124  
   1.125 +def xapi_pif_list(*args):
   1.126 +    server, session = _connect()
   1.127 +    pif_uuids = execute(server.PIF.get_all, session)
   1.128 +    for pif_uuid in pif_uuids:
   1.129 +        pif = execute(server.PIF.get_record, session, pif_uuid)
   1.130 +        print pif
   1.131 +    
   1.132 +
   1.133  #
   1.134  # Command Line Utils
   1.135  #
   1.136 @@ -517,10 +560,12 @@ def usage(command = None, print_usage = 
   1.137              print
   1.138              print 'Subcommands:'
   1.139              print
   1.140 -        sorted_commands = sorted(COMMANDS.keys())
   1.141 -        for command  in sorted_commands:
   1.142 -            args, description = COMMANDS[command]
   1.143 -            print '%-16s  %-40s' % (command, description)
   1.144 +
   1.145 +        for func in sorted(globals().keys()):
   1.146 +            if func.startswith('xapi_'):
   1.147 +                command = func[5:].replace('_', '-')
   1.148 +                args, description = COMMANDS.get(command, ('', ''))
   1.149 +                print '%-16s  %-40s' % (command, description)
   1.150          print
   1.151      else:
   1.152          parse_args(command, ['-h'])
   1.153 @@ -549,7 +594,7 @@ def main(args):
   1.154      try:
   1.155          subcmd_func(*args[1:])
   1.156      except XenAPIError, e:
   1.157 -        print 'Error: %s' % str(e.args[1])
   1.158 +        print 'Error: %s' % str(e.args[0])
   1.159          sys.exit(2)
   1.160      except OptionError, e:
   1.161          print 'Error: %s' % e