[Kimchi-devel] [PATCH V2] pass params to create method of all Collections.

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Wed Feb 12 10:21:22 UTC 2014


From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

We can pass params as an argument to create method, do not need call
parse_request in every create method.

create means the HTTP POST method, and POST requires body.
So every create needs params parsed from body.
But we do not need to parse params in every create.

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 src/kimchi/control/base.py         | 8 +++-----
 src/kimchi/control/storagepools.py | 5 ++---
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
index 5c8ee82..6ce8113 100644
--- a/src/kimchi/control/base.py
+++ b/src/kimchi/control/base.py
@@ -196,14 +196,13 @@ class Collection(object):
         self.resource_args = []
         self.model_args = []
 
-    def create(self, *args):
+    def create(self, params, *args):
         try:
             create = getattr(self.model, model_fn(self, 'create'))
         except AttributeError:
             error = 'Create is not allowed for %s' % get_class_name(self)
             raise cherrypy.HTTPError(405, error)
 
-        params = parse_request()
         validate_params(params, self, 'create')
         args = self.model_args + [params]
         name = create(*args)
@@ -273,7 +272,7 @@ class Collection(object):
 
         elif method == 'POST':
             try:
-                return self.create(*args)
+                return self.create(parse_request(), *args)
             except MissingParameter, param:
                 error = "Missing parameter: '%s'" % param
                 raise cherrypy.HTTPError(400, error)
@@ -296,14 +295,13 @@ class AsyncCollection(Collection):
     def __init__(self, model):
         super(AsyncCollection, self).__init__(model)
 
-    def create(self, *args):
+    def create(self, params, *args):
         try:
             create = getattr(self.model, model_fn(self, 'create'))
         except AttributeError:
             error = 'Create is not allowed for %s' % get_class_name(self)
             raise cherrypy.HTTPError(405, error)
 
-        params = parse_request()
         args = self.model_args + [params]
         task = create(*args)
         cherrypy.response.status = 202
diff --git a/src/kimchi/control/storagepools.py b/src/kimchi/control/storagepools.py
index af10acd..ea19609 100644
--- a/src/kimchi/control/storagepools.py
+++ b/src/kimchi/control/storagepools.py
@@ -28,7 +28,7 @@ import cherrypy
 
 from kimchi.control.base import Collection, Resource
 from kimchi.control.storagevolumes import IsoVolumes, StorageVolumes
-from kimchi.control.utils import get_class_name, model_fn, parse_request
+from kimchi.control.utils import get_class_name, model_fn
 from kimchi.control.utils import validate_params
 from kimchi.model.storagepools import ISO_POOL_NAME
 from kimchi.control.utils import UrlSubNode
@@ -42,14 +42,13 @@ class StoragePools(Collection):
         isos = IsoPool(model)
         setattr(self, ISO_POOL_NAME, isos)
 
-    def create(self, *args):
+    def create(self, params, *args):
         try:
             create = getattr(self.model, model_fn(self, 'create'))
         except AttributeError:
             error = 'Create is not allowed for %s' % get_class_name(self)
             raise cherrypy.HTTPError(405, error)
 
-        params = parse_request()
         validate_params(params, self, 'create')
         args = self.model_args + [params]
         name = create(*args)
-- 
1.8.4.2




More information about the Kimchi-devel mailing list