"Fossies" - the Fresh Open Source Software Archive

Member "glance-19.0.0/glance/common/exception.py" (16 Oct 2019, 14568 Bytes) of package /linux/misc/openstack/glance-19.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "exception.py" see the Fossies "Dox" file reference documentation.

    1 # Copyright 2010 United States Government as represented by the
    2 # Administrator of the National Aeronautics and Space Administration.
    3 # All Rights Reserved.
    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 """Glance exception subclasses"""
   18 
   19 import six
   20 import six.moves.urllib.parse as urlparse
   21 
   22 from glance.i18n import _
   23 
   24 _FATAL_EXCEPTION_FORMAT_ERRORS = False
   25 
   26 
   27 class RedirectException(Exception):
   28     def __init__(self, url):
   29         self.url = urlparse.urlparse(url)
   30 
   31 
   32 class GlanceException(Exception):
   33     """
   34     Base Glance Exception
   35 
   36     To correctly use this class, inherit from it and define
   37     a 'message' property. That message will get printf'd
   38     with the keyword arguments provided to the constructor.
   39     """
   40     message = _("An unknown exception occurred")
   41 
   42     def __init__(self, message=None, *args, **kwargs):
   43         if not message:
   44             message = self.message
   45         try:
   46             if kwargs:
   47                 message = message % kwargs
   48         except Exception:
   49             if _FATAL_EXCEPTION_FORMAT_ERRORS:
   50                 raise
   51             else:
   52                 # at least get the core message out if something happened
   53                 pass
   54         self.msg = message
   55         super(GlanceException, self).__init__(message)
   56 
   57     def __unicode__(self):
   58         # NOTE(flwang): By default, self.msg is an instance of Message, which
   59         # can't be converted by str(). Based on the definition of
   60         # __unicode__, it should return unicode always.
   61         return six.text_type(self.msg)
   62 
   63 
   64 class MissingCredentialError(GlanceException):
   65     message = _("Missing required credential: %(required)s")
   66 
   67 
   68 class BadAuthStrategy(GlanceException):
   69     message = _("Incorrect auth strategy, expected \"%(expected)s\" but "
   70                 "received \"%(received)s\"")
   71 
   72 
   73 class NotFound(GlanceException):
   74     message = _("An object with the specified identifier was not found.")
   75 
   76 
   77 class BadStoreUri(GlanceException):
   78     message = _("The Store URI was malformed.")
   79 
   80 
   81 class Duplicate(GlanceException):
   82     message = _("An object with the same identifier already exists.")
   83 
   84 
   85 class Conflict(GlanceException):
   86     message = _("An object with the same identifier is currently being "
   87                 "operated on.")
   88 
   89 
   90 class StorageQuotaFull(GlanceException):
   91     message = _("The size of the data %(image_size)s will exceed the limit. "
   92                 "%(remaining)s bytes remaining.")
   93 
   94 
   95 class AuthBadRequest(GlanceException):
   96     message = _("Connect error/bad request to Auth service at URL %(url)s.")
   97 
   98 
   99 class AuthUrlNotFound(GlanceException):
  100     message = _("Auth service at URL %(url)s not found.")
  101 
  102 
  103 class AuthorizationFailure(GlanceException):
  104     message = _("Authorization failed.")
  105 
  106 
  107 class NotAuthenticated(GlanceException):
  108     message = _("You are not authenticated.")
  109 
  110 
  111 class UploadException(GlanceException):
  112     message = _('Image upload problem: %s')
  113 
  114 
  115 class Forbidden(GlanceException):
  116     message = _("You are not authorized to complete %(action)s action.")
  117 
  118 
  119 class ForbiddenPublicImage(Forbidden):
  120     message = _("You are not authorized to complete this action.")
  121 
  122 
  123 class ProtectedImageDelete(Forbidden):
  124     message = _("Image %(image_id)s is protected and cannot be deleted.")
  125 
  126 
  127 class ProtectedMetadefNamespaceDelete(Forbidden):
  128     message = _("Metadata definition namespace %(namespace)s is protected"
  129                 " and cannot be deleted.")
  130 
  131 
  132 class ProtectedMetadefNamespacePropDelete(Forbidden):
  133     message = _("Metadata definition property %(property_name)s is protected"
  134                 " and cannot be deleted.")
  135 
  136 
  137 class ProtectedMetadefObjectDelete(Forbidden):
  138     message = _("Metadata definition object %(object_name)s is protected"
  139                 " and cannot be deleted.")
  140 
  141 
  142 class ProtectedMetadefResourceTypeAssociationDelete(Forbidden):
  143     message = _("Metadata definition resource-type-association"
  144                 " %(resource_type)s is protected and cannot be deleted.")
  145 
  146 
  147 class ProtectedMetadefResourceTypeSystemDelete(Forbidden):
  148     message = _("Metadata definition resource-type %(resource_type_name)s is"
  149                 " a seeded-system type and cannot be deleted.")
  150 
  151 
  152 class ProtectedMetadefTagDelete(Forbidden):
  153     message = _("Metadata definition tag %(tag_name)s is protected"
  154                 " and cannot be deleted.")
  155 
  156 
  157 class Invalid(GlanceException):
  158     message = _("Data supplied was not valid.")
  159 
  160 
  161 class InvalidSortKey(Invalid):
  162     message = _("Sort key supplied was not valid.")
  163 
  164 
  165 class InvalidSortDir(Invalid):
  166     message = _("Sort direction supplied was not valid.")
  167 
  168 
  169 class InvalidPropertyProtectionConfiguration(Invalid):
  170     message = _("Invalid configuration in property protection file.")
  171 
  172 
  173 class InvalidSwiftStoreConfiguration(Invalid):
  174     message = _("Invalid configuration in glance-swift conf file.")
  175 
  176 
  177 class InvalidFilterOperatorValue(Invalid):
  178     message = _("Unable to filter using the specified operator.")
  179 
  180 
  181 class InvalidFilterRangeValue(Invalid):
  182     message = _("Unable to filter using the specified range.")
  183 
  184 
  185 class InvalidOptionValue(Invalid):
  186     message = _("Invalid value for option %(option)s: %(value)s")
  187 
  188 
  189 class ReadonlyProperty(Forbidden):
  190     message = _("Attribute '%(property)s' is read-only.")
  191 
  192 
  193 class ReservedProperty(Forbidden):
  194     message = _("Attribute '%(property)s' is reserved.")
  195 
  196 
  197 class AuthorizationRedirect(GlanceException):
  198     message = _("Redirecting to %(uri)s for authorization.")
  199 
  200 
  201 class ClientConnectionError(GlanceException):
  202     message = _("There was an error connecting to a server")
  203 
  204 
  205 class ClientConfigurationError(GlanceException):
  206     message = _("There was an error configuring the client.")
  207 
  208 
  209 class MultipleChoices(GlanceException):
  210     message = _("The request returned a 302 Multiple Choices. This generally "
  211                 "means that you have not included a version indicator in a "
  212                 "request URI.\n\nThe body of response returned:\n%(body)s")
  213 
  214 
  215 class LimitExceeded(GlanceException):
  216     message = _("The request returned a 413 Request Entity Too Large. This "
  217                 "generally means that rate limiting or a quota threshold was "
  218                 "breached.\n\nThe response body:\n%(body)s")
  219 
  220     def __init__(self, *args, **kwargs):
  221         self.retry_after = (int(kwargs['retry']) if kwargs.get('retry')
  222                             else None)
  223         super(LimitExceeded, self).__init__(*args, **kwargs)
  224 
  225 
  226 class ServiceUnavailable(GlanceException):
  227     message = _("The request returned 503 Service Unavailable. This "
  228                 "generally occurs on service overload or other transient "
  229                 "outage.")
  230 
  231     def __init__(self, *args, **kwargs):
  232         self.retry_after = (int(kwargs['retry']) if kwargs.get('retry')
  233                             else None)
  234         super(ServiceUnavailable, self).__init__(*args, **kwargs)
  235 
  236 
  237 class ServerError(GlanceException):
  238     message = _("The request returned 500 Internal Server Error.")
  239 
  240 
  241 class UnexpectedStatus(GlanceException):
  242     message = _("The request returned an unexpected status: %(status)s."
  243                 "\n\nThe response body:\n%(body)s")
  244 
  245 
  246 class InvalidContentType(GlanceException):
  247     message = _("Invalid content type %(content_type)s")
  248 
  249 
  250 class BadRegistryConnectionConfiguration(GlanceException):
  251     message = _("Registry was not configured correctly on API server. "
  252                 "Reason: %(reason)s")
  253 
  254 
  255 class BadDriverConfiguration(GlanceException):
  256     message = _("Driver %(driver_name)s could not be configured correctly. "
  257                 "Reason: %(reason)s")
  258 
  259 
  260 class MaxRedirectsExceeded(GlanceException):
  261     message = _("Maximum redirects (%(redirects)s) was exceeded.")
  262 
  263 
  264 class InvalidRedirect(GlanceException):
  265     message = _("Received invalid HTTP redirect.")
  266 
  267 
  268 class NoServiceEndpoint(GlanceException):
  269     message = _("Response from Keystone does not contain a Glance endpoint.")
  270 
  271 
  272 class RegionAmbiguity(GlanceException):
  273     message = _("Multiple 'image' service matches for region %(region)s. This "
  274                 "generally means that a region is required and you have not "
  275                 "supplied one.")
  276 
  277 
  278 class WorkerCreationFailure(GlanceException):
  279     message = _("Server worker creation failed: %(reason)s.")
  280 
  281 
  282 class SchemaLoadError(GlanceException):
  283     message = _("Unable to load schema: %(reason)s")
  284 
  285 
  286 class InvalidObject(GlanceException):
  287     message = _("Provided object does not match schema "
  288                 "'%(schema)s': %(reason)s")
  289 
  290 
  291 class ImageSizeLimitExceeded(GlanceException):
  292     message = _("The provided image is too large.")
  293 
  294 
  295 class FailedToGetScrubberJobs(GlanceException):
  296     message = _("Scrubber encountered an error while trying to fetch "
  297                 "scrub jobs.")
  298 
  299 
  300 class ImageMemberLimitExceeded(LimitExceeded):
  301     message = _("The limit has been exceeded on the number of allowed image "
  302                 "members for this image. Attempted: %(attempted)s, "
  303                 "Maximum: %(maximum)s")
  304 
  305 
  306 class ImagePropertyLimitExceeded(LimitExceeded):
  307     message = _("The limit has been exceeded on the number of allowed image "
  308                 "properties. Attempted: %(attempted)s, Maximum: %(maximum)s")
  309 
  310 
  311 class ImageTagLimitExceeded(LimitExceeded):
  312     message = _("The limit has been exceeded on the number of allowed image "
  313                 "tags. Attempted: %(attempted)s, Maximum: %(maximum)s")
  314 
  315 
  316 class ImageLocationLimitExceeded(LimitExceeded):
  317     message = _("The limit has been exceeded on the number of allowed image "
  318                 "locations. Attempted: %(attempted)s, Maximum: %(maximum)s")
  319 
  320 
  321 class SIGHUPInterrupt(GlanceException):
  322     message = _("System SIGHUP signal received.")
  323 
  324 
  325 class RPCError(GlanceException):
  326     message = _("%(cls)s exception was raised in the last rpc call: %(val)s")
  327 
  328 
  329 class TaskException(GlanceException):
  330     message = _("An unknown task exception occurred")
  331 
  332 
  333 class BadTaskConfiguration(GlanceException):
  334     message = _("Task was not configured properly")
  335 
  336 
  337 class ImageNotFound(NotFound):
  338     message = _("Image with the given id %(image_id)s was not found")
  339 
  340 
  341 class TaskNotFound(TaskException, NotFound):
  342     message = _("Task with the given id %(task_id)s was not found")
  343 
  344 
  345 class InvalidTaskStatus(TaskException, Invalid):
  346     message = _("Provided status of task is unsupported: %(status)s")
  347 
  348 
  349 class InvalidTaskType(TaskException, Invalid):
  350     message = _("Provided type of task is unsupported: %(type)s")
  351 
  352 
  353 class InvalidTaskStatusTransition(TaskException, Invalid):
  354     message = _("Status transition from %(cur_status)s to"
  355                 " %(new_status)s is not allowed")
  356 
  357 
  358 class ImportTaskError(TaskException, Invalid):
  359     message = _("An import task exception occurred")
  360 
  361 
  362 class DuplicateLocation(Duplicate):
  363     message = _("The location %(location)s already exists")
  364 
  365 
  366 class InvalidParameterValue(Invalid):
  367     message = _("Invalid value '%(value)s' for parameter '%(param)s': "
  368                 "%(extra_msg)s")
  369 
  370 
  371 class InvalidImageStatusTransition(Invalid):
  372     message = _("Image status transition from %(cur_status)s to"
  373                 " %(new_status)s is not allowed")
  374 
  375 
  376 class MetadefDuplicateNamespace(Duplicate):
  377     message = _("The metadata definition namespace=%(namespace_name)s"
  378                 " already exists.")
  379 
  380 
  381 class MetadefDuplicateObject(Duplicate):
  382     message = _("A metadata definition object with name=%(object_name)s"
  383                 " already exists in namespace=%(namespace_name)s.")
  384 
  385 
  386 class MetadefDuplicateProperty(Duplicate):
  387     message = _("A metadata definition property with name=%(property_name)s"
  388                 " already exists in namespace=%(namespace_name)s.")
  389 
  390 
  391 class MetadefDuplicateResourceType(Duplicate):
  392     message = _("A metadata definition resource-type with"
  393                 " name=%(resource_type_name)s already exists.")
  394 
  395 
  396 class MetadefDuplicateResourceTypeAssociation(Duplicate):
  397     message = _("The metadata definition resource-type association of"
  398                 " resource-type=%(resource_type_name)s to"
  399                 " namespace=%(namespace_name)s"
  400                 " already exists.")
  401 
  402 
  403 class MetadefDuplicateTag(Duplicate):
  404     message = _("A metadata tag with name=%(name)s"
  405                 " already exists in namespace=%(namespace_name)s."
  406                 " (Please note that metadata tag names are"
  407                 " case insensitive).")
  408 
  409 
  410 class MetadefForbidden(Forbidden):
  411     message = _("You are not authorized to complete this action.")
  412 
  413 
  414 class MetadefIntegrityError(Forbidden):
  415     message = _("The metadata definition %(record_type)s with"
  416                 " name=%(record_name)s not deleted."
  417                 " Other records still refer to it.")
  418 
  419 
  420 class MetadefNamespaceNotFound(NotFound):
  421     message = _("Metadata definition namespace=%(namespace_name)s"
  422                 " was not found.")
  423 
  424 
  425 class MetadefObjectNotFound(NotFound):
  426     message = _("The metadata definition object with"
  427                 " name=%(object_name)s was not found in"
  428                 " namespace=%(namespace_name)s.")
  429 
  430 
  431 class MetadefPropertyNotFound(NotFound):
  432     message = _("The metadata definition property with"
  433                 " name=%(property_name)s was not found in"
  434                 " namespace=%(namespace_name)s.")
  435 
  436 
  437 class MetadefResourceTypeNotFound(NotFound):
  438     message = _("The metadata definition resource-type with"
  439                 " name=%(resource_type_name)s, was not found.")
  440 
  441 
  442 class MetadefResourceTypeAssociationNotFound(NotFound):
  443     message = _("The metadata definition resource-type association of"
  444                 " resource-type=%(resource_type_name)s to"
  445                 " namespace=%(namespace_name)s,"
  446                 " was not found.")
  447 
  448 
  449 class MetadefTagNotFound(NotFound):
  450     message = _("The metadata definition tag with"
  451                 " name=%(name)s was not found in"
  452                 " namespace=%(namespace_name)s.")
  453 
  454 
  455 class InvalidDataMigrationScript(GlanceException):
  456     message = _("Invalid data migration script '%(script)s'. A valid data "
  457                 "migration script must implement functions 'has_migrations' "
  458                 "and 'migrate'.")