[Kimchi-devel] [PATCH 03/16] Move login() and logout() functions from controller.py to root.py

Aline Manera alinefm at linux.vnet.ibm.com
Mon Dec 23 18:41:18 UTC 2013


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

controller.py file must contain all related to Kimchi API resources
Common cherrypy functions must be in root.py

Signed-off-by: Aline Manera <alinefm at br.ibm.com>
---
 src/kimchi/controller.py |   20 --------------------
 src/kimchi/root.py       |   25 +++++++++++++++++++++++--
 2 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/src/kimchi/controller.py b/src/kimchi/controller.py
index aec1579..5bcffff 100644
--- a/src/kimchi/controller.py
+++ b/src/kimchi/controller.py
@@ -28,7 +28,6 @@ from functools import wraps
 
 
 import kimchi.template
-from kimchi import auth
 from kimchi.control.utils import get_class_name, internal_redirect, model_fn
 from kimchi.control.utils import parse_request, validate_method, validate_params
 from kimchi.exception import InvalidOperation, InvalidParameter, MissingParameter
@@ -649,25 +648,6 @@ class Partition(Resource):
     def data(self):
         return self.info
 
- at cherrypy.expose
-def login(*args):
-    params = parse_request()
-    try:
-        userid = params['userid']
-        password = params['password']
-    except KeyError, key:
-        raise cherrypy.HTTPError(400, "Missing parameter: '%s'" % key)
-    try:
-        auth.login(userid, password)
-    except OperationFailed:
-        raise cherrypy.HTTPError(401)
-    return '{}'
-
- at cherrypy.expose
-def logout():
-    auth.logout()
-    return '{}'
-
 class Plugins(Collection):
     def __init__(self, model):
         super(Plugins, self).__init__(model)
diff --git a/src/kimchi/root.py b/src/kimchi/root.py
index d1fe818..6310781 100644
--- a/src/kimchi/root.py
+++ b/src/kimchi/root.py
@@ -25,9 +25,11 @@ import cherrypy
 import json
 
 
+from kimchi import auth
 from kimchi import controller
 from kimchi import template
 from kimchi.config import get_api_schema_file
+from kimchi.control.utils import parse_request
 
 
 class Root(controller.Resource):
@@ -52,8 +54,6 @@ class Root(controller.Resource):
         self.tasks = controller.Tasks(model)
         self.config = controller.Config(model)
         self.host = controller.Host(model)
-        self.login = controller.login
-        self.logout = controller.logout
         self.debugreports = controller.DebugReports(model)
         self.plugins = controller.Plugins(model)
         self.api_schema = json.load(open(get_api_schema_file()))
@@ -87,3 +87,24 @@ class Root(controller.Resource):
         if page.endswith('.html'):
             return template.render('tabs/' + page, None)
         raise cherrypy.HTTPError(404)
+
+    @cherrypy.expose
+    def login(*args):
+        params = parse_request()
+        try:
+            userid = params['userid']
+            password = params['password']
+        except KeyError, key:
+            raise cherrypy.HTTPError(400, "Missing parameter: '%s'" % key)
+
+        try:
+            auth.login(userid, password)
+        except OperationFailed:
+            raise cherrypy.HTTPError(401)
+
+        return '{}'
+
+    @cherrypy.expose
+    def logout():
+        auth.logout()
+        return '{}'
-- 
1.7.10.4




More information about the Kimchi-devel mailing list