Example #1
0
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
Example #2
0
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)
Example #3
0
    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)
Example #4
0
        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)
Example #5
0
class FlavorNotFound(ResourceNotFound):
    """The code here changed to 400 according to the latest document."""
    message = _("Unable to find flavor %(flavor)s.")
    code = 400
Example #6
0
class Urllib2InvalidScheme(MagnumException):
    message = _("The urllib2 URL %(url)s has an invalid scheme.")
Example #7
0
class UnsupportedDockerQuantityFormat(MagnumException):
    message = _("Unsupported quantity format for Swarm cluster.")
Example #8
0
class RegionsListFailed(MagnumException):
    message = _("Failed to list regions.")
Example #9
0
class CertificatesToClusterFailed(MagnumException):
    message = _("Failed to create certificates for Cluster: %(cluster_uuid)s")
Example #10
0
class TrustDeleteFailed(MagnumException):
    message = _("Failed to delete trust %(trust_id)s.")
Example #11
0
class TrusteeDeleteFailed(MagnumException):
    message = _("Failed to delete trustee %(trustee_id)s")
Example #12
0
class X509KeyPairAlreadyExists(Conflict):
    message = _("A key pair with UUID %(uuid)s already exists.")
Example #13
0
class CertificateStorageException(MagnumException):
    message = _("Could not store certificate: %(msg)s")
Example #14
0
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
Example #15
0
class X509KeyPairNotFound(ResourceNotFound):
    message = _("A key pair %(x509keypair)s could not be found.")
Example #16
0
class ImageNotAuthorized(MagnumException):
    message = _("Not authorized for image %(image_id)s.")
Example #17
0
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
Example #18
0
class OperationInProgress(Invalid):
    message = _("Cluster %(cluster_name)s already has an operation in "
                "progress.")
Example #19
0
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
Example #20
0
class CertificateValidationError(Invalid):
    message = _("Extension '%(extension)s' not allowed")
Example #21
0
class TrustCreateFailed(MagnumException):
    message = _("Failed to create trust for trustee %(trustee_user_id)s.")
Example #22
0
class KeyPairNotFound(ResourceNotFound):
    message = _("Unable to find keypair %(keypair)s.")
Example #23
0
class TrusteeCreateFailed(MagnumException):
    message = _("Failed to create trustee %(username)s "
                "in domain %(domain_id)s")
Example #24
0
class ClusterTypeNotEnabled(MagnumException):
    message = _("Cluster type (%(server_type)s, %(os)s, %(coe)s)"
                " not enabled.")
Example #25
0
class QuotaAlreadyExists(Conflict):
    message = _("Quota for project %(project_id)s already exists "
                "for resource %(resource)s.")
Example #26
0
class MagnumServiceAlreadyExists(Conflict):
    message = _("A magnum service with ID %(id)s already exists.")
Example #27
0
class TrusteeOrTrustToClusterFailed(MagnumException):
    message = _("Failed to create trustee or trust for Cluster: "
                "%(cluster_uuid)s")
Example #28
0
class UnsupportedK8sQuantityFormat(MagnumException):
    message = _("Unsupported quantity format for k8s cluster.")
Example #29
0
class MagnumServiceNotFound(ResourceNotFound):
    message = _("A magnum service %(magnum_service_id)s could not be found.")
Example #30
0
class RequiredParameterNotProvided(MagnumException):
    message = _("Required parameter %(heat_param)s not provided.")