[Kimchi-devel] [PATCH v2 3/8] Debug Report Rename: Implement Back-end

Hongliang Wang hlwang at linux.vnet.ibm.com
Thu May 22 07:55:39 UTC 2014


Added processing in model and controller.

Signed-off-by: Hongliang Wang <hlwang at linux.vnet.ibm.com>
---
 src/kimchi/control/debugreports.py |  4 +++-
 src/kimchi/model/debugreports.py   | 13 +++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/kimchi/control/debugreports.py b/src/kimchi/control/debugreports.py
index 3c12230..65b53a3 100644
--- a/src/kimchi/control/debugreports.py
+++ b/src/kimchi/control/debugreports.py
@@ -22,7 +22,7 @@ from kimchi.control.utils import internal_redirect
 from kimchi.control.utils import UrlSubNode
 
 
- at UrlSubNode("debugreports", True, ['GET', 'POST'])
+ at UrlSubNode("debugreports", True, ['GET', 'PUT', 'POST'])
 class DebugReports(AsyncCollection):
     def __init__(self, model):
         super(DebugReports, self).__init__(model)
@@ -32,6 +32,8 @@ class DebugReports(AsyncCollection):
 class DebugReport(Resource):
     def __init__(self, model, ident):
         super(DebugReport, self).__init__(model, ident)
+        self.update_params = ["name"]
+        self.uri_fmt = '/debugreports/%s'
         self.content = DebugReportContent(model, ident)
 
     @property
diff --git a/src/kimchi/model/debugreports.py b/src/kimchi/model/debugreports.py
index cd31b31..43c4fb6 100644
--- a/src/kimchi/model/debugreports.py
+++ b/src/kimchi/model/debugreports.py
@@ -170,6 +170,19 @@ class DebugReportModel(object):
         return {'uri': file_target,
                 'ctime': ctime}
 
+    def update(self, name, params):
+        path = config.get_debugreports_path()
+        file_pattern = os.path.join(path, name + '.*')
+        try:
+            file_source = glob.glob(file_pattern)[0]
+        except IndexError:
+            raise NotFoundError("KCHDR0001E", {'name': name})
+
+        file_target = file_source.replace(name, params['name'])
+        shutil.move(file_source, file_target)
+        kimchi_log.info('%s renamed to %s' % (file_source, file_target))
+        return params['name']
+
     def delete(self, name):
         path = config.get_debugreports_path()
         file_pattern = os.path.join(path, name + '.*')
-- 
1.8.1.4




More information about the Kimchi-devel mailing list