ia64/xen-unstable

changeset 14118:02f32a4df8db

Added tab completion for methods and object references to xm shell.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Sun Feb 25 21:52:54 2007 +0000 (2007-02-25)
parents f3aa6e34aeb1
children d81c0b55e248
files tools/python/xen/xend/XendAPI.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Sun Feb 25 17:20:51 2007 +0000
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Sun Feb 25 21:52:54 2007 +0000
     1.3 @@ -2138,7 +2138,15 @@ class XendAPI(object):
     1.4      def debug_get_record(self, session, debug_ref):
     1.5          return xen_api_success({'uuid': debug_ref})
     1.6  
     1.7 -             
     1.8 +
     1.9 +    def list_all_methods(self, _):
    1.10 +        def _funcs():
    1.11 +            return [getattr(XendAPI, x) for x in XendAPI.__dict__]
    1.12 +
    1.13 +        return xen_api_success([x.api for x in _funcs()
    1.14 +                                if hasattr(x, 'api')])
    1.15 +    list_all_methods.api = '_UNSUPPORTED_list_all_methods'
    1.16 +
    1.17  
    1.18  class XendAPIAsyncProxy:
    1.19      """ A redirector for Async.Class.function calls to XendAPI
     2.1 --- a/tools/python/xen/xm/main.py	Sun Feb 25 17:20:51 2007 +0000
     2.2 +++ b/tools/python/xen/xm/main.py	Sun Feb 25 21:52:54 2007 +0000
     2.3 @@ -549,6 +549,10 @@ class Shell(cmd.Cmd):
     2.4      def __init__(self):
     2.5          cmd.Cmd.__init__(self)
     2.6          self.prompt = "xm> "
     2.7 +        if serverType == SERVER_XEN_API:
     2.8 +            res = server.xenapi._UNSUPPORTED_list_all_methods()
     2.9 +            for f in res:
    2.10 +                setattr(Shell, 'do_' + f, self.default)
    2.11  
    2.12      def default(self, line):
    2.13          words = shlex.split(line)
    2.14 @@ -568,6 +572,16 @@ class Shell(cmd.Cmd):
    2.15                  print '*** Unknown command: %s' % words[0]
    2.16          return False
    2.17  
    2.18 +    def completedefault(self, text, line, begidx, endidx):
    2.19 +        cmd = line.split(' ')[0]
    2.20 +        clas, func = cmd.split('.')
    2.21 +        if begidx != len(cmd) + 1 or \
    2.22 +           func.startswith('get_by_') or \
    2.23 +           func == 'get_all':
    2.24 +            return []
    2.25 +        uuids = server.xenapi_request('%s.get_all' % clas, ())
    2.26 +        return [u + " " for u in uuids if u.startswith(text)]
    2.27 +
    2.28      def emptyline(self):
    2.29          pass
    2.30