Added task.session field.
authorEwan Mellor <ewan@xensource.com>
Tue, 30 Jan 2007 16:09:16 +0000 (16:09 +0000)
committerEwan Mellor <ewan@xensource.com>
Tue, 30 Jan 2007 16:09:16 +0000 (16:09 +0000)
Fix session.get_by_uuid and get_uuid, and remove session.get_all.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
docs/xen-api/xenapi-datamodel.tex
tools/python/xen/xend/XendAPI.py
tools/python/xen/xend/XendTask.py
tools/python/xen/xend/XendTaskManager.py

index cde30247cd0ff4c0f3e48fb9dbe46078b6a6fb20..2454b28f7a6f72fe4327b3bd52b51558f4302a12 100644 (file)
@@ -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}
index 1854f4aa19419cf04293d4ddc996857313ee2e9a..7de21ad4d9a08c4bd691af5f7f7c65f8fc0abf3e 100644 (file)
@@ -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)
 
 #   
index 92d5fdd73295259395d5c220b8167ca6dfdca39d..0485c3920797a38deca659ba3aef5fb64c14b937 100644 (file)
@@ -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):
index ee5403c24a06e81de7d3b65bcfc2226a684a60d3..6282078a44f7388bad9f25df3606f9bef858082e 100644 (file)
@@ -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()