ia64/xen-unstable

changeset 12112:029e04982e94

[XENAPI] Support for VBD/VIF info listing in vm-list --long

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Fri Oct 06 16:30:35 2006 +0100 (2006-10-06)
parents c88a78f8bed9
children c21f4949a746
files tools/python/scripts/README tools/python/scripts/xapi.py
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/python/scripts/README	Fri Oct 06 16:30:35 2006 +0100
     1.3 @@ -0,0 +1,49 @@
     1.4 +Xen API Test
     1.5 +============
     1.6 +
     1.7 +xapi.py is a simple command line tool to test the functionality of a
     1.8 +domain lifecycle supporting, Xen API talking version of Xend.
     1.9 +
    1.10 +Creating a VM is slightly more work under the Xen API. The differences
    1.11 +with this and xm is:
    1.12 +
    1.13 +1. None of the devices are created during vm-create. You must use
    1.14 +   vbd-create and vif-create to attach a new device to the VM.
    1.15 +
    1.16 +2. VM's that are created using vm-create will not start by
    1.17 +   default. You must use vm-start to "start" the domain.
    1.18 +
    1.19 +3. VM's that are created using vm-create will not be removed on
    1.20 +   shutdown. You must remove it using vm-delete.
    1.21 +
    1.22 +Example Configuration Files
    1.23 +---------------------------
    1.24 +
    1.25 +xapi.py uses a simple python configuration file similar to xm in the
    1.26 +face of the lack of any other reasonable format.
    1.27 +
    1.28 +All the fields are directly mapped to the arguments that are in the
    1.29 +Xen API constructore for the respective classes.
    1.30 +
    1.31 +xapi.domcfg.py: example configuration for a paravirtualised domain.
    1.32 +xapi.vbdcfg.py: example configuration for a file based block device.
    1.33 +xapi.vifcfg.py: example configuration for a simple bridged network
    1.34 +                device.
    1.35 +
    1.36 +Example Session
    1.37 +---------------
    1.38 +
    1.39 +xapi.py vm-list
    1.40 +xapi.py vm-create xapi.domcfg.py
    1.41 +xapi.py vbd-create <DomainName> xapi.vbdcfg.py
    1.42 +xapi.py vif-create <DomainName> xapi.vifcfg.py
    1.43 +
    1.44 +Notes
    1.45 +-----
    1.46 +
    1.47 +Currently lacking:
    1.48 +
    1.49 +1. Any real authentication. XendAuthSessions need to be filled in with
    1.50 +   a proper authentication implementation either using PAM or other
    1.51 +   means.
    1.52 +
     2.1 --- a/tools/python/scripts/xapi.py	Fri Oct 06 16:27:06 2006 +0100
     2.2 +++ b/tools/python/scripts/xapi.py	Fri Oct 06 16:30:35 2006 +0100
     2.3 @@ -36,7 +36,7 @@ COMMANDS = {
     2.4      'vm-delete': ('<domname>', 'Delete VM'),
     2.5      
     2.6      'vm-destroy': ('<name>', 'Hard shutdown a VM with name'),
     2.7 -    'vm-list':   ('', 'List all domains.'),
     2.8 +    'vm-list':   ('[--long]', 'List all domains.'),
     2.9      'vm-name':   ('<uuid>', 'Name of UUID.'),
    2.10      'vm-shutdown': ('<name>', 'Shutdown VM with name'),
    2.11      'vm-start':  ('<name>', 'Start VM with name'),
    2.12 @@ -62,13 +62,15 @@ class XenAPIError(Exception):
    2.13  #
    2.14  
    2.15  def parse_args(cmd_name, args):
    2.16 +    argstring, desc = COMMANDS[cmd_name]
    2.17 +    parser = OptionParser(usage = 'xapi %s %s' % (cmd_name, argstring),
    2.18 +                          description = desc)
    2.19      if cmd_name in OPTIONS:
    2.20 -        parser = OptionParser()
    2.21          for optargs, optkwds in OPTIONS[cmd_name]:
    2.22              parser.add_option(*optargs, **optkwds)
    2.23 -        (opts, extraargs) = parser.parse_args(list(args))
    2.24 -        return opts, extraargs
    2.25 -    return None, []
    2.26 +            
    2.27 +    (opts, extraargs) = parser.parse_args(list(args))
    2.28 +    return opts, extraargs
    2.29  
    2.30  def execute(fn, *args):
    2.31      result = fn(*args)
    2.32 @@ -141,6 +143,18 @@ def xapi_vm_list(*args):
    2.33      for uuid in vm_uuids:
    2.34          vm_info = execute(server.VM.get_record, session, uuid)
    2.35          if is_long:
    2.36 +            vbds = vm_info['vbds']
    2.37 +            vifs = vm_info['vifs']
    2.38 +            vif_infos = []
    2.39 +            vbd_infos = []
    2.40 +            for vbd in vbds:
    2.41 +                vbd_info = execute(server.VBD.get_record, session, vbd)
    2.42 +                vbd_infos.append(vbd_info)
    2.43 +            for vif in vifs:
    2.44 +                vif_info = execute(server.VIF.get_record, session, vif)
    2.45 +                vif_infos.append(vif_info)
    2.46 +            vm_info['vbds'] = vbd_infos
    2.47 +            vm_info['vifs'] = vif_infos
    2.48              pprint(vm_info)
    2.49          else:
    2.50              print VM_LIST_FORMAT % _stringify(vm_info)
    2.51 @@ -234,15 +248,18 @@ def xapi_vif_create(*args):
    2.52  #
    2.53  
    2.54  def usage(command = None):
    2.55 -    print 'Usage: xapi <subcommand> [options] [args]'
    2.56 -    print
    2.57 -    print 'Subcommands:'
    2.58 -    print
    2.59 -    sorted_commands = sorted(COMMANDS.keys())
    2.60 -    for command  in sorted_commands:
    2.61 -        args, description = COMMANDS[command]
    2.62 -        print '%-16s  %-40s' % (command, description)
    2.63 -    print
    2.64 +    if not command:
    2.65 +        print 'Usage: xapi <subcommand> [options] [args]'
    2.66 +        print
    2.67 +        print 'Subcommands:'
    2.68 +        print
    2.69 +        sorted_commands = sorted(COMMANDS.keys())
    2.70 +        for command  in sorted_commands:
    2.71 +            args, description = COMMANDS[command]
    2.72 +            print '%-16s  %-40s' % (command, description)
    2.73 +        print
    2.74 +    else:
    2.75 +        parse_args(command, ['-h'])
    2.76  
    2.77  def main(args):
    2.78  
    2.79 @@ -267,7 +284,7 @@ def main(args):
    2.80          subcmd_func(*args[1:])
    2.81      except XenAPIError, e:
    2.82          print 'Error: %s' % str(e.args[1])
    2.83 -        sys.exit(1)
    2.84 +        sys.exit(2)
    2.85  
    2.86      sys.exit(0)
    2.87