from request import Request
from server import Server
-from restful.decorators import catch
-
class Root(RestController):
config = Config()
server = Server()
@expose(template='json')
- @catch
def get(self, **kwargs):
"""
Show the basic information for the REST API
from pecan.rest import RestController
from restful import common, module
-from restful.decorators import auth, catch
+from restful.decorators import auth
class ConfigOsd(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
@expose(template='json')
- @catch
@auth
def patch(self, **kwargs):
"""
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
class ConfigCluster(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
from restful import common, module
from collections import defaultdict
-from restful.decorators import auth, catch
+from restful.decorators import auth
class CrushRuleset(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
class CrushRule(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
from pecan.rest import RestController
from restful import module
-from restful.decorators import catch
import restful
class Doc(RestController):
@expose(template='json')
- @catch
def get(self, **kwargs):
"""
Show documentation information
from pecan.rest import RestController
from restful import module
-from restful.decorators import auth, catch
+from restful.decorators import auth
class MonName(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
class Mon(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
from pecan.rest import RestController
from restful import common, module
-from restful.decorators import auth, catch
+from restful.decorators import auth
class OsdIdCommand(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
@expose(template='json')
- @catch
@auth
def post(self, **kwargs):
"""
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
@expose(template='json')
- @catch
@auth
def patch(self, **kwargs):
"""
class Osd(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
from pecan.rest import RestController
from restful import common, module
-from restful.decorators import auth, catch
+from restful.decorators import auth
class PoolId(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
@expose(template='json')
- @catch
@auth
def patch(self, **kwargs):
"""
@expose(template='json')
- @catch
@auth
def delete(self, **kwargs):
"""
class Pool(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
@expose(template='json')
- @catch
@auth
def post(self, **kwargs):
"""
from pecan.rest import RestController
from restful import module
-from restful.decorators import auth, catch, lock
+from restful.decorators import auth, lock
class RequestId(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
@expose(template='json')
- @catch
@auth
@lock
def delete(self, **kwargs):
class Request(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
@expose(template='json')
- @catch
@auth
@lock
def delete(self, **kwargs):
@expose(template='json')
- @catch
@auth
def post(self, **kwargs):
"""
from pecan.rest import RestController
from restful import module
-from restful.decorators import auth, catch
+from restful.decorators import auth
class ServerFqdn(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
class Server(RestController):
@expose(template='json')
- @catch
@auth
def get(self, **kwargs):
"""
return decorated
-# Helper function to catch and log the exceptions
-def catch(f):
- @wraps(f)
- def decorated(*args, **kwargs):
- try:
- return f(*args, **kwargs)
- except:
- module.instance.log.error(str(traceback.format_exc()))
- response.status = 500
- return {'message': str(traceback.format_exc()).split('\n')}
- return decorated
-
-
# Helper function to lock the function
def lock(f):
@wraps(f)
--- /dev/null
+from pecan.hooks import PecanHook
+
+import traceback
+
+import module
+
+class ErrorHook(PecanHook):
+ def on_error(self, stat, exc):
+ module.instance.log.error(str(traceback.format_exc()))
from pecan.rest import RestController
from werkzeug.serving import make_server, make_ssl_devcert
+from hooks import ErrorHook
from mgr_module import MgrModule, CommandResult
# Global instance to share
self.server = make_server(
host='0.0.0.0',
port=8003,
- app=make_app('restful.api.Root'),
+ app=make_app(
+ root='restful.api.Root',
+ hooks = lambda: [ErrorHook()],
+ ),
ssl_context=(cert, pkey),
)