[Kimchi-devel] [PATCHv5 1/8] Support params for GET method
lvroyce at linux.vnet.ibm.com
lvroyce at linux.vnet.ibm.com
Tue Jan 7 09:43:03 UTC 2014
From: Royce Lv <lvroyce at linux.vnet.ibm.com>
Add support for passing params for GET method,
we will call it like:
GET /vms?state=running
Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
src/kimchi/control/base.py | 8 +++++---
src/kimchi/control/utils.py | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
index 185c8d8..da8a444 100644
--- a/src/kimchi/control/base.py
+++ b/src/kimchi/control/base.py
@@ -28,7 +28,7 @@ import urllib2
import kimchi.template
from kimchi.control.utils import get_class_name, internal_redirect, model_fn
-from kimchi.control.utils import parse_request, validate_method
+from kimchi.control.utils import parse_request, parse_param, validate_method
from kimchi.control.utils import validate_params
from kimchi.exception import InvalidOperation, InvalidParameter
from kimchi.exception import MissingParameter, NotFoundError, OperationFailed
@@ -214,8 +214,10 @@ class Collection(object):
def _get_resources(self):
try:
+ params = parse_param()
+ validate_params(params, self, 'get_list')
get_list = getattr(self.model, model_fn(self, 'get_list'))
- idents = get_list(*self.model_args)
+ idents = get_list(*self.model_args, **params)
res_list = []
for ident in idents:
# internal text, get_list changes ident to unicode for sorted
@@ -242,7 +244,7 @@ class Collection(object):
return kimchi.template.render(get_class_name(self), data)
@cherrypy.expose
- def index(self, *args):
+ def index(self, *args, **kwargs):
method = validate_method(('GET', 'POST'))
if method == 'GET':
try:
diff --git a/src/kimchi/control/utils.py b/src/kimchi/control/utils.py
index c3c5f8e..4b3c4b0 100644
--- a/src/kimchi/control/utils.py
+++ b/src/kimchi/control/utils.py
@@ -81,6 +81,8 @@ def parse_request():
raise cherrypy.HTTPError(415, "This API only supports"
" 'application/json'")
+def parse_param():
+ return cherrypy.request.params
def internal_redirect(url):
raise cherrypy.InternalRedirect(url.encode("utf-8"))
--
1.8.1.2
More information about the Kimchi-devel
mailing list