How to use ovs - 10 common examples

To help you get started, we’ve selected a few ovs 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 ovn-org / ovn / tests / test-jsonrpc.py View on Github external
def do_request(name, method, params_string):
    params = ovs.json.from_string(params_string)
    msg = ovs.jsonrpc.Message.create_request(method, params)
    s = msg.is_valid()
    if s:
        sys.stderr.write("not a valid JSON-RPC request: %s\n" % s)
        sys.exit(1)

    error, stream = ovs.stream.Stream.open_block(ovs.stream.Stream.open(name))
    if error:
        sys.stderr.write("could not open \"%s\": %s\n"
                         % (name, os.strerror(error)))
        sys.exit(1)

    rpc = ovs.jsonrpc.Connection(stream)

    error = rpc.send(msg)
    if error:
        sys.stderr.write("could not send request: %s\n" % os.strerror(error))
github ovn-org / ovn / tests / appctl.py View on Github external
parser = argparse.ArgumentParser(description="Python Implementation of"
                                     " ovs-appctl.")
    parser.add_argument("-t", "--target", default="ovs-vswitchd",
                        help="pidfile or socket to contact")

    parser.add_argument("command", metavar="COMMAND",
                        help="Command to run.")
    parser.add_argument("argv", metavar="ARG", nargs="*",
                        help="Arguments to the command.")
    parser.add_argument("-T", "--timeout", metavar="SECS",
                        help="wait at most SECS seconds for a response")
    args = parser.parse_args()

    signal_alarm(int(args.timeout) if args.timeout else None)

    ovs.vlog.Vlog.init()
    target = args.target
    client = connect_to_target(target)
    err_no, error, result = client.transact(args.command, args.argv)
    client.close()

    if err_no:
        ovs.util.ovs_fatal(err_no, "%s: transaction error" % target)
    elif error is not None:
        sys.stderr.write(error)
        ovs.util.ovs_error(0, "%s: server returned an error" % target)
        sys.exit(2)
    else:
        assert result is not None
        sys.stdout.write(result)
github ovn-org / ovn / tests / test-ovsdb.py View on Github external
def idl_set(idl, commands, step):
    txn = ovs.db.idl.Transaction(idl)
    increment = False
    fetch_cmds = []
    events = []
    for command in commands.split(','):
        words = command.split()
        name = words[0]
        args = words[1:]

        if name == "notifytest":
            name = args[0]
            args = args[1:]
            old_notify = idl.notify

            def notify(event, row, updates=None):
                if updates:
                    upcol = list(updates._data.keys())[0]
github ovn-org / ovn / tests / test-ovsdb.py View on Github external
commands = commands[3:]

    schema_helper.register_all()
    idl = ovs.db.idl.Idl(remote, schema_helper)

    step = 0
    seqno = 0
    commands = list(commands)
    for command in commands:
        if command.startswith("+"):
            # The previous transaction didn't change anything.
            command = command[1:]
        else:
            # Wait for update.
            while idl.change_seqno == seqno and not idl.run():
                poller = ovs.poller.Poller()
                idl.wait(poller)
                poller.block()
            step += 1

        seqno = idl.change_seqno

        if command == "reconnect":
            print("%03d: reconnect" % step)
            sys.stdout.flush()
            step += 1
            idl.force_reconnect()
        elif command == "remote":
            print("%03d: %s" % (step, idl.session_name()))
            sys.stdout.flush()
            step += 1
        elif command == "remotestop":
github ovn-org / ovn / tests / test-unixctl.py View on Github external
error, server = ovs.unixctl.server.UnixctlServer.create(args.unixctl)
    if error:
        ovs.util.ovs_fatal(error, "could not create unixctl server at %s"
                           % args.unixctl, vlog)

    ovs.unixctl.command_register("exit", "", 0, 0, unixctl_exit, "aux_exit")
    ovs.unixctl.command_register("echo", "[arg ...]", 1, 2, unixctl_echo,
                                 "aux_echo")
    ovs.unixctl.command_register("log", "[arg ...]", 1, 2, unixctl_log, None)
    ovs.unixctl.command_register("echo_error", "[arg ...]", 1, 2,
                                 unixctl_echo_error, "aux_echo_error")
    ovs.unixctl.command_register("block", "", 0, 0, unixctl_block, None)
    ovs.daemon.daemonize_complete()

    vlog.info("Entering run loop.")
    poller = ovs.poller.Poller()
    while not exiting:
        server.run()
        server.wait(poller)
        if exiting:
            poller.immediate_wake()
        poller.block()
    server.close()
github ovn-org / ovn / tests / test-jsonrpc.py View on Github external
% (name, os.strerror(error)))
        sys.exit(1)

    rpc = ovs.jsonrpc.Connection(stream)

    error = rpc.send(msg)
    if error:
        sys.stderr.write("could not send request: %s\n" % os.strerror(error))
        sys.exit(1)

    error, msg = rpc.recv_block()
    if error:
        sys.stderr.write("error waiting for reply: %s\n" % os.strerror(error))
        sys.exit(1)

    print(ovs.json.to_string(msg.to_json()))

    rpc.close()
github ovn-org / ovn / tests / test-stream.py View on Github external
def main(argv):
    remote = argv[1]
    err, stream = ovs.stream.Stream.open_block(
            ovs.stream.Stream.open(remote), 10000)

    if err or stream is None:
        sys.exit(1)

    sys.exit(0)
github ovn-org / ovn / tests / test-jsonrpc.py View on Github external
def do_request(name, method, params_string):
    params = ovs.json.from_string(params_string)
    msg = ovs.jsonrpc.Message.create_request(method, params)
    s = msg.is_valid()
    if s:
        sys.stderr.write("not a valid JSON-RPC request: %s\n" % s)
        sys.exit(1)

    error, stream = ovs.stream.Stream.open_block(ovs.stream.Stream.open(name))
    if error:
        sys.stderr.write("could not open \"%s\": %s\n"
                         % (name, os.strerror(error)))
        sys.exit(1)

    rpc = ovs.jsonrpc.Connection(stream)

    error = rpc.send(msg)
    if error:
        sys.stderr.write("could not send request: %s\n" % os.strerror(error))
        sys.exit(1)

    error, msg = rpc.recv_block()
    if error:
        sys.stderr.write("error waiting for reply: %s\n" % os.strerror(error))
        sys.exit(1)

    print(ovs.json.to_string(msg.to_json()))

    rpc.close()
github ovn-org / ovn / tests / test-jsonrpc.py View on Github external
def do_notify(name, method, params_string):
    params = ovs.json.from_string(params_string)
    msg = ovs.jsonrpc.Message.create_notify(method, params)
    s = msg.is_valid()
    if s:
        sys.stderr.write("not a valid JSON-RPC notification: %s\n" % s)
        sys.exit(1)

    error, stream = ovs.stream.Stream.open_block(ovs.stream.Stream.open(name))
    if error:
        sys.stderr.write("could not open \"%s\": %s\n"
                         % (name, os.strerror(error)))
        sys.exit(1)

    rpc = ovs.jsonrpc.Connection(stream)

    error = rpc.send_block(msg)
    if error:
        sys.stderr.write("could not send notification: %s\n"
                         % os.strerror(error))
        sys.exit(1)

    rpc.close()
github ovn-org / ovn / tests / test-jsonrpc.py View on Github external
# that the parent process created.
        error, pstream = ovs.stream.PassiveStream.open(name)
        if error:
            sys.stderr.write("could not listen on \"%s\": %s\n"
                             % (name, os.strerror(error)))
            sys.exit(1)

    ovs.daemon.daemonize()

    rpcs = []
    done = False
    while True:
        # Accept new connections.
        error, stream = pstream.accept()
        if stream:
            rpcs.append(ovs.jsonrpc.Connection(stream))
        elif error != errno.EAGAIN:
            sys.stderr.write("PassiveStream.accept() failed\n")
            sys.exit(1)

        # Service existing connections.
        dead_rpcs = []
        for rpc in rpcs:
            rpc.run()

            error = 0
            if not rpc.get_backlog():
                error, msg = rpc.recv()
                if not error:
                    if handle_rpc(rpc, msg):
                        done = True