def get_connect_kwargs(self): connect_kwargs = {} if self.use_ssl: if self.key_file is None: self.key_file = os.environ.get('HEAT_CLIENT_KEY_FILE') if self.cert_file is None: self.cert_file = os.environ.get('HEAT_CLIENT_CERT_FILE') if self.ca_file is None: self.ca_file = os.environ.get('HEAT_CLIENT_CA_FILE') # Check that key_file/cert_file are either both set or both unset if self.cert_file is not None and self.key_file is None: msg = _("You have selected to use SSL in connecting, " "and you have supplied a cert, " "however you have failed to supply either a " "key_file parameter or set the " "HEAT_CLIENT_KEY_FILE environ variable") raise exception.ClientConnectionError(msg) if self.key_file is not None and self.cert_file is None: msg = _("You have selected to use SSL in connecting, " "and you have supplied a key, " "however you have failed to supply either a " "cert_file parameter or set the " "HEAT_CLIENT_CERT_FILE environ variable") raise exception.ClientConnectionError(msg) if (self.key_file is not None and not os.path.exists(self.key_file)): msg = _("The key file you specified %s does not " "exist") % self.key_file raise exception.ClientConnectionError(msg) connect_kwargs['key_file'] = self.key_file if (self.cert_file is not None and not os.path.exists(self.cert_file)): msg = _("The cert file you specified %s does not " "exist") % self.cert_file raise exception.ClientConnectionError(msg) connect_kwargs['cert_file'] = self.cert_file if (self.ca_file is not None and not os.path.exists(self.ca_file)): msg = _("The CA file you specified %s does not " "exist") % self.ca_file raise exception.ClientConnectionError(msg) if self.ca_file is None: for ca in self.DEFAULT_CA_FILE_PATH.split(":"): if os.path.exists(ca): self.ca_file = ca break connect_kwargs['ca_file'] = self.ca_file connect_kwargs['insecure'] = self.insecure return connect_kwargs
def get_plugin_from_strategy(strategy, creds=None, service_type=None): if strategy == 'noauth': return NoAuthStrategy() elif strategy == 'keystone': return KeystoneStrategy(creds, service_type) else: raise Exception(_("Unknown auth strategy '%s'") % strategy)
def deprecated(self, msg, *args, **kwargs): stdmsg = _("Deprecated: %s") % msg if CONF.fatal_deprecations: self.critical(stdmsg, *args, **kwargs) raise DeprecatedConfig(msg=stdmsg) else: self.warn(stdmsg, *args, **kwargs)
class ServiceUnavailable(OpenstackException): message = _("The request returned a 503 ServiceUnavilable. This " "generally occurs on service overload or other transient " "outage.") def __init__(self, *args, **kwargs): self.retry_after = (int(kwargs['retry']) if kwargs.get('retry') else None) super(ServiceUnavailable, self).__init__(*args, **kwargs)
class LimitExceeded(OpenstackException): message = _("The request returned a 413 Request Entity Too Large. This " "generally means that rate limiting or a quota threshold was " "breached.\n\nThe response body:\n%(body)s") def __init__(self, *args, **kwargs): self.retry_after = (int(kwargs['retry']) if kwargs.get('retry') else None) super(LimitExceeded, self).__init__(*args, **kwargs)
class ResourceFailure(OpenstackException): message = _("%(exc_type)s: %(message)s") def __init__(self, exception): if isinstance(exception, ResourceFailure): exception = getattr(exception, 'exc', exception) self.exc = exception exc_type = type(exception).__name__ super(ResourceFailure, self).__init__(exc_type=exc_type, message=str(exception))
def _wrap(*args, **kw): try: return f(*args, **kw) except Exception as e: if not isinstance(e, Error): #exc_type, exc_value, exc_traceback = sys.exc_info() logging.exception(_('Uncaught exception')) #logging.error(traceback.extract_stack(exc_traceback)) raise Error(str(e)) raise
class LogConfigError(Exception): message = _('Error loading logging config %(log_config)s: %(err_msg)s') def __init__(self, log_config, err_msg): self.log_config = log_config self.err_msg = err_msg def __str__(self): return self.message % dict(log_config=self.log_config, err_msg=self.err_msg)
def _v1_auth(self, token_url): creds = self.creds headers = {} headers['X-Auth-User'] = creds['username'] headers['X-Auth-Key'] = creds['password'] tenant = creds.get('tenant') if tenant: headers['X-Auth-Tenant'] = tenant resp, resp_body = self._do_request(token_url, 'GET', headers=headers) def _management_url(self, resp): for url_header in ('x-heat-management-url', 'x-server-management-url', 'x-heat'): try: return resp[url_header] except KeyError as e: not_found = e raise not_found if resp.status in (200, 204): try: self.management_url = _management_url(self, resp) self.auth_token = resp['x-auth-token'] except KeyError: raise exception.AuthorizationFailure() elif resp.status == 305: raise exception.AuthorizationRedirect(resp['location']) elif resp.status == 400: raise exception.AuthBadRequest(url=token_url) elif resp.status == 401: raise exception.NotAuthorized() elif resp.status == 404: raise exception.AuthUrlNotFound(url=token_url) else: status = resp.status raise Exception(_('Unexpected response: %(status)s') % {'status': resp.status})
def _v1_auth(self, token_url): creds = self.creds headers = {} headers['X-Auth-User'] = creds['username'] headers['X-Auth-Key'] = creds['password'] tenant = creds.get('tenant') if tenant: headers['X-Auth-Tenant'] = tenant resp, resp_body = self._do_request(token_url, 'GET', headers=headers) def _management_url(self, resp): for url_header in ('x-heat-management-url', 'x-server-management-url', 'x-heat'): try: return resp[url_header] except KeyError as e: not_found = e raise not_found if resp.status in (200, 204): try: self.management_url = _management_url(self, resp) self.auth_token = resp['x-auth-token'] except KeyError: raise exception.AuthorizationFailure() elif resp.status == 305: raise exception.AuthorizationRedirect(resp['location']) elif resp.status == 400: raise exception.AuthBadRequest(url=token_url) elif resp.status == 401: raise exception.NotAuthorized() elif resp.status == 404: raise exception.AuthUrlNotFound(url=token_url) else: status = resp.status raise Exception( _('Unexpected response: %(status)s') % {'status': resp.status})
def _find_facility_from_conf(): facility_names = logging.handlers.SysLogHandler.facility_names facility = getattr(logging.handlers.SysLogHandler, CONF.syslog_log_facility, None) if facility is None and CONF.syslog_log_facility in facility_names: facility = facility_names.get(CONF.syslog_log_facility) if facility is None: valid_facilities = facility_names.keys() consts = ['LOG_AUTH', 'LOG_AUTHPRIV', 'LOG_CRON', 'LOG_DAEMON', 'LOG_FTP', 'LOG_KERN', 'LOG_LPR', 'LOG_MAIL', 'LOG_NEWS', 'LOG_AUTH', 'LOG_SYSLOG', 'LOG_USER', 'LOG_UUCP', 'LOG_LOCAL0', 'LOG_LOCAL1', 'LOG_LOCAL2', 'LOG_LOCAL3', 'LOG_LOCAL4', 'LOG_LOCAL5', 'LOG_LOCAL6', 'LOG_LOCAL7'] valid_facilities.extend(consts) raise TypeError(_('syslog facility must be one of: %s') % ', '.join("'%s'" % fac for fac in valid_facilities)) return facility
def _find_facility_from_conf(): facility_names = logging.handlers.SysLogHandler.facility_names facility = getattr(logging.handlers.SysLogHandler, CONF.syslog_log_facility, None) if facility is None and CONF.syslog_log_facility in facility_names: facility = facility_names.get(CONF.syslog_log_facility) if facility is None: valid_facilities = facility_names.keys() consts = [ 'LOG_AUTH', 'LOG_AUTHPRIV', 'LOG_CRON', 'LOG_DAEMON', 'LOG_FTP', 'LOG_KERN', 'LOG_LPR', 'LOG_MAIL', 'LOG_NEWS', 'LOG_AUTH', 'LOG_SYSLOG', 'LOG_USER', 'LOG_UUCP', 'LOG_LOCAL0', 'LOG_LOCAL1', 'LOG_LOCAL2', 'LOG_LOCAL3', 'LOG_LOCAL4', 'LOG_LOCAL5', 'LOG_LOCAL6', 'LOG_LOCAL7' ] valid_facilities.extend(consts) raise TypeError( _('syslog facility must be one of: %s') % ', '.join("'%s'" % fac for fac in valid_facilities)) return facility
class InvalidTemplateAttribute(OpenstackException): message = _("The Referenced Attribute (%(resource)s %(key)s)" " is incorrect.")
class UserKeyPairMissing(OpenstackException): message = _("The Key (%(key_name)s) could not be found.")
class InvalidTemplateReference(OpenstackException): message = _("The specified reference (%(resource)s %(key)s)" " is incorrect.")
class NoServiceEndpoint(OpenstackException): message = _("Response from Keystone does not contain a Heat endpoint.")
class ResourceNotFound(OpenstackException): message = _("The Resource (%(resource_name)s) could not be found " "in Stack %(stack_name)s.")
class InvalidTenant(OpenstackException): message = _("Searching Tenant %(target)s " "from Tenant %(actual)s forbidden.")
class UserParameterMissing(OpenstackException): message = _("The Parameter (%(key)s) was not provided.")
class StackNotFound(OpenstackException): message = _("The Stack (%(stack_name)s) could not be found.")
class MissingCredentialError(OpenstackException): message = _("Missing required credential: %(required)s")
class WatchRuleNotFound(OpenstackException): message = _("The Watch Rule (%(watch_name)s) could not be found.")
class StackExists(OpenstackException): message = _("The Stack (%(stack_name)s) already exists.")
class ResourceNotAvailable(OpenstackException): message = _("The Resource (%(resource_name)s) is not available.")
class DeprecatedConfig(Exception): message = _("Fatal call to deprecated config: %(msg)s") def __init__(self, msg): super(Exception, self).__init__(self.message % dict(msg=msg))
class NoUniqueImageFound(OpenstackException): message = _("Multiple images were found with name (%(image_name)s).")
class UnknownUserParameter(OpenstackException): message = _("The Parameter (%(key)s) was not defined in template.")
class ImageNotFound(OpenstackException): message = _("The Image (%(image_name)s) could not be found.")
class RegionAmbiguity(OpenstackException): message = _("Multiple 'image' service matches for region %(region)s. This " "generally means that a region is required and you have not " "supplied one.")
class FlavorMissing(OpenstackException): message = _("The Flavor ID (%(flavor_id)s) could not be found.")
class PhysicalResourceNotFound(OpenstackException): message = _("The Resource (%(resource_id)s) could not be found.")
class StackValidationFailed(OpenstackException): message = _("%(message)s")