How to use the circus.exc.MessageError function in circus

To help you get started, we’ve selected a few circus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github circus-tent / circus / circus / commands.py View on Github external
def _get_show(self, trainer, show_name):
        """ get show from the trainer if any """
        try:
            return trainer.get_show(show_name.lower())
        except KeyError:
            raise MessageError("program %s not found" % show_name)
github circus-tent / circus / circus / commands / addwatcher.py View on Github external
def execute(self, arbiter, props):
        options = props.get('options', {})

        # check for endpoint_owner uid restriction mode
        # it would be better to use some type of SO_PEERCRED lookup on the ipc
        # socket to get the uid of the client process and restrict on that,
        # but there's no good portable pythonic way of doing that right now
        # inside pyzmq or here. So we'll assume that the administrator has
        # set good rights on the ipc socket to help prevent privilege
        # escalation
        if arbiter.endpoint_owner_mode:
            cmd_uid = options.get('uid', None)
            if cmd_uid != arbiter.endpoint_owner:
                raise MessageError("uid does not match endpoint_owner")

        # convert all rlimit_* options into one rlimits dict which is required
        # by the watcher constructor (follows same pattern as config.py)
        rlimits = {}
        for key, val in options.items():
            if key.startswith('rlimit_'):
                rlimits[key[7:]] = rlimit_value(val)

        if len(rlimits) > 0:
            options['rlimits'] = rlimits
            for key in rlimits.keys():
                del options['rlimit_' + key]

        # now create and start the watcher
        watcher = arbiter.add_watcher(props['name'], props['cmd'],
                                      args=props.get('args'), **options)
github circus-tent / circus / circus / commands.py View on Github external
def execute(self, trainer, args):
        if len(args) > 2:
            raise MessageError("message invalid")

        if len(args) == 2:
            show = self._get_show(trainer, args[0])
            try:
                return show.fly_info(args[1])
            except KeyError:
                raise MessageError("fly %r not found in %r" % (args[1],
                                    args[0]))

        elif len(args) == 1:
            show = self._get_show(trainer, args[0])
            return "\n".join(show.info())
        else:
            infos = []
            for show in trainer.shows:
                infos.append("%s:\n" % show.name)
                show_info = "\n".join(show.info())
                infos.append("%s\n" % show_info)
            return buffer("".join(infos))
github circus-tent / circus / circus / commands / util.py View on Github external
valid_prefixes = ('stdout_stream.', 'stderr_stream.', 'hooks.', 'rlimit_')

    def _valid_prefix():
        for prefix in valid_prefixes:
            if key.startswith('%s' % prefix):
                return True
        return False

    if key not in valid_keys and not _valid_prefix():
        raise MessageError('unknown key %r' % key)

    if key in ('numprocesses', 'max_retry', 'max_age', 'max_age_variance',
               'stop_signal'):
        if not isinstance(val, int):
            raise MessageError("%r isn't an integer" % key)

    elif key in ('warmup_delay', 'retry_in', 'graceful_timeout',):
        if not isinstance(val, (int, float)):
            raise MessageError("%r isn't a number" % key)

    elif key in ('uid', 'gid',):
        if not isinstance(val, int) and not isinstance(val, str):
            raise MessageError("%r isn't an integer or string" % key)

    elif key in ('send_hup', 'shell', 'copy_env', 'respawn', 'stop_children',
                 'close_child_stdin', 'close_child_stdout',
                 'close_child_stderr'):
        if not isinstance(val, bool):
            raise MessageError("%r isn't a valid boolean" % key)

    elif key in ('env', ):
github circus-tent / circus / circus / commands.py View on Github external
def execute(self, trainer, args):
        if len(args) < 2:
            raise MessageError("invalid number of parameters")

        show = self._get_show(trainer, args.pop(0))

        # get options values. It return an error if one of the asked
        # options isn't found
        ret = []
        for name in args:
            if name in show.optnames:
                val = show.get_opt(name)
                ret.append("%s: %s" % (name, val))
            else:
                return "error: %r option not found" % name
        return "\n".join(ret)
github circus-tent / circus / circus / commands.py View on Github external
def execute(self, trainer, args):
        raise MessageError("invalid message. use a pub/sub socket")
github circus-tent / circus / circus / commands / util.py View on Github external
if 'class' not in val:
            raise MessageError("%r must have a 'class' key" % key)
        if 'refresh_time' in val:
            warnings.warn("'refresh_time' is deprecated and not useful "
                          "anymore for %r" % key)

    elif key.startswith('rlimit_'):
        if resource:
            rlimit_key = key[7:]
            rlimit_int = getattr(
                resource, 'RLIMIT_' + rlimit_key.upper(), None
            )
            if rlimit_int is None:
                raise MessageError("%r isn't a valid rlimit setting" % key)
        else:
            raise MessageError("rlimit options are not supported on this"
                               " platform")

        # note that a null val means RLIM_INFINITY
        if val is not None and not isinstance(val, int):
            raise MessageError("%r rlimit value isn't a valid int" % val)
github circus-tent / circus / circus / commands / listen.py View on Github external
def execute(self, arbiter, args):
        raise MessageError("invalid message. use a pub/sub socket")
github circus-tent / circus / circus / commands.py View on Github external
def _get_signal(self, args):
        if args[-1].lower() in ('quit', 'hup', 'kill', 'term',):
            return args[:-1], getattr(signal, "SIG%s" % args[-1].upper())
        raise MessageError("signal %r not supported" % args[-1])
github circus-tent / circus / circus / commands / sendsignal.py View on Github external
def validate(self, props):
        super(Signal, self).validate(props)

        if 'childpid' in props and 'pid' not in props:
            raise ArgumentError('cannot specify childpid without pid')

        try:
            props['signum'] = to_signum(props['signum'])
        except ValueError:
            raise MessageError('signal invalid')