Exemplo n.º 1
0
def check(rule, ctxt, target=None, do_raise=True, exc=exceptions.Forbidden):
    creds = ctxt.to_dict()
    target = target or {}
    try:
        result = _ENFORCER.enforce(rule, target, creds, do_raise, exc)
    except Exception:
        result = False
        raise
    else:
        return result
    finally:
        extra = {'policy': {'rule': rule, 'target': target}}

        if result:
            LOG.info(_("Policy check succeeded for rule '%(rule)s' "
                       "on target %(target)s"), {
                           'rule': rule,
                           'target': repr(target)
                       },
                     extra=extra)
        else:
            LOG.info(_("Policy check failed for rule '%(rule)s' "
                       "on target %(target)s"), {
                           'rule': rule,
                           'target': repr(target)
                       },
                     extra=extra)
Exemplo n.º 2
0
    def coerce(self, obj, attr, value):
        super(StateMachineEnforce, self).coerce(obj, attr, value)
        msg = _("%(object)s's are not allowed transition out of %(value)s "
                "state")
        # olso.versionedobjects do not create the field until it is first used
        try:
            current_value = getattr(obj, attr)
        except NotImplementedError:
            return value

        if current_value in self.ALLOWED_TRANSITIONS:

            if value in self.ALLOWED_TRANSITIONS[current_value]:
                return value
            else:
                msg = _(
                    "%(object)s's are not allowed transition out of "
                    "'%(current_value)s' state to '%(value)s' state, choose "
                    "from %(options)r")
        msg = msg % {
            'object': obj.obj_name(),
            'current_value': current_value,
            'value': value,
            'options': [x for x in self.ALLOWED_TRANSITIONS[current_value]]
        }
        raise ValueError(msg)
Exemplo n.º 3
0
    def coerce(self, obj, attr, value):
        super(StateMachineEnforce, self).coerce(obj, attr, value)
        msg = _("%(object)s's are not allowed transition out of %(value)s "
                "state")
        # olso.versionedobjects do not create the field until it is first used
        try:
            current_value = getattr(obj, attr)
        except NotImplementedError:
            return value

        if current_value in self.ALLOWED_TRANSITIONS:

            if value in self.ALLOWED_TRANSITIONS[current_value]:
                return value
            else:
                msg = _(
                    "%(object)s's are not allowed transition out of "
                    "'%(current_value)s' state to '%(value)s' state, choose "
                    "from %(options)r")
        msg = msg % {
            'object': obj.obj_name(),
            'current_value': current_value,
            'value': value,
            'options': [x for x in self.ALLOWED_TRANSITIONS[current_value]]
        }
        raise ValueError(msg)
Exemplo n.º 4
0
    def coerce(self, obj, attr, value):

        if not re.match(RE_ZONENAME, value):
            msg = _("'%s' is not a valid DNS Zone name") % value
            raise ValueError(msg)

        return super(DNSZoneName, self).coerce(obj, attr, value)
Exemplo n.º 5
0
    def coerce(self, obj, attr, value):

        if not re.match(RE_ZONENAME, value):
            msg = _("'%s' is not a valid DNS Zone name") % value
            raise ValueError(msg)

        return super(DNSZoneName, self).coerce(obj, attr, value)
Exemplo n.º 6
0
    def start(self):
        super(Service, self).start()

        LOG.info(
            _('Starting %(name)s service (version: %(version)s)'), {
                'name': self.service_name,
                'version': version.version_info.version_string()
            })
Exemplo n.º 7
0
def check(rule, ctxt, target=None, do_raise=True, exc=exceptions.Forbidden):
    creds = ctxt.to_dict()
    target = target or {}
    try:
        result = _ENFORCER.enforce(rule, target, creds, do_raise, exc)
    except Exception:
        result = False
        raise
    else:
        return result
    finally:
        extra = {'policy': {'rule': rule, 'target': target}}

        if result:
            LOG.info(_("Policy check succeeded for rule '%(rule)s' "
                       "on target %(target)s"),
                     {'rule': rule, 'target': repr(target)}, extra=extra)
        else:
            LOG.info(_("Policy check failed for rule '%(rule)s' "
                       "on target %(target)s"),
                     {'rule': rule, 'target': repr(target)}, extra=extra)
Exemplo n.º 8
0
    def coerce(self, obj, attr, value):

        msg = _("%(value)s is not a valid UUID for %(attr)s") % {
            'attr': attr,
            'value': value
        }
        try:
            uuid_tools.UUID(value)
        except ValueError:
            raise ValueError(msg)

        return str(value)
Exemplo n.º 9
0
    def coerce(self, obj, attr, value):

        msg = _("%(value)s is not a valid UUID for %(attr)s") % {
            'attr': attr,
            'value': value
        }
        try:
            uuid_tools.UUID(value)
        except ValueError:
            raise ValueError(msg)

        return str(value)
Exemplo n.º 10
0
class MonitorType(PreDefinedEnumType):

    TCP = 'TCP'
    UDP = 'UDP'
    ICMP = 'ICMP'
    HTTP = 'HTTP'
    HTTPS = 'HTTPS'
    SSH = 'SSH'

    # TODO(graham): Dynamically Load this list of types from config + plugins
    _TYPES = (TCP, UDP, ICMP, HTTP, HTTPS, SSH)

    _msg = _("%(value)s is not a valid Monitor Type, choose from %(options)r")
Exemplo n.º 11
0
class PreDefinedEnumType(EnumField):

    _TYPES = ()
    _msg = _("%(value)s is not a valid choice, choose from %(options)r")

    def __init__(self, **kwargs):
        super(PreDefinedEnumType, self).__init__(self._TYPES, **kwargs)

    def coerce(self, obj, attr, value):
        try:
            return super(PreDefinedEnumType, self).coerce(obj, attr, value)
        except ValueError:
            msg = self._msg % {"value": value, "options": self._TYPES}
            raise ValueError(msg)
Exemplo n.º 12
0
class MonitorStatus(fields.StateMachineEnforce, fields.PreDefinedEnumType):

    ACTIVE = 'ACTIVE'
    PENDING = 'PENDING'
    ERROR = 'ERROR'
    DELETED = 'DELETED'

    ALLOWED_TRANSITIONS = {
        ACTIVE: {ERROR, PENDING, DELETED},
        PENDING: {ACTIVE, ERROR, DELETED},
        ERROR: {PENDING, ACTIVE, DELETED},
        DELETED: {}
    }

    _TYPES = (ACTIVE, PENDING, ERROR, DELETED)

    _msg = _("'%(value)s' is not a valid status, choose from %(options)r")
Exemplo n.º 13
0
class KosmosActions(StateMachineEnforce, PreDefinedEnumType):

    CREATE = 'CREATE'
    UPDATE = 'UPDATE'
    DELETE = 'DELETE'
    NONE = 'NONE'

    ALLOWED_TRANSITIONS = {
        CREATE: {NONE, UPDATE},
        UPDATE: {NONE},
        NONE: {UPDATE, DELETE},
        DELETE: {NONE}
    }

    _TYPES = (CREATE, UPDATE, DELETE, NONE)

    _msg = _("%(value)s is not a valid Action, choose from %(options)r")
Exemplo n.º 14
0
import os

from oslo_config import cfg
from oslo_db import options as db_options
from oslo_log import log as logging
import oslo_messaging as messaging

from kosmos._i18n import _, _LI
from kosmos.common import utils
from kosmos import version

LOG = logging.getLogger(__name__)

core_opts = [
    cfg.IPOpt('bind_host', default='0.0.0.0',
              help=_("The host IP to bind to")),
    cfg.PortOpt('bind_port', default=9876,
                help=_("The port to bind to")),
    cfg.StrOpt('host', default=utils.get_hostname(),
               help=_("The hostname Kosmos is running on")),
]

core_cli_opts = []


# Register the configuration options
cfg.CONF.register_opts(core_opts)
cfg.CONF.register_cli_opts(core_cli_opts)

cfg.CONF.register_opts([
    cfg.StrOpt(
Exemplo n.º 15
0
    def stop(self):
        LOG.info(_('Stopping %(name)s service'), {'name': self.service_name})

        super(Service, self).stop()
Exemplo n.º 16
0
    def coerce(self, obj, attr, value):
        if not re.match(RE_HOSTNAME, value):
            msg = _("'%s' is not valid a valid DNS FQDN") % value
            raise ValueError(msg)

        return super(DNSFQDN, self).coerce(obj, attr, value)
Exemplo n.º 17
0
    def stop(self):
        LOG.info(_('Stopping %(name)s service'), {'name': self.service_name})

        super(Service, self).stop()
Exemplo n.º 18
0
    def coerce(self, obj, attr, value):
        if not re.match(RE_HOSTNAME, value):
            msg = _("'%s' is not valid a valid DNS FQDN") % value
            raise ValueError(msg)

        return super(DNSFQDN, self).coerce(obj, attr, value)
Exemplo n.º 19
0
    def start(self):
        super(Service, self).start()

        LOG.info(_('Starting %(name)s service (version: %(version)s)'),
                 {'name': self.service_name,
                  'version': version.version_info.version_string()})