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)
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))
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))
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)
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)
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
class VNFSvcClientNoUniqueMatch(VNFSvcCLIError): message = _("Multiple %(resource)s matches found for name '%(name)s'," " use an ID to be more specific.")
class EndpointTypeNotFound(VNFSvcClientException): message = _("Could not find endpoint type %(type_)s in Service Catalog.")
class AmbiguousEndpoints(VNFSvcClientException): message = _("Found more than one matching endpoint in Service Catalog: " "%(matching_endpoints)")
class ConnectionFailed(VNFSvcClientException): message = _("Connection to vnfsvc failed: %(reason)s")
class Forbidden(VNFSvcClientException): status_code = 403 message = _("Forbidden: your credentials don't give you access to this " "resource.")
class Unauthorized(VNFSvcClientException): status_code = 401 message = _("Unauthorized: bad credentials.")
class EndpointNotFound(VNFSvcClientException): message = _("Could not find Service or Region in Service Catalog.")
class SslCertificateValidationError(VNFSvcClientException): message = _("SSL certificate validation has failed: %(reason)s")
class InvalidContentType(VNFSvcClientException): message = _("Invalid content type %(content_type)s.")
class MalformedResponseBody(VNFSvcClientException): message = _("Malformed response body: %(reason)s")
class UserInputHandler(VNFSvcCLIError): message = _("Network Service activate only accepts either %(error_message)s")
class NoAuthURLProvided(Unauthorized): message = _("auth_url was not provided to the vnfsvc client")