direct-io.hg
changeset 13593:a94363b85e19
[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@xensource.com>
debug.wait(seconds) will just do a time.sleep() so the task progress
support can be tested.
Signed-off-by: Alastair Tse <atse@xensource.com>
author | Alastair Tse <atse@xensource.com> |
---|---|
date | Wed Jan 24 15:59:09 2007 +0000 (2007-01-24) |
parents | da23e1b616b0 |
children | 30af6cfdb05c |
files | tools/python/scripts/xapi.py tools/python/xen/xend/XendAPI.py |
line diff
1.1 --- a/tools/python/scripts/xapi.py Wed Jan 24 15:57:10 2007 +0000 1.2 +++ b/tools/python/scripts/xapi.py Wed Jan 24 15:59:09 2007 +0000 1.3 @@ -662,7 +662,7 @@ def xapi_debug_wait(args, async = False) 1.4 if len(args) > 0: 1.5 secs = int(args[0]) 1.6 server, session = connect() 1.7 - task_uuid = execute(server, 'Debug.wait', (session, secs), async=async) 1.8 + task_uuid = execute(server, 'debug.wait', (session, secs), async=async) 1.9 print 'Task UUID: %s' % task_uuid 1.10 1.11 #
2.1 --- a/tools/python/xen/xend/XendAPI.py Wed Jan 24 15:57:10 2007 +0000 2.2 +++ b/tools/python/xen/xend/XendAPI.py Wed Jan 24 15:59:09 2007 +0000 2.3 @@ -260,6 +260,17 @@ def valid_task(func): 2.4 _check_ref(XendTaskManager.get_task, 2.5 'TASK_HANDLE_INVALID', func, *args, **kwargs) 2.6 2.7 +def valid_debug(func): 2.8 + """Decorator to verify if task_ref is valid before calling 2.9 + method. 2.10 + 2.11 + @param func: function with params: (self, session, task_ref) 2.12 + @rtype: callable object 2.13 + """ 2.14 + return lambda *args, **kwargs: \ 2.15 + _check_ref(lambda r: r in XendAPI._debug, 2.16 + 'TASK_HANDLE_INVALID', func, *args, **kwargs) 2.17 + 2.18 # ----------------------------- 2.19 # Bridge to Legacy XM API calls 2.20 # ----------------------------- 2.21 @@ -300,6 +311,7 @@ class XendAPI(object): 2.22 2.23 __decorated__ = False 2.24 __init_lock__ = threading.Lock() 2.25 + _debug = {} 2.26 2.27 def __new__(cls, *args, **kwds): 2.28 """ Override __new__ to decorate the class only once. 2.29 @@ -337,6 +349,7 @@ class XendAPI(object): 2.30 'SR' : valid_sr, 2.31 'PIF' : valid_pif, 2.32 'task' : valid_task, 2.33 + 'debug' : valid_debug, 2.34 } 2.35 2.36 # Cheat methods 2.37 @@ -1866,6 +1879,40 @@ class XendAPI(object): 2.38 return xen_api_success_void() 2.39 2.40 2.41 + # Xen API: Class debug 2.42 + # ---------------------------------------------------------------- 2.43 + 2.44 + debug_methods = [('destroy', None), 2.45 + ('get_record', 'debug')] 2.46 + debug_funcs = [('wait', None), 2.47 + ('return_failure', None)] 2.48 + 2.49 + def debug_wait(self, session, wait_secs): 2.50 + import time 2.51 + prog_units = 100/float(wait_secs) 2.52 + for i in range(int(wait_secs)): 2.53 + XendTask.log_progress(prog_units * i, prog_units * (i + 1), 2.54 + time.sleep, 1) 2.55 + return xen_api_success_void() 2.56 + 2.57 + 2.58 + def debug_return_failure(self, session): 2.59 + return xen_api_error(['DEBUG_FAIL', session]) 2.60 + 2.61 + def debug_create(self, session): 2.62 + debug_uuid = uuid.createString() 2.63 + self._debug[debug_uuid] = None 2.64 + return xen_api_success(debug_uuid) 2.65 + 2.66 + def debug_destroy(self, session, debug_ref): 2.67 + del self._debug[debug_ref] 2.68 + return xen_api_success_void() 2.69 + 2.70 + def debug_get_record(self, session, debug_ref): 2.71 + return xen_api_success({'uuid': debug_ref}) 2.72 + 2.73 + 2.74 + 2.75 class XendAPIAsyncProxy: 2.76 """ A redirector for Async.Class.function calls to XendAPI 2.77 but wraps the call for use with the XendTaskManager.