~ubuntu-branches/ubuntu/utopic/cinder/utopic

« back to all changes in this revision

Viewing changes to cinder/brick/exception.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Adam Gandelman, Chuck Short
  • Date: 2013-09-08 21:09:46 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20130908210946-3dbzq1jy5uji4wad
Tags: 1:2013.2~b3-0ubuntu1
[ James Page ]
* d/control: Switch ceph-common -> python-ceph inline with upstream
  refactoring of Ceph RBD driver, move to Suggests of python-cinder.
  (LP: #1190791). 

[ Adam Gandelman ]
* debian/patches/avoid_paramiko_vers_depends.patch: Dropped, no longer
  required.
* Add minimum requirement python-greenlet (>= 0.3.2).
* Add minimum requirement python-eventlet (>= 0.12.0).
* Add minimum requirement python-paramiko (>= 1.8).

[ Chuck Short ]
* New upstream release.
* debian/patches/skip-sqlachemy-failures.patch: Skip testfailures
  with sqlalchemy 0.8 until they are fixed upstream.
* debian/control: Add python-babel to build-depends.
* debian/control: Add python-novaclient to build-depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
 
4
#
 
5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
6
#    not use this file except in compliance with the License. You may obtain
 
7
#    a copy of the License at
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
11
#    Unless required by applicable law or agreed to in writing, software
 
12
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
13
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
14
#    License for the specific language governing permissions and limitations
 
15
#    under the License.
 
16
 
 
17
"""Exceptions for the Brick library."""
 
18
 
 
19
import sys
 
20
 
 
21
from oslo.config import cfg
 
22
 
 
23
from cinder.openstack.common.gettextutils import _
 
24
from cinder.openstack.common import log as logging
 
25
 
 
26
 
 
27
LOG = logging.getLogger(__name__)
 
28
 
 
29
CONF = cfg.CONF
 
30
 
 
31
 
 
32
class BrickException(Exception):
 
33
    """Base Brick Exception
 
34
 
 
35
    To correctly use this class, inherit from it and define
 
36
    a 'msg_fmt' property. That msg_fmt will get printf'd
 
37
    with the keyword arguments provided to the constructor.
 
38
    """
 
39
    msg_fmt = _("An unknown exception occurred.")
 
40
    code = 500
 
41
    headers = {}
 
42
    safe = False
 
43
 
 
44
    def __init__(self, message=None, **kwargs):
 
45
        self.kwargs = kwargs
 
46
 
 
47
        if 'code' not in self.kwargs:
 
48
            try:
 
49
                self.kwargs['code'] = self.code
 
50
            except AttributeError:
 
51
                pass
 
52
 
 
53
        if not message:
 
54
            try:
 
55
                message = self.msg_fmt % kwargs
 
56
 
 
57
            except Exception:
 
58
                exc_info = sys.exc_info()
 
59
                # kwargs doesn't match a variable in the message
 
60
                # log the issue and the kwargs
 
61
                LOG.exception(_('Exception in string format operation'))
 
62
                for name, value in kwargs.iteritems():
 
63
                    LOG.error("%s: %s" % (name, value))
 
64
 
 
65
                if CONF.fatal_exception_format_errors:
 
66
                    raise exc_info[0], exc_info[1], exc_info[2]
 
67
                else:
 
68
                    # at least get the core message out if something happened
 
69
                    message = self.msg_fmt
 
70
 
 
71
        super(BrickException, self).__init__(message)
 
72
 
 
73
 
 
74
class NotFound(BrickException):
 
75
    message = _("Resource could not be found.")
 
76
    code = 404
 
77
    safe = True
 
78
 
 
79
 
 
80
class Invalid(BrickException):
 
81
    message = _("Unacceptable parameters.")
 
82
    code = 400
 
83
 
 
84
 
 
85
# Cannot be templated as the error syntax varies.
 
86
# msg needs to be constructed when raised.
 
87
class InvalidParameterValue(Invalid):
 
88
    message = _("%(err)s")
 
89
 
 
90
 
 
91
class NoFibreChannelHostsFound(BrickException):
 
92
    message = _("We are unable to locate any Fibre Channel devices.")
 
93
 
 
94
 
 
95
class NoFibreChannelVolumeDeviceFound(BrickException):
 
96
    message = _("Unable to find a Fibre Channel volume device.")
 
97
 
 
98
 
 
99
class VolumeDeviceNotFound(BrickException):
 
100
    message = _("Volume device not found at %(device)s.")
 
101
 
 
102
 
 
103
class ISERTargetCreateFailed(BrickException):
 
104
    message = _("Failed to create iser target for volume %(volume_id)s.")
 
105
 
 
106
 
 
107
class ISERTargetRemoveFailed(BrickException):
 
108
    message = _("Failed to remove iser target for volume %(volume_id)s.")
 
109
 
 
110
 
 
111
class VolumeGroupNotFound(BrickException):
 
112
    message = _('Unable to find Volume Group: %(vg_name)s')
 
113
 
 
114
 
 
115
class VolumeGroupCreationFailed(BrickException):
 
116
    message = _('Failed to create Volume Group: %(vg_name)s')
 
117
 
 
118
 
 
119
class ISCSITargetCreateFailed(BrickException):
 
120
    message = _("Failed to create iscsi target for volume %(volume_id)s.")
 
121
 
 
122
 
 
123
class ISCSITargetRemoveFailed(BrickException):
 
124
    message = _("Failed to remove iscsi target for volume %(volume_id)s.")
 
125
 
 
126
 
 
127
class ISCSITargetAttachFailed(BrickException):
 
128
    message = _("Failed to attach iSCSI target for volume %(volume_id)s.")