- Better error reporting.
- Flask now uses application's logger instead of its own. - ucloud file scanner refactored.
This commit is contained in:
parent
eea6c1568e
commit
972bb5a920
14 changed files with 157 additions and 154 deletions
|
|
@ -10,7 +10,8 @@ from pyotp import TOTP
|
|||
from ucloud.shared import shared
|
||||
from ucloud.settings import settings
|
||||
|
||||
logger = logging.getLogger("ucloud.api.helper")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def check_otp(name, realm, token):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
import json
|
||||
import pynetbox
|
||||
import logging
|
||||
import urllib3
|
||||
|
||||
from uuid import uuid4
|
||||
from os.path import join as join_path
|
||||
|
||||
from flask import Flask, request
|
||||
from flask_restful import Resource, Api
|
||||
from werkzeug.exceptions import HTTPException
|
||||
|
||||
from ucloud.common import counters
|
||||
from ucloud.common.vm import VMStatus
|
||||
|
|
@ -15,10 +18,33 @@ from ucloud.shared import shared
|
|||
|
||||
from . import schemas
|
||||
from .helper import generate_mac, mac2ipv6
|
||||
from . import logger
|
||||
|
||||
|
||||
def get_parent(obj, attr):
|
||||
parent = getattr(obj, attr)
|
||||
child = parent
|
||||
while parent is not None:
|
||||
child = parent
|
||||
parent = getattr(parent, attr)
|
||||
return child
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
app = Flask(__name__)
|
||||
api = Api(app)
|
||||
app.logger.handlers.clear()
|
||||
|
||||
|
||||
@app.errorhandler(Exception)
|
||||
def handle_exception(e):
|
||||
app.logger.error(e)
|
||||
# pass through HTTP errors
|
||||
if isinstance(e, HTTPException):
|
||||
return e
|
||||
|
||||
# now you're handling non-HTTP exceptions only
|
||||
return {'message': 'Server Error'}, 500
|
||||
|
||||
|
||||
class CreateVM(Resource):
|
||||
|
|
@ -438,8 +464,8 @@ class CreateNetwork(Resource):
|
|||
"is_pool": True,
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Exception occur while contacting netbox")
|
||||
except Exception as err:
|
||||
app.logger.error(err)
|
||||
return {"message": "Error occured while creating network."}
|
||||
else:
|
||||
network_entry["ipv6"] = prefix["prefix"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue