def _get_ssl_configs(use_ssl): if use_ssl: cert_file = CONF.api.ssl_cert_file key_file = CONF.api.ssl_key_file if cert_file and not os.path.exists(cert_file): raise RuntimeError(_("Unable to find cert_file : %s") % cert_file) if key_file and not os.path.exists(key_file): raise RuntimeError(_("Unable to find key_file : %s") % key_file) return cert_file, key_file else: return None
class MagnumException(Exception): """Base Magnum 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.") code = 500 def __init__(self, message=None, **kwargs): self.kwargs = kwargs if 'code' not in self.kwargs and hasattr(self, 'code'): self.kwargs['code'] = self.code if message: self.message = message try: self.message = self.message % kwargs except Exception: # kwargs doesn't match a variable in the message # log the issue and the kwargs LOG.exception( _LE('Exception in string format operation, ' 'kwargs: %s') % kwargs) try: if CONF.fatal_exception_format_errors: raise except cfg.NoSuchOptError: # Note: work around for Bug: #1447873 if CONF.oslo_versionedobjects.fatal_exception_format_errors: raise super(MagnumException, self).__init__(self.message) def __str__(self): if six.PY3: return self.message return self.message.encode('utf-8') def __unicode__(self): return self.message def format_message(self): if self.__class__.__name__.endswith('_Remote'): return self.args[0] else: return six.text_type(self)
def __init__(self, app, conf, public_api_routes=None): if public_api_routes is None: public_api_routes = [] route_pattern_tpl = '%s(\.json)?$' try: self.public_api_routes = [ re.compile(route_pattern_tpl % route_tpl) for route_tpl in public_api_routes ] except re.error as e: msg = _('Cannot compile public API routes: %s') % e LOG.error(msg) raise exception.ConfigInvalid(error_msg=msg) super(AuthTokenMiddleware, self).__init__(app, conf)
def replacement_start_response(status, headers, exc_info=None): """Overrides the default response to make errors parsable.""" try: status_code = int(status.split(' ')[0]) state['status_code'] = status_code except (ValueError, TypeError): # pragma: nocover raise Exception( _('ErrorDocumentMiddleware received an invalid ' 'status %s') % status) else: if (state['status_code'] // 100) not in (2, 3): # Remove some headers so we can replace them later # when we have the full error message and can # compute the length. headers = [(h, v) for (h, v) in headers if h not in ('Content-Length', 'Content-Type')] # Save the headers in case we need to modify them. state['headers'] = headers return start_response(status, headers, exc_info)
class FlavorNotFound(ResourceNotFound): """The code here changed to 400 according to the latest document.""" message = _("Unable to find flavor %(flavor)s.") code = 400
class Urllib2InvalidScheme(MagnumException): message = _("The urllib2 URL %(url)s has an invalid scheme.")
class UnsupportedDockerQuantityFormat(MagnumException): message = _("Unsupported quantity format for Swarm cluster.")
class RegionsListFailed(MagnumException): message = _("Failed to list regions.")
class CertificatesToClusterFailed(MagnumException): message = _("Failed to create certificates for Cluster: %(cluster_uuid)s")
class TrustDeleteFailed(MagnumException): message = _("Failed to delete trust %(trust_id)s.")
class TrusteeDeleteFailed(MagnumException): message = _("Failed to delete trustee %(trustee_id)s")
class X509KeyPairAlreadyExists(Conflict): message = _("A key pair with UUID %(uuid)s already exists.")
class CertificateStorageException(MagnumException): message = _("Could not store certificate: %(msg)s")
class OSDistroFieldNotFound(ResourceNotFound): """The code here changed to 400 according to the latest document.""" message = _("Image %(image_id)s doesn't contain os_distro field.") code = 400
class X509KeyPairNotFound(ResourceNotFound): message = _("A key pair %(x509keypair)s could not be found.")
class ImageNotAuthorized(MagnumException): message = _("Not authorized for image %(image_id)s.")
class ImageNotFound(ResourceNotFound): """The code here changed to 400 according to the latest document.""" message = _("Image %(image_id)s could not be found.") code = 400
class OperationInProgress(Invalid): message = _("Cluster %(cluster_name)s already has an operation in " "progress.")
class ExternalNetworkNotFound(ResourceNotFound): """The code here changed to 400 according to the latest document.""" """"Ensure the network is not private.""" message = _("Unable to find external network %(network)s.") code = 400
class CertificateValidationError(Invalid): message = _("Extension '%(extension)s' not allowed")
class TrustCreateFailed(MagnumException): message = _("Failed to create trust for trustee %(trustee_user_id)s.")
class KeyPairNotFound(ResourceNotFound): message = _("Unable to find keypair %(keypair)s.")
class TrusteeCreateFailed(MagnumException): message = _("Failed to create trustee %(username)s " "in domain %(domain_id)s")
class ClusterTypeNotEnabled(MagnumException): message = _("Cluster type (%(server_type)s, %(os)s, %(coe)s)" " not enabled.")
class QuotaAlreadyExists(Conflict): message = _("Quota for project %(project_id)s already exists " "for resource %(resource)s.")
class MagnumServiceAlreadyExists(Conflict): message = _("A magnum service with ID %(id)s already exists.")
class TrusteeOrTrustToClusterFailed(MagnumException): message = _("Failed to create trustee or trust for Cluster: " "%(cluster_uuid)s")
class UnsupportedK8sQuantityFormat(MagnumException): message = _("Unsupported quantity format for k8s cluster.")
class MagnumServiceNotFound(ResourceNotFound): message = _("A magnum service %(magnum_service_id)s could not be found.")
class RequiredParameterNotProvided(MagnumException): message = _("Required parameter %(heat_param)s not provided.")