[Kimchi-devel] [PATCH 07/15] Move all resources related to debug reports to control/debugreports.py

Aline Manera alinefm at linux.vnet.ibm.com
Thu Dec 26 21:48:55 UTC 2013


From: Aline Manera <alinefm at br.ibm.com>

DebugReports(Collection), DebugReport(Resource) and DebugReportContent(Resource)
were moved to a new - control/debugreports.py
That way we can easily know where debug report resource is implemented.

Signed-off-by: Aline Manera <alinefm at br.ibm.com>
---
 src/kimchi/control/debugreports.py |   52 ++++++++++++++++++++++++++++++++++++
 src/kimchi/controller.py           |   28 -------------------
 src/kimchi/root.py                 |    3 ++-
 3 files changed, 54 insertions(+), 29 deletions(-)
 create mode 100644 src/kimchi/control/debugreports.py

diff --git a/src/kimchi/control/debugreports.py b/src/kimchi/control/debugreports.py
new file mode 100644
index 0000000..a55ba38
--- /dev/null
+++ b/src/kimchi/control/debugreports.py
@@ -0,0 +1,52 @@
+#
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2013
+#
+# Authors:
+#  Aline Manera <alinefm at linux.vnet.ibm.com>
+#  Shu Ming <shuming at linux.vnet.ibm.com>
+#
+# 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 kimchi.control.base import AsyncCollection, Resource
+from kimchi.control.utils import internal_redirect
+
+
+class DebugReports(AsyncCollection):
+    def __init__(self, model):
+        super(DebugReports, self).__init__(model)
+        self.resource = DebugReport
+
+
+class DebugReport(Resource):
+    def __init__(self, model, ident):
+        super(DebugReport, self).__init__(model, ident)
+        self.content = DebugReportContent(model, ident)
+
+    @property
+    def data(self):
+        return {'name': self.ident,
+                'file': self.info['file'],
+                'time': self.info['ctime']}
+
+
+class DebugReportContent(Resource):
+    def __init__(self, model, ident):
+        super(DebugReportContent, self).__init__(model, ident)
+
+    def get(self):
+        self.lookup()
+        raise internal_redirect(self.info['file'])
diff --git a/src/kimchi/controller.py b/src/kimchi/controller.py
index 38ccb7b..a856efd 100644
--- a/src/kimchi/controller.py
+++ b/src/kimchi/controller.py
@@ -35,15 +35,6 @@ from kimchi.exception import NotFoundError,  OperationFailed
 from kimchi.model import ISO_POOL_NAME
 
 
-class DebugReportContent(Resource):
-    def __init__(self, model, ident):
-        super(DebugReportContent, self).__init__(model, ident)
-
-    def get(self):
-        self.lookup()
-        raise internal_redirect(self.info['file'])
-
-
 class Interfaces(Collection):
     def __init__(self, model):
         super(Interfaces, self).__init__(model)
@@ -244,25 +235,6 @@ class Tasks(Collection):
         self.resource = Task
 
 
-class DebugReports(AsyncCollection):
-    def __init__(self, model):
-        super(DebugReports, self).__init__(model)
-        self.resource = DebugReport
-
-
-class DebugReport(Resource):
-    def __init__(self, model, ident):
-        super(DebugReport, self).__init__(model, ident)
-        self.ident = ident
-        self.content = DebugReportContent(model, ident)
-
-    @property
-    def data(self):
-        return {'name': self.ident,
-                'file': self.info['file'],
-                'time': self.info['ctime']}
-
-
 class Config(Resource):
     def __init__(self, model, id=None):
         super(Config, self).__init__(model, id)
diff --git a/src/kimchi/root.py b/src/kimchi/root.py
index cd4a11f..d2aeb9f 100644
--- a/src/kimchi/root.py
+++ b/src/kimchi/root.py
@@ -31,6 +31,7 @@ from kimchi import template
 from kimchi.config import get_api_schema_file
 from kimchi.control.utils import parse_request
 from kimchi.control.base import Resource
+from kimchi.control.debugreports import DebugReports
 from kimchi.control.templates import Templates
 from kimchi.control.vms import VMs
 from kimchi.exception import OperationFailed
@@ -58,7 +59,7 @@ class Root(Resource):
         self.tasks = controller.Tasks(model)
         self.config = controller.Config(model)
         self.host = controller.Host(model)
-        self.debugreports = controller.DebugReports(model)
+        self.debugreports = DebugReports(model)
         self.plugins = controller.Plugins(model)
         self.api_schema = json.load(open(get_api_schema_file()))
 
-- 
1.7.10.4




More information about the Kimchi-devel mailing list