From 77442ed1d3615d15b9cb2841e4510915d7eaee1c Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Tue, 30 Jan 2007 16:09:16 +0000 Subject: [PATCH] Added task.session field. Fix session.get_by_uuid and get_uuid, and remove session.get_all. Signed-off-by: Ewan Mellor --- docs/xen-api/xenapi-datamodel.tex | 33 ++++++++++++++++++++++++ tools/python/xen/xend/XendAPI.py | 21 ++++++++++++--- tools/python/xen/xend/XendTask.py | 7 +++-- tools/python/xen/xend/XendTaskManager.py | 6 ++--- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/docs/xen-api/xenapi-datamodel.tex b/docs/xen-api/xenapi-datamodel.tex index cde30247cd..2454b28f7a 100644 --- a/docs/xen-api/xenapi-datamodel.tex +++ b/docs/xen-api/xenapi-datamodel.tex @@ -495,6 +495,7 @@ $\mathit{RO}_\mathit{run}$ & {\tt uuid} & string & unique identifier/object ref $\mathit{RO}_\mathit{run}$ & {\tt name/label} & string & a human-readable name \\ $\mathit{RO}_\mathit{run}$ & {\tt name/description} & string & a notes field containg human-readable description \\ $\mathit{RO}_\mathit{run}$ & {\tt status} & task\_status\_type & current status of the task \\ +$\mathit{RO}_\mathit{run}$ & {\tt session} & session ref & the session that created the task \\ $\mathit{RO}_\mathit{run}$ & {\tt progress} & int & if the task is still pending, this field contains the estimated percentage complete (0-100). If task has completed (successfully or unsuccessfully) this should be 100. \\ $\mathit{RO}_\mathit{run}$ & {\tt type} & string & if the task has completed successfully, this field contains the type of the encoded result (i.e. name of the class whose reference is in the result field). Undefined otherwise. \\ $\mathit{RO}_\mathit{run}$ & {\tt result} & string & if the task has completed successfully, this field contains the result value (either Void or an object reference). Undefined otherwise. \\ @@ -687,6 +688,38 @@ task\_status\_type } +value of the field +\vspace{0.3cm} +\vspace{0.3cm} +\vspace{0.3cm} +\subsubsection{RPC name:~get\_session} + +{\bf Overview:} +Get the session field of the given task. + + \noindent {\bf Signature:} +\begin{verbatim} (session ref) get_session (session_id s, task ref self)\end{verbatim} + + +\noindent{\bf Arguments:} + + +\vspace{0.3cm} +\begin{tabular}{|c|c|p{7cm}|} + \hline +{\bf type} & {\bf name} & {\bf description} \\ \hline +{\tt task ref } & self & reference to the object \\ \hline + +\end{tabular} + +\vspace{0.3cm} + + \noindent {\bf Return Type:} +{\tt +session ref +} + + value of the field \vspace{0.3cm} \vspace{0.3cm} diff --git a/tools/python/xen/xend/XendAPI.py b/tools/python/xen/xend/XendAPI.py index 1854f4aa19..7de21ad4d9 100644 --- a/tools/python/xen/xend/XendAPI.py +++ b/tools/python/xen/xend/XendAPI.py @@ -396,6 +396,9 @@ class XendAPI(object): # all get_by_uuid() methods. for api_cls in classes.keys(): + if api_cls == 'session': + continue + get_by_uuid = '%s_get_by_uuid' % api_cls get_uuid = '%s_get_uuid' % api_cls def _get_by_uuid(_1, _2, ref): @@ -501,9 +504,13 @@ class XendAPI(object): 'this_host': XendNode.instance().uuid, 'this_user': auth_manager().get_user(session)} return xen_api_success(record) - def session_get_all(self): - return xen_api_error(XEND_ERROR_UNSUPPORTED) - + + def session_get_uuid(self, session): + return xen_api_success(session) + + def session_get_by_uuid(self, session): + return xen_api_success(session) + # attributes (ro) def session_get_this_host(self, session): return xen_api_success(XendNode.instance().uuid) @@ -530,6 +537,7 @@ class XendAPI(object): 'error_code', 'error_info', 'allowed_operations', + 'session' ] task_attr_rw = [] @@ -572,6 +580,10 @@ class XendAPI(object): def task_get_allowed_operations(self, session, task_ref): return xen_api_success({}) + def task_get_session(self, session, task_ref): + task = XendTaskManager.get_task(task_ref) + return xen_api_success(task.session) + def task_get_all(self, session): tasks = XendTaskManager.get_all_tasks() return xen_api_success(tasks) @@ -2057,7 +2069,8 @@ class XendAPIAsyncProxy: task_uuid = XendTaskManager.create_task(method, args, synchronous_method_name, return_type, - synchronous_method_name) + synchronous_method_name, + session) return xen_api_success(task_uuid) # diff --git a/tools/python/xen/xend/XendTask.py b/tools/python/xen/xend/XendTask.py index 92d5fdd732..0485c39207 100644 --- a/tools/python/xen/xend/XendTask.py +++ b/tools/python/xen/xend/XendTask.py @@ -45,8 +45,8 @@ class XendTask(threading.Thread): task_progress = {} task_progress_lock = threading.Lock() - def __init__(self, uuid, func, args, func_name, return_type = None, - label = None, desc = None): + def __init__(self, uuid, func, args, func_name, return_type, label, desc, + session): """ @param uuid: UUID of the task @type uuid: string @@ -82,6 +82,8 @@ class XendTask(threading.Thread): self.func = func self.args = args + self.session = session + def set_status(self, new_status): self.status_lock.acquire() try: @@ -145,6 +147,7 @@ class XendTask(threading.Thread): 'error_code': self.error_code, 'error_info': self.error_info, 'allowed_operations': {}, + 'session': self.session, } def get_progress(self): diff --git a/tools/python/xen/xend/XendTaskManager.py b/tools/python/xen/xend/XendTaskManager.py index ee5403c24a..6282078a44 100644 --- a/tools/python/xen/xend/XendTaskManager.py +++ b/tools/python/xen/xend/XendTaskManager.py @@ -32,7 +32,7 @@ import threading tasks = {} tasks_lock = threading.Lock() -def create_task(func, args, func_name, return_type = None, label = ''): +def create_task(func, args, func_name, return_type, label, session): """Creates a new Task and registers it with the XendTaskManager. @param func: callable object XMLRPC method @@ -48,8 +48,8 @@ def create_task(func, args, func_name, return_type = None, label = ''): task_uuid = uuid.createString() try: tasks_lock.acquire() - task = XendTask(task_uuid, func, args, func_name, - return_type = return_type, label = label) + task = XendTask(task_uuid, func, args, func_name, return_type, label, + '', session) tasks[task_uuid] = task finally: tasks_lock.release() -- 2.30.2