1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
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
9
# http://www.apache.org/licenses/LICENSE-2.0
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
17
"""Exceptions for the Brick library."""
21
from oslo.config import cfg
23
from cinder.openstack.common.gettextutils import _
24
from cinder.openstack.common import log as logging
27
LOG = logging.getLogger(__name__)
32
class BrickException(Exception):
33
"""Base Brick Exception
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.
39
msg_fmt = _("An unknown exception occurred.")
44
def __init__(self, message=None, **kwargs):
47
if 'code' not in self.kwargs:
49
self.kwargs['code'] = self.code
50
except AttributeError:
55
message = self.msg_fmt % kwargs
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))
65
if CONF.fatal_exception_format_errors:
66
raise exc_info[0], exc_info[1], exc_info[2]
68
# at least get the core message out if something happened
69
message = self.msg_fmt
71
super(BrickException, self).__init__(message)
74
class NotFound(BrickException):
75
message = _("Resource could not be found.")
80
class Invalid(BrickException):
81
message = _("Unacceptable parameters.")
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")
91
class NoFibreChannelHostsFound(BrickException):
92
message = _("We are unable to locate any Fibre Channel devices.")
95
class NoFibreChannelVolumeDeviceFound(BrickException):
96
message = _("Unable to find a Fibre Channel volume device.")
99
class VolumeDeviceNotFound(BrickException):
100
message = _("Volume device not found at %(device)s.")
103
class ISERTargetCreateFailed(BrickException):
104
message = _("Failed to create iser target for volume %(volume_id)s.")
107
class ISERTargetRemoveFailed(BrickException):
108
message = _("Failed to remove iser target for volume %(volume_id)s.")
111
class VolumeGroupNotFound(BrickException):
112
message = _('Unable to find Volume Group: %(vg_name)s')
115
class VolumeGroupCreationFailed(BrickException):
116
message = _('Failed to create Volume Group: %(vg_name)s')
119
class ISCSITargetCreateFailed(BrickException):
120
message = _("Failed to create iscsi target for volume %(volume_id)s.")
123
class ISCSITargetRemoveFailed(BrickException):
124
message = _("Failed to remove iscsi target for volume %(volume_id)s.")
127
class ISCSITargetAttachFailed(BrickException):
128
message = _("Failed to attach iSCSI target for volume %(volume_id)s.")