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

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Mon Dec 30 17:39:48 UTC 2013


Reviewed-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>

On 12/26/2013 07:48 PM, Aline Manera wrote:
> 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       |   26 ++++++++++++++++++++++++--
>   2 files changed, 24 insertions(+), 22 deletions(-)
>
> diff --git a/src/kimchi/controller.py b/src/kimchi/controller.py
> index 13b394e..af30118 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 46403ab..21950bc 100644
> --- a/src/kimchi/root.py
> +++ b/src/kimchi/root.py
> @@ -25,9 +25,12 @@ 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
> +from kimchi.exception import OperationFailed
>
>
>   class Root(controller.Resource):
> @@ -52,8 +55,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 +88,24 @@ class Root(controller.Resource):
>           if page.endswith('.html'):
>               return template.render('tabs/' + page, None)
>           raise cherrypy.HTTPError(404)
> +
> +    @cherrypy.expose
> +    def login(self, *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(self):
> +        auth.logout()
> +        return '{}'




More information about the Kimchi-devel mailing list