aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/random.c
diff options
context:
space:
mode:
authorBenoît Ganne <bganne@cisco.com>2021-01-18 19:24:34 +0100
committerNeale Ranns <neale@graphiant.com>2021-01-20 13:52:11 +0000
commit58a1915b501845c47676d529ff3b5840a876e39d (patch)
tree34988661db0ce60387e00a19fea18ee8c32b916f /src/vppinfra/random.c
parentb2525922cd7932413a370c212c09485367d15464 (diff)
ip: add API to retrieve IPv6 link-layer address
Type: feature Change-Id: I5739869490155b0b9674b4faf61882d97e66a4ed Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src/vppinfra/random.c')
0 files changed, 0 insertions, 0 deletions
omment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/usr/bin/python

import outer_packages
import lockfile
from daemon import runner,daemon
from daemon.runner import *
import os, sys
from argparse import ArgumentParser
from trex_server import trex_parser
try:
    from termstyle import termstyle
except ImportError:
    import termstyle


def daemonize_parser(parser_obj, action_funcs, help_menu):
    """Update the regular process parser to deal with daemon process options"""
    parser_obj.description += " (as a daemon process)"
    parser_obj.usage = None
    parser_obj.add_argument("action", choices=action_funcs,
                            action="store", help=help_menu)
    return


class ExtendedDaemonRunner(runner.DaemonRunner):
    """ Controller for a callable running in a separate background process.

    The first command-line argument is the action to take:

    * 'start': Become a daemon and call `app.run()`.
    * 'stop': Exit the daemon process specified in the PID file.
    * 'restart': Stop, then start.

        """

    help_menu = """Specify action command to be applied on server.
    (*) start      : start the application in as a daemon process.
    (*) show       : prompt an updated status of daemon process (running/ not running).
    (*) stop       : exit the daemon process.
    (*) restart    : stop, then start again the application as daemon process
    (*) start-live : start the application in live mode (no daemon process).
    """

    def __init__(self, app, parser_obj):
        """ Set up the parameters of a new runner.
            THIS METHOD INTENTIONALLY DO NOT INVOKE SUPER __init__() METHOD

            :param app: The application instance; see below.
            :return: ``None``.

            The `app` argument must have the following attributes:

            * `stdin_path`, `stdout_path`, `stderr_path`: Filesystem paths
              to open and replace the existing `sys.stdin`, `sys.stdout`,
              `sys.stderr`.

            * `pidfile_path`: Absolute filesystem path to a file that will
              be used as the PID file for the daemon. If ``None``, no PID
              file will be used.

            * `pidfile_timeout`: Used as the default acquisition timeout
              value supplied to the runner's PID lock file.

            * `run`: Callable that will be invoked when the daemon is
              started.

            """
        super(runner.DaemonRunner, self).__init__()
        # update action_funcs to support more operations
        self.update_action_funcs()

        daemonize_parser(parser_obj, self.action_funcs, ExtendedDaemonRunner.help_menu)
        args = parser_obj.parse_args()
        self.action = unicode(args.action)

        self.app = app
        self.daemon_context = daemon.DaemonContext()
        self.daemon_context.stdin = open(app.stdin_path, 'rt')
        self.daemon_context.stdout = open(app.stdout_path, 'w+t')
        self.daemon_context.stderr = open(app.stderr_path,
                                          'a+t', buffering=0)

        self.pidfile = None
        if app.pidfile_path is not None:
            self.pidfile = make_pidlockfile(app.pidfile_path, app.pidfile_timeout)
        self.daemon_context.pidfile = self.pidfile

        # mask out all arguments that aren't relevant to main app script

    def update_action_funcs(self):
        self.action_funcs.update({u'start-live': self._start_live, u'show': self._show})     # add key (=action), value (=desired func)

    @staticmethod
    def _start_live(self):
        self.app.run()

    @staticmethod
    def _show(self):
        if self.pidfile.is_locked():
            print termstyle.red("T-Rex server daemon is running")
        else:
            print termstyle.red("T-Rex server daemon is NOT running")

    def do_action(self):
        self.__prevent_duplicate_runs()
        self.__prompt_init_msg()
        try:
            super(ExtendedDaemonRunner, self).do_action()
            if self.action == 'stop':
                self.__verify_termination()
        except runner.DaemonRunnerStopFailureError:
            if self.action == 'restart':
                # error means server wasn't running in the first place- so start it!
                self.action = 'start'
                self.do_action()

    
    def __prevent_duplicate_runs(self):
        if self.action == 'start' and self.pidfile.is_locked():
            print termstyle.green("Server daemon is already running")
            exit(1)
        elif self.action == 'stop' and not self.pidfile.is_locked():
            print termstyle.green("Server daemon is not running")
            exit(1)

    def __prompt_init_msg(self):
        if self.action == 'start':
            print termstyle.green("Starting daemon server...")
        elif self.action == 'stop':
            print termstyle.green("Stopping daemon server...")

    def __verify_termination(self):
        pass
#       import time
#       while self.pidfile.is_locked():
#           time.sleep(2)
#           self._stop()
#


if __name__ == "__main__":
    pass