mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
Added tab completion for methods and object references to xm shell.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
1 parent
5baa3458c5
commit
bc26603f4b
2 files changed
+23
-1
No files matched your search
@@ -2138,7 +2138,15 @@ class XendAPI(object):
|
||||
def debug_get_record(self, session, debug_ref):
|
||||
return xen_api_success({'uuid': debug_ref})
|
||||
|
||||
|
||||
|
||||
def list_all_methods(self, _):
|
||||
def _funcs():
|
||||
return [getattr(XendAPI, x) for x in XendAPI.__dict__]
|
||||
|
||||
return xen_api_success([x.api for x in _funcs()
|
||||
if hasattr(x, 'api')])
|
||||
list_all_methods.api = '_UNSUPPORTED_list_all_methods'
|
||||
|
||||
|
||||
class XendAPIAsyncProxy:
|
||||
""" A redirector for Async.Class.function calls to XendAPI
|
||||
|
||||
@@ -549,6 +549,10 @@ class Shell(cmd.Cmd):
|
||||
def __init__(self):
|
||||
cmd.Cmd.__init__(self)
|
||||
self.prompt = "xm> "
|
||||
if serverType == SERVER_XEN_API:
|
||||
res = server.xenapi._UNSUPPORTED_list_all_methods()
|
||||
for f in res:
|
||||
setattr(Shell, 'do_' + f, self.default)
|
||||
|
||||
def default(self, line):
|
||||
words = shlex.split(line)
|
||||
@@ -568,6 +572,16 @@ class Shell(cmd.Cmd):
|
||||
print '*** Unknown command: %s' % words[0]
|
||||
return False
|
||||
|
||||
def completedefault(self, text, line, begidx, endidx):
|
||||
cmd = line.split(' ')[0]
|
||||
clas, func = cmd.split('.')
|
||||
if begidx != len(cmd) + 1 or \
|
||||
func.startswith('get_by_') or \
|
||||
func == 'get_all':
|
||||
return []
|
||||
uuids = server.xenapi_request('%s.get_all' % clas, ())
|
||||
return [u + " " for u in uuids if u.startswith(text)]
|
||||
|
||||
def emptyline(self):
|
||||
pass
|
||||
|
||||
|
||||