[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] [XEND] Add debug class to Xen API plus non-standard debug.wait().
# HG changeset patch # User Alastair Tse <atse@xxxxxxxxxxxxx> # Date 1169654349 0 # Node ID a94363b85e192540bf94c4da60adcf4176ecbdd0 # Parent da23e1b616b0a2abe46290c3ed8e18e8c95a25ab [XEND] Add debug class to Xen API plus non-standard debug.wait(). debug.wait(seconds) will just do a time.sleep() so the task progress support can be tested. Signed-off-by: Alastair Tse <atse@xxxxxxxxxxxxx> --- tools/python/scripts/xapi.py | 2 - tools/python/xen/xend/XendAPI.py | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff -r da23e1b616b0 -r a94363b85e19 tools/python/scripts/xapi.py --- a/tools/python/scripts/xapi.py Wed Jan 24 15:57:10 2007 +0000 +++ b/tools/python/scripts/xapi.py Wed Jan 24 15:59:09 2007 +0000 @@ -662,7 +662,7 @@ def xapi_debug_wait(args, async = False) if len(args) > 0: secs = int(args[0]) server, session = connect() - task_uuid = execute(server, 'Debug.wait', (session, secs), async=async) + task_uuid = execute(server, 'debug.wait', (session, secs), async=async) print 'Task UUID: %s' % task_uuid # diff -r da23e1b616b0 -r a94363b85e19 tools/python/xen/xend/XendAPI.py --- a/tools/python/xen/xend/XendAPI.py Wed Jan 24 15:57:10 2007 +0000 +++ b/tools/python/xen/xend/XendAPI.py Wed Jan 24 15:59:09 2007 +0000 @@ -260,6 +260,17 @@ def valid_task(func): _check_ref(XendTaskManager.get_task, 'TASK_HANDLE_INVALID', func, *args, **kwargs) +def valid_debug(func): + """Decorator to verify if task_ref is valid before calling + method. + + @param func: function with params: (self, session, task_ref) + @rtype: callable object + """ + return lambda *args, **kwargs: \ + _check_ref(lambda r: r in XendAPI._debug, + 'TASK_HANDLE_INVALID', func, *args, **kwargs) + # ----------------------------- # Bridge to Legacy XM API calls # ----------------------------- @@ -300,6 +311,7 @@ class XendAPI(object): __decorated__ = False __init_lock__ = threading.Lock() + _debug = {} def __new__(cls, *args, **kwds): """ Override __new__ to decorate the class only once. @@ -337,6 +349,7 @@ class XendAPI(object): 'SR' : valid_sr, 'PIF' : valid_pif, 'task' : valid_task, + 'debug' : valid_debug, } # Cheat methods @@ -1866,6 +1879,40 @@ class XendAPI(object): return xen_api_success_void() + # Xen API: Class debug + # ---------------------------------------------------------------- + + debug_methods = [('destroy', None), + ('get_record', 'debug')] + debug_funcs = [('wait', None), + ('return_failure', None)] + + def debug_wait(self, session, wait_secs): + import time + prog_units = 100/float(wait_secs) + for i in range(int(wait_secs)): + XendTask.log_progress(prog_units * i, prog_units * (i + 1), + time.sleep, 1) + return xen_api_success_void() + + + def debug_return_failure(self, session): + return xen_api_error(['DEBUG_FAIL', session]) + + def debug_create(self, session): + debug_uuid = uuid.createString() + self._debug[debug_uuid] = None + return xen_api_success(debug_uuid) + + def debug_destroy(self, session, debug_ref): + del self._debug[debug_ref] + return xen_api_success_void() + + def debug_get_record(self, session, debug_ref): + return xen_api_success({'uuid': debug_ref}) + + + class XendAPIAsyncProxy: """ A redirector for Async.Class.function calls to XendAPI but wraps the call for use with the XendTaskManager. _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |