summaryrefslogtreecommitdiff
path: root/glance_store/exceptions.py
blob: 448e7548a460d8d4ebb4f0776f9ccf3e0eb53659 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Copyright (c) 2014 Red Hat, 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.

"""Glance Store exception subclasses"""

import urllib.parse

from glance_store.i18n import _


class BackendException(Exception):
    pass


class UnsupportedBackend(BackendException):
    pass


class RedirectException(Exception):
    def __init__(self, url):
        self.url = urllib.parse.urlparse(url)


class GlanceStoreException(Exception):
    """
    Base Glance Store Exception

    To correctly use this class, inherit from it and define
    a 'message' property. That message will get printf'd
    with the keyword arguments provided to the constructor.
    """
    message = _("An unknown exception occurred")

    def __init__(self, message=None, **kwargs):
        if not message:
            message = self.message
        try:
            if kwargs:
                message = message % kwargs
        except Exception:
            pass
        self.msg = message
        super(GlanceStoreException, self).__init__(message)


class MissingCredentialError(GlanceStoreException):
    message = _("Missing required credential: %(required)s")


class BadAuthStrategy(GlanceStoreException):
    message = _("Incorrect auth strategy, expected \"%(expected)s\" but "
                "received \"%(received)s\"")


class AuthorizationRedirect(GlanceStoreException):
    message = _("Redirecting to %(uri)s for authorization.")


class NotFound(GlanceStoreException):
    message = _("Image %(image)s not found")


class UnknownHashingAlgo(GlanceStoreException):
    message = _("Unknown hashing algorithm identifier: %(algo)s")


class UnknownScheme(GlanceStoreException):
    message = _("Unknown scheme '%(scheme)s' found in URI")


class BadStoreUri(GlanceStoreException):
    message = _("The Store URI was malformed: %(uri)s")


class Duplicate(GlanceStoreException):
    message = _("Image %(image)s already exists")


class StorageFull(GlanceStoreException):
    message = _("There is not enough disk space on the image storage media.")


class StorageWriteDenied(GlanceStoreException):
    message = _("Permission to write image storage media denied.")


class AuthBadRequest(GlanceStoreException):
    message = _("Connect error/bad request to Auth service at URL %(url)s.")


class AuthUrlNotFound(GlanceStoreException):
    message = _("Auth service at URL %(url)s not found.")


class AuthorizationFailure(GlanceStoreException):
    message = _("Authorization failed.")


class NotAuthenticated(GlanceStoreException):
    message = _("You are not authenticated.")


class Forbidden(GlanceStoreException):
    message = _("You are not authorized to complete this action.")


class Invalid(GlanceStoreException):
    # NOTE(NiallBunting) This could be deprecated however the debtcollector
    # seems to have problems deprecating this as well as the subclasses.
    message = _("Data supplied was not valid.")


class BadStoreConfiguration(GlanceStoreException):
    message = _("Store %(store_name)s could not be configured correctly. "
                "Reason: %(reason)s")


class DriverLoadFailure(GlanceStoreException):
    message = _("Driver %(driver_name)s could not be loaded.")


class StoreDeleteNotSupported(GlanceStoreException):
    message = _("Deleting images from this store is not supported.")


class StoreGetNotSupported(GlanceStoreException):
    message = _("Getting images from this store is not supported.")


class StoreRandomGetNotSupported(StoreGetNotSupported):
    message = _("Getting images randomly from this store is not supported. "
                "Offset: %(offset)s, length: %(chunk_size)s")


class StoreAddDisabled(GlanceStoreException):
    message = _("Configuration for store failed. Adding images to this "
                "store is disabled.")


class MaxRedirectsExceeded(GlanceStoreException):
    message = _("Maximum redirects (%(redirects)s) was exceeded.")


class NoServiceEndpoint(GlanceStoreException):
    message = _("Response from Keystone does not contain a Glance endpoint.")


class RegionAmbiguity(GlanceStoreException):
    message = _("Multiple 'image' service matches for region %(region)s. This "
                "generally means that a region is required and you have not "
                "supplied one.")


class RemoteServiceUnavailable(GlanceStoreException):
    message = _("Remote server where the image is present is unavailable.")


class HasSnapshot(GlanceStoreException):
    message = _("The image cannot be deleted because it has snapshot(s).")


class InUseByStore(GlanceStoreException):
    message = _("The image cannot be deleted because it is in use through "
                "the backend store outside of Glance.")


class HostNotInitialized(GlanceStoreException):
    message = _("The glance cinder store host %(host)s which will used to "
                "perform nfs mount/umount operations isn't initialized.")