[Kimchi-devel] [PATCH 1/3] [WOK] Move Tasks to Wok.

pvital at linux.vnet.ibm.com pvital at linux.vnet.ibm.com
Mon Sep 21 14:00:18 UTC 2015


From: Paulo Vital <pvital at linux.vnet.ibm.com>

The Tasks collection and Task resource are basic structures and will be used by
all plugins inside the Wok framework. Moving them from Kimchi to Wok.

Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
 docs/API.md                     | 30 +++++++++++++++++++
 plugins/kimchi/control/tasks.py | 37 ------------------------
 plugins/kimchi/docs/API.md      | 31 --------------------
 plugins/kimchi/model/tasks.py   | 64 -----------------------------------------
 src/wok/control/tasks.py        | 37 ++++++++++++++++++++++++
 src/wok/model/tasks.py          | 64 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 131 insertions(+), 132 deletions(-)
 delete mode 100644 plugins/kimchi/control/tasks.py
 delete mode 100644 plugins/kimchi/model/tasks.py
 create mode 100644 src/wok/control/tasks.py
 create mode 100644 src/wok/model/tasks.py

diff --git a/docs/API.md b/docs/API.md
index 67d966e..0ec1653 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -44,3 +44,33 @@ general conventions:

 * **GET**: Retrieve a summarized list names of all UI Plugins

+### Collection: Tasks
+
+**URI:** /tasks
+
+**Methods:**
+
+* **GET**: Retrieve a summarized list of current Tasks
+
+### Resource: Task
+
+**URI:** /tasks/*:id*
+
+A task represents an asynchronous operation that is being performed by the
+server.
+
+**Methods:**
+
+* **GET**: Retrieve the full description of the Task
+    * id: The Task ID is used to identify this Task in the API.
+    * status: The current status of the Task
+        * running: The task is running
+        * finished: The task has finished successfully
+        * failed: The task failed
+    * message: Human-readable details about the Task status
+    * target_uri: Resource URI related to the Task
+* **POST**: *See Task Actions*
+
+**Actions (POST):**
+
+*No actions defined*
diff --git a/plugins/kimchi/control/tasks.py b/plugins/kimchi/control/tasks.py
deleted file mode 100644
index b25d892..0000000
--- a/plugins/kimchi/control/tasks.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#
-# Project Kimchi
-#
-# Copyright IBM, Corp. 2013-2014
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
-
-from wok.control.base import Collection, Resource
-from wok.control.utils import UrlSubNode
-
-
- at UrlSubNode("tasks", True)
-class Tasks(Collection):
-    def __init__(self, model):
-        super(Tasks, self).__init__(model)
-        self.resource = Task
-
-
-class Task(Resource):
-    def __init__(self, model, id):
-        super(Task, self).__init__(model, id)
-
-    @property
-    def data(self):
-        return self.info
diff --git a/plugins/kimchi/docs/API.md b/plugins/kimchi/docs/API.md
index bfefeab..fca424c 100644
--- a/plugins/kimchi/docs/API.md
+++ b/plugins/kimchi/docs/API.md
@@ -635,37 +635,6 @@ A interface represents available interface on host.
 * deactivate: Deactivate an active Network


-### Collection: Tasks
-
-**URI:** /plugins/kimchi/tasks
-
-**Methods:**
-
-* **GET**: Retrieve a summarized list of current Tasks
-
-### Resource: Task
-
-**URI:** /plugins/kimchi/tasks/*:id*
-
-A task represents an asynchronous operation that is being performed by the
-server.
-
-**Methods:**
-
-* **GET**: Retrieve the full description of the Task
-    * id: The Task ID is used to identify this Task in the API.
-    * status: The current status of the Task
-        * running: The task is running
-        * finished: The task has finished successfully
-        * failed: The task failed
-    * message: Human-readable details about the Task status
-    * target_uri: Resource URI related to the Task
-* **POST**: *See Task Actions*
-
-**Actions (POST):**
-
-*No actions defined*
-
 ### Resource: Configuration

 **URI:** /plugins/kimchi/config
diff --git a/plugins/kimchi/model/tasks.py b/plugins/kimchi/model/tasks.py
deleted file mode 100644
index 678fdc2..0000000
--- a/plugins/kimchi/model/tasks.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#
-# Project Kimchi
-#
-# Copyright IBM, Corp. 2014
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
-
-
-import time
-
-from wok.exception import TimeoutExpired
-
-
-class TasksModel(object):
-    def __init__(self, **kargs):
-        self.objstore = kargs['objstore']
-
-    def get_list(self):
-        with self.objstore as session:
-            return session.get_list('task')
-
-
-class TaskModel(object):
-    def __init__(self, **kargs):
-        self.objstore = kargs['objstore']
-
-    def lookup(self, id):
-        with self.objstore as session:
-            return session.get('task', str(id))
-
-    def wait(self, id, timeout=10):
-        """Wait for a task until it stops running (successfully or due to
-        an error). If the Task finishes its execution before <timeout>, this
-        function returns normally; otherwise an exception is raised.
-
-        Parameters:
-        id -- The Task ID.
-        timeout -- The maximum time, in seconds, that this function should wait
-            for the Task. If the Task runs for more than <timeout>,
-            "TimeoutExpired" is raised.
-        """
-        for i in range(0, timeout):
-            with self.objstore as session:
-                task = session.get('task', str(id))
-
-            if task['status'] != 'running':
-                return
-
-            time.sleep(1)
-
-        raise TimeoutExpired('KCHASYNC0003E', {'seconds': timeout,
-                                               'task': task['target_uri']})
diff --git a/src/wok/control/tasks.py b/src/wok/control/tasks.py
new file mode 100644
index 0000000..f6e8a80
--- /dev/null
+++ b/src/wok/control/tasks.py
@@ -0,0 +1,37 @@
+#
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2013-2014
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+from base import Collection, Resource
+from utils import UrlSubNode
+
+
+ at UrlSubNode("tasks", True)
+class Tasks(Collection):
+    def __init__(self, model):
+        super(Tasks, self).__init__(model)
+        self.resource = Task
+
+
+class Task(Resource):
+    def __init__(self, model, id):
+        super(Task, self).__init__(model, id)
+
+    @property
+    def data(self):
+        return self.info
diff --git a/src/wok/model/tasks.py b/src/wok/model/tasks.py
new file mode 100644
index 0000000..678fdc2
--- /dev/null
+++ b/src/wok/model/tasks.py
@@ -0,0 +1,64 @@
+#
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2014
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+
+import time
+
+from wok.exception import TimeoutExpired
+
+
+class TasksModel(object):
+    def __init__(self, **kargs):
+        self.objstore = kargs['objstore']
+
+    def get_list(self):
+        with self.objstore as session:
+            return session.get_list('task')
+
+
+class TaskModel(object):
+    def __init__(self, **kargs):
+        self.objstore = kargs['objstore']
+
+    def lookup(self, id):
+        with self.objstore as session:
+            return session.get('task', str(id))
+
+    def wait(self, id, timeout=10):
+        """Wait for a task until it stops running (successfully or due to
+        an error). If the Task finishes its execution before <timeout>, this
+        function returns normally; otherwise an exception is raised.
+
+        Parameters:
+        id -- The Task ID.
+        timeout -- The maximum time, in seconds, that this function should wait
+            for the Task. If the Task runs for more than <timeout>,
+            "TimeoutExpired" is raised.
+        """
+        for i in range(0, timeout):
+            with self.objstore as session:
+                task = session.get('task', str(id))
+
+            if task['status'] != 'running':
+                return
+
+            time.sleep(1)
+
+        raise TimeoutExpired('KCHASYNC0003E', {'seconds': timeout,
+                                               'task': task['target_uri']})
--
2.4.3




More information about the Kimchi-devel mailing list