Example #1
0
    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
Example #2
0
    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
Example #3
0
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)
Example #4
0
 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)
Example #5
0
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)
Example #6
0
 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)
Example #7
0
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)
Example #8
0
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)
Example #9
0
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))
Example #10
0
 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
Example #11
0
 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
Example #12
0
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)
Example #13
0
    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})
Example #14
0
    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})
Example #15
0
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
Example #16
0
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
Example #17
0
class InvalidTemplateAttribute(OpenstackException):
    message = _("The Referenced Attribute (%(resource)s %(key)s)"
                " is incorrect.")
Example #18
0
class UserKeyPairMissing(OpenstackException):
    message = _("The Key (%(key_name)s) could not be found.")
Example #19
0
class InvalidTemplateReference(OpenstackException):
    message = _("The specified reference (%(resource)s %(key)s)"
                " is incorrect.")
Example #20
0
class NoServiceEndpoint(OpenstackException):
    message = _("Response from Keystone does not contain a Heat endpoint.")
Example #21
0
class ResourceNotFound(OpenstackException):
    message = _("The Resource (%(resource_name)s) could not be found "
                "in Stack %(stack_name)s.")
Example #22
0
class InvalidTenant(OpenstackException):
    message = _("Searching Tenant %(target)s "
                "from Tenant %(actual)s forbidden.")
Example #23
0
class UserParameterMissing(OpenstackException):
    message = _("The Parameter (%(key)s) was not provided.")
Example #24
0
class StackNotFound(OpenstackException):
    message = _("The Stack (%(stack_name)s) could not be found.")
Example #25
0
class MissingCredentialError(OpenstackException):
    message = _("Missing required credential: %(required)s")
Example #26
0
class WatchRuleNotFound(OpenstackException):
    message = _("The Watch Rule (%(watch_name)s) could not be found.")
Example #27
0
class StackExists(OpenstackException):
    message = _("The Stack (%(stack_name)s) already exists.")
Example #28
0
class ResourceNotAvailable(OpenstackException):
    message = _("The Resource (%(resource_name)s) is not available.")
Example #29
0
class DeprecatedConfig(Exception):
    message = _("Fatal call to deprecated config: %(msg)s")

    def __init__(self, msg):
        super(Exception, self).__init__(self.message % dict(msg=msg))
Example #30
0
class NoUniqueImageFound(OpenstackException):
    message = _("Multiple images were found with name (%(image_name)s).")
Example #31
0
class UnknownUserParameter(OpenstackException):
    message = _("The Parameter (%(key)s) was not defined in template.")
Example #32
0
class ImageNotFound(OpenstackException):
    message = _("The Image (%(image_name)s) could not be found.")
Example #33
0
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.")
Example #34
0
class FlavorMissing(OpenstackException):
    message = _("The Flavor ID (%(flavor_id)s) could not be found.")
Example #35
0
class PhysicalResourceNotFound(OpenstackException):
    message = _("The Resource (%(resource_id)s) could not be found.")
Example #36
0
class StackValidationFailed(OpenstackException):
    message = _("%(message)s")