Separate OpenStack exceptions from Horizon exceptions.
Placing the OpenStack exception class definitions into their own module inside the openstack_dashboard project allows more flexibility for deployers and others who might wish to use the horizon module for non-OpenStack Django projects. The patch also contains two tiny cleanup items in the templatetag files. Change-Id: I8b250804ad07027d40d554ad1e7ee0b5af63d466
This commit is contained in:
parent
2f0678db45
commit
30b58e2d03
@ -28,11 +28,6 @@ from django.utils import termcolors
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.debug import SafeExceptionReporterFilter, CLEANSED_SUBSTITUTE
|
||||
|
||||
from cloudfiles import errors as swiftclient
|
||||
from glanceclient.common import exceptions as glanceclient
|
||||
from keystoneclient import exceptions as keystoneclient
|
||||
from novaclient import exceptions as novaclient
|
||||
|
||||
from horizon import messages
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -200,33 +195,9 @@ class HandledException(HorizonException):
|
||||
|
||||
HORIZON_CONFIG = getattr(settings, "HORIZON_CONFIG", {})
|
||||
EXCEPTION_CONFIG = HORIZON_CONFIG.get("exceptions", {})
|
||||
|
||||
|
||||
UNAUTHORIZED = (keystoneclient.Unauthorized,
|
||||
keystoneclient.Forbidden,
|
||||
novaclient.Unauthorized,
|
||||
novaclient.Forbidden,
|
||||
glanceclient.Unauthorized,
|
||||
swiftclient.AuthenticationFailed,
|
||||
swiftclient.AuthenticationError)
|
||||
UNAUTHORIZED += tuple(EXCEPTION_CONFIG.get('unauthorized', []))
|
||||
|
||||
NOT_FOUND = (keystoneclient.NotFound,
|
||||
novaclient.NotFound,
|
||||
glanceclient.NotFound,
|
||||
swiftclient.NoSuchContainer,
|
||||
swiftclient.NoSuchObject)
|
||||
NOT_FOUND += tuple(EXCEPTION_CONFIG.get('not_found', []))
|
||||
|
||||
|
||||
# NOTE(gabriel): This is very broad, and may need to be dialed in.
|
||||
RECOVERABLE = (keystoneclient.ClientException,
|
||||
# AuthorizationFailure is raised when Keystone is "unavailable".
|
||||
keystoneclient.AuthorizationFailure,
|
||||
novaclient.ClientException,
|
||||
glanceclient.ClientException,
|
||||
swiftclient.Error,
|
||||
AlreadyExists)
|
||||
UNAUTHORIZED = tuple(EXCEPTION_CONFIG.get('unauthorized', []))
|
||||
NOT_FOUND = tuple(EXCEPTION_CONFIG.get('not_found', []))
|
||||
RECOVERABLE = (AlreadyExists,)
|
||||
RECOVERABLE += tuple(EXCEPTION_CONFIG.get('recoverable', []))
|
||||
|
||||
|
||||
|
@ -24,6 +24,7 @@ Template tags for customizing Horizon.
|
||||
|
||||
from django import template
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
register = template.Library()
|
||||
@ -31,7 +32,7 @@ register = template.Library()
|
||||
|
||||
class SiteBrandingNode(template.Node):
|
||||
def render(self, context):
|
||||
return settings.SITE_BRANDING
|
||||
return getattr(settings, "SITE_BRANDING", _("Horizon"))
|
||||
|
||||
|
||||
@register.tag
|
||||
|
@ -17,8 +17,8 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django import template
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.datastructures import SortedDict
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from horizon.base import Horizon
|
||||
|
||||
|
@ -23,6 +23,8 @@ import socket
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from openstack_dashboard.exceptions import UNAUTHORIZED, RECOVERABLE, NOT_FOUND
|
||||
|
||||
socket.setdefaulttimeout(1)
|
||||
|
||||
LOGIN_URL = '/auth/login/'
|
||||
@ -116,7 +118,10 @@ HORIZON_CONFIG = {
|
||||
"help_text": _("Password must be between 8 and 18 characters.")
|
||||
},
|
||||
'user_home': None,
|
||||
'help_url': "http://docs.openstack.org"
|
||||
'help_url': "http://docs.openstack.org",
|
||||
'exceptions': {'recoverable': RECOVERABLE,
|
||||
'not_found': NOT_FOUND,
|
||||
'unauthorized': UNAUTHORIZED},
|
||||
}
|
||||
|
||||
COMPRESS_ENABLED = False
|
||||
|
47
openstack_dashboard/exceptions.py
Normal file
47
openstack_dashboard/exceptions.py
Normal file
@ -0,0 +1,47 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2012 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Copyright 2012 Nebula, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cloudfiles import errors as swiftclient
|
||||
from glanceclient.common import exceptions as glanceclient
|
||||
from keystoneclient import exceptions as keystoneclient
|
||||
from novaclient import exceptions as novaclient
|
||||
|
||||
|
||||
UNAUTHORIZED = (keystoneclient.Unauthorized,
|
||||
keystoneclient.Forbidden,
|
||||
novaclient.Unauthorized,
|
||||
novaclient.Forbidden,
|
||||
glanceclient.Unauthorized,
|
||||
swiftclient.AuthenticationFailed,
|
||||
swiftclient.AuthenticationError)
|
||||
|
||||
NOT_FOUND = (keystoneclient.NotFound,
|
||||
novaclient.NotFound,
|
||||
glanceclient.NotFound,
|
||||
swiftclient.NoSuchContainer,
|
||||
swiftclient.NoSuchObject)
|
||||
|
||||
# NOTE(gabriel): This is very broad, and may need to be dialed in.
|
||||
RECOVERABLE = (keystoneclient.ClientException,
|
||||
# AuthorizationFailure is raised when Keystone is "unavailable".
|
||||
keystoneclient.AuthorizationFailure,
|
||||
novaclient.ClientException,
|
||||
glanceclient.ClientException,
|
||||
swiftclient.Error)
|
@ -22,6 +22,8 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from openstack_dashboard import exceptions
|
||||
|
||||
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
BIN_DIR = os.path.abspath(os.path.join(ROOT_PATH, '..', 'bin'))
|
||||
|
||||
@ -53,7 +55,10 @@ HORIZON_CONFIG = {
|
||||
'default_dashboard': 'nova',
|
||||
'user_home': 'horizon.views.user_home',
|
||||
'ajax_queue_limit': 10,
|
||||
'help_url': "http://docs.openstack.org"
|
||||
'help_url': "http://docs.openstack.org",
|
||||
'exceptions': {'recoverable': exceptions.RECOVERABLE,
|
||||
'not_found': exceptions.NOT_FOUND,
|
||||
'unauthorized': exceptions.UNAUTHORIZED},
|
||||
}
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
|
Loading…
Reference in New Issue
Block a user