Пример #1
0
    def retry_request(self, method, action, body=None,
                      headers=None, params=None):
        """Call do_request with the default retry configuration.

        Only idempotent requests should retry failed connection attempts.
        :raises: ConnectionFailed if the maximum # of retries is exceeded
        """
        max_attempts = self.retries + 1
        for i in range(max_attempts):
            try:
                return self.do_request(method, action, body=body,
                                       headers=headers, params=params)
            except exceptions.ConnectionFailed:
                # Exception has already been logged by do_request()
                if i < self.retries:
                    _logger.debug('Retrying connection to vnfsvc service')
                    time.sleep(self.retry_interval)
                elif self.raise_errors:
                    raise

        if self.retries:
            msg = (_("Failed to connect to vnfsvc server after %d attempts")
                   % max_attempts)
        else:
            msg = _("Failed to connect vnfsvc server")

        raise exceptions.ConnectionFailed(reason=msg)
Пример #2
0
    def retry_request(self,
                      method,
                      action,
                      body=None,
                      headers=None,
                      params=None):
        """Call do_request with the default retry configuration.

        Only idempotent requests should retry failed connection attempts.
        :raises: ConnectionFailed if the maximum # of retries is exceeded
        """
        max_attempts = self.retries + 1
        for i in range(max_attempts):
            try:
                return self.do_request(method,
                                       action,
                                       body=body,
                                       headers=headers,
                                       params=params)
            except exceptions.ConnectionFailed:
                # Exception has already been logged by do_request()
                if i < self.retries:
                    _logger.debug('Retrying connection to vnfsvc service')
                    time.sleep(self.retry_interval)
                elif self.raise_errors:
                    raise

        if self.retries:
            msg = (_("Failed to connect to vnfsvc server after %d attempts") %
                   max_attempts)
        else:
            msg = _("Failed to connect vnfsvc server")

        raise exceptions.ConnectionFailed(reason=msg)
Пример #3
0
    def serialize(self, data):
        """Serializes a dictionary into either XML or JSON.

        A dictionary with a single key can be passed and
        it can contain any structure.
        """
        if data is None:
            return None
        elif type(data) is dict:
            return serializer.Serializer(
                self.get_attr_metadata()).serialize(data, self.content_type())
        else:
            raise Exception(_("Unable to serialize object of type = '%s'") %
                            type(data))
Пример #4
0
    def serialize(self, data):
        """Serializes a dictionary into either XML or JSON.

        A dictionary with a single key can be passed and
        it can contain any structure.
        """
        if data is None:
            return None
        elif type(data) is dict:
            return serializer.Serializer(self.get_attr_metadata()).serialize(
                data, self.content_type())
        else:
            raise Exception(
                _("Unable to serialize object of type = '%s'") % type(data))
Пример #5
0
def get_client_class(api_name, version, version_map):
    """Returns the client class for the requested API version

    :param api_name: the name of the API, e.g. 'compute', 'image', etc
    :param version: the requested API version
    :param version_map: a dict of client classes keyed by version
    :rtype: a client class for the requested API version
    """
    try:
        client_path = version_map[str(version)]
    except (KeyError, ValueError):
        msg = _("Invalid %(api_name)s client version '%(version)s'. must be "
                "one of: %(map_keys)s")
        msg = msg % {'api_name': api_name, 'version': version,
                     'map_keys': ', '.join(version_map.keys())}
        raise exceptions.UnsupportedVersion(msg)

    return import_class(client_path)
Пример #6
0
def get_client_class(api_name, version, version_map):
    """Returns the client class for the requested API version

    :param api_name: the name of the API, e.g. 'compute', 'image', etc
    :param version: the requested API version
    :param version_map: a dict of client classes keyed by version
    :rtype: a client class for the requested API version
    """
    try:
        client_path = version_map[str(version)]
    except (KeyError, ValueError):
        msg = _("Invalid %(api_name)s client version '%(version)s'. must be "
                "one of: %(map_keys)s")
        msg = msg % {
            'api_name': api_name,
            'version': version,
            'map_keys': ', '.join(version_map.keys())
        }
        raise exceptions.UnsupportedVersion(msg)

    return import_class(client_path)
Пример #7
0
class VNFSvcException(Exception):
    """Base vnfsvc 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 message:
            self.message = message
        try:
            self._error_string = self.message % kwargs
        except Exception:
            # at least get the core message out if something happened
            self._error_string = self.message

    def __str__(self):
        return self._error_string
Пример #8
0
class VNFSvcClientNoUniqueMatch(VNFSvcCLIError):
    message = _("Multiple %(resource)s matches found for name '%(name)s',"
                " use an ID to be more specific.")
Пример #9
0
class EndpointTypeNotFound(VNFSvcClientException):
    message = _("Could not find endpoint type %(type_)s in Service Catalog.")
Пример #10
0
class AmbiguousEndpoints(VNFSvcClientException):
    message = _("Found more than one matching endpoint in Service Catalog: "
                "%(matching_endpoints)")
Пример #11
0
class ConnectionFailed(VNFSvcClientException):
    message = _("Connection to vnfsvc failed: %(reason)s")
Пример #12
0
class Forbidden(VNFSvcClientException):
    status_code = 403
    message = _("Forbidden: your credentials don't give you access to this "
                "resource.")
Пример #13
0
class Unauthorized(VNFSvcClientException):
    status_code = 401
    message = _("Unauthorized: bad credentials.")
Пример #14
0
class EndpointNotFound(VNFSvcClientException):
    message = _("Could not find Service or Region in Service Catalog.")
Пример #15
0
class SslCertificateValidationError(VNFSvcClientException):
    message = _("SSL certificate validation has failed: %(reason)s")
Пример #16
0
class InvalidContentType(VNFSvcClientException):
    message = _("Invalid content type %(content_type)s.")
Пример #17
0
class MalformedResponseBody(VNFSvcClientException):
    message = _("Malformed response body: %(reason)s")
Пример #18
0
class UserInputHandler(VNFSvcCLIError):
    message = _("Network Service activate only accepts either %(error_message)s")
Пример #19
0
class NoAuthURLProvided(Unauthorized):
    message = _("auth_url was not provided to the vnfsvc client")