[ovs-dev] [bug15983 2/4] ovsdb-server: Add commands for adding and removing remotes at runtime.
Ansis Atteka
aatteka at nicira.com
Wed Apr 10 19:25:14 UTC 2013
On Wed, Apr 10, 2013 at 10:35 AM, Ben Pfaff <blp at nicira.com> wrote:
> This will make it possible, in later commits, to make ovsdb-server connect
> to OVS managers only after ovs-vswitchd has completed its initial
> configuration.
>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
> ovsdb/ovsdb-server.1.in | 28 +++++++++++++++++++
> ovsdb/ovsdb-server.c | 68
> +++++++++++++++++++++++++++++++++++++++++++++--
> tests/ovsdb-server.at | 37 ++++++++++++++++++++++++++
> 3 files changed, 131 insertions(+), 2 deletions(-)
>
> diff --git a/ovsdb/ovsdb-server.1.in b/ovsdb/ovsdb-server.1.in
> index 9d42471..82dd9c6 100644
> --- a/ovsdb/ovsdb-server.1.in
> +++ b/ovsdb/ovsdb-server.1.in
> @@ -1,4 +1,9 @@
> .\" -*- nroff -*-
> +.de IQ
> +. br
> +. ns
> +. IP "\\$1"
> +..
> .TH ovsdb\-server 1 "@VERSION@" "Open vSwitch" "Open vSwitch Manual"
> .\" This program's name:
> .ds PN ovsdb\-server
> @@ -124,6 +129,29 @@ connections to database clients and reconnect.
> This command might be useful for debugging issues with database
> clients.
> .
> +.IP "\fBovsdb\-server/add\-remote \fIremote\fR"
> +Adds a remote, as if \fB\-\-remote=\fIremote\fR had been specified on
> +the \fBovsdb\-server\fR command line. (If \fIremote\fR is already a
> +remote, this command succeeds without changing the configuration.)
> +.
> +.IP "\fBovsdb\-server/remove\-remote \fIremote\fR"
> +Removes the specified \fIremote\fR from the configuration, failing
> +with an error if \fIremote\fR is not configured as a remote. This
> +command only works with remotes that were named on \fB\-\-remote\fR or
> +\fBovsdb\-server/add\-remote\fR, that is, it will not remove remotes
> +added indirectly because they were read from the database by
> +configuring a \fBdb:\fR[\fIdb\fB,\fR]\fItable\fB,\fIcolumn\fR remote.
> +(You can remove a database source with \fBovsdb\-server/remove\-remote
> +\fBdb:\fR[\fIdb\fB,\fR]\fItable\fB,\fIcolumn\fR, but not individual
> +remotes found indirectly through the database.)
> +.
> +.IP "\fBovsdb\-server/list\-remotes"
> +Outputs a list of the currently configured remotes named on
> +\fB\-\-remote\fR or \fBovsdb\-server/add\-remote\fR, that is, it does
> +not list remotes added indirectly because they were read from the
> +database by configuring a
> +\fBdb:\fR[\fIdb\fB,\fR]\fItable\fB,\fIcolumn\fR remote.
> +.
> .so lib/vlog-unixctl.man
> .so lib/memory-unixctl.man
> .so lib/coverage-unixctl.man
> diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
> index 2657e26..dcc43f8 100644
> --- a/ovsdb/ovsdb-server.c
> +++ b/ovsdb/ovsdb-server.c
> @@ -1,4 +1,4 @@
> -/* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
> +/* Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
> *
> * Licensed under the Apache License, Version 2.0 (the "License");
> * you may not use this file except in compliance with the License.
> @@ -75,6 +75,9 @@ static bool bootstrap_ca_cert;
> static unixctl_cb_func ovsdb_server_exit;
> static unixctl_cb_func ovsdb_server_compact;
> static unixctl_cb_func ovsdb_server_reconnect;
> +static unixctl_cb_func ovsdb_server_add_remote;
> +static unixctl_cb_func ovsdb_server_remove_remote;
> +static unixctl_cb_func ovsdb_server_list_remotes;
>
> static void parse_options(int *argc, char **argvp[],
> struct sset *remotes, char **unixctl_pathp,
> @@ -180,6 +183,12 @@ main(int argc, char *argv[])
> ovsdb_server_compact, dbs);
> unixctl_command_register("ovsdb-server/reconnect", "", 0, 0,
> ovsdb_server_reconnect, jsonrpc);
> + unixctl_command_register("ovsdb-server/add-remote", "REMOTE", 1, 1,
> + ovsdb_server_add_remote, &remotes);
> + unixctl_command_register("ovsdb-server/remove-remote", "REMOTE", 1, 1,
> + ovsdb_server_remove_remote, &remotes);
> + unixctl_command_register("ovsdb-server/list-remotes", "", 0, 0,
> + ovsdb_server_list_remotes, &remotes);
>
> exiting = false;
> while (!exiting) {
> @@ -198,9 +207,13 @@ main(int argc, char *argv[])
> simap_destroy(&usage);
> }
>
> + /* Run unixctl_server_run() before reconfigure_from_db() because
> + * ovsdb-server/add-remote and ovsdb-server/remove-remote can
> change
> + * the set of remotes that reconfigure_from_db() uses. */
> + unixctl_server_run(unixctl);
> +
> reconfigure_from_db(jsonrpc, dbs, n_dbs, &remotes);
> ovsdb_jsonrpc_server_run(jsonrpc);
> - unixctl_server_run(unixctl);
>
> for (i = 0; i < n_dbs; i++) {
> ovsdb_trigger_run(dbs[i].db, time_msec());
> @@ -838,6 +851,57 @@ ovsdb_server_reconnect(struct unixctl_conn *conn, int
> argc OVS_UNUSED,
> unixctl_command_reply(conn, NULL);
> }
>
> +/* "ovsdb-server/add-remote REMOTE": adds REMOTE to the set of remotes
> that
> + * ovsdb-server services. */
> +static void
> +ovsdb_server_add_remote(struct unixctl_conn *conn, int argc OVS_UNUSED,
> + const char *argv[], void *remotes_)
> +{
> + struct sset *remotes = remotes_;
> +
> + sset_add(remotes, argv[1]);
>
+ unixctl_command_reply(conn, NULL);
>
sset_add() would return NULL, if item was already present in sset. Perhaps
unixctl_command_reply() should pass a warning to caller in this case (e.g.
"remote already present")?
> +}
> +
> +/* "ovsdb-server/remove-remote REMOTE": removes REMOTE frmo the set of
> remotes
> + * that ovsdb-server services. */
> +static void
> +ovsdb_server_remove_remote(struct unixctl_conn *conn, int argc OVS_UNUSED,
> + const char *argv[], void *remotes_)
> +{
> + struct sset *remotes = remotes_;
> + struct sset_node *node;
> +
> + node = sset_find(remotes, argv[1]);
> + if (node) {
> + sset_delete(remotes, node);
> + unixctl_command_reply(conn, NULL);
> + } else {
> + unixctl_command_reply_error(conn, "no such remote");
> + }
> +}
> +
> +/* "ovsdb-server/list-remotes": outputs a list of configured rmeotes. */
> +static void
> +ovsdb_server_list_remotes(struct unixctl_conn *conn, int argc OVS_UNUSED,
> + const char *argv[] OVS_UNUSED, void *remotes_)
> +{
> + struct sset *remotes = remotes_;
> + const char **list, **p;
> + struct ds s;
> +
> + ds_init(&s);
> +
> + list = sset_sort(remotes);
> + for (p = list; *p; p++) {
> + ds_put_format(&s, "%s\n", *p);
> + }
> + free(list);
> +
> + unixctl_command_reply(conn, ds_cstr(&s));
> + ds_destroy(&s);
> +}
> +
> static void
> parse_options(int *argcp, char **argvp[],
> struct sset *remotes, char **unixctl_pathp, char
> **run_command)
> diff --git a/tests/ovsdb-server.at b/tests/ovsdb-server.at
> index 62eae38..d310912 100644
> --- a/tests/ovsdb-server.at
> +++ b/tests/ovsdb-server.at
> @@ -229,6 +229,43 @@ AT_CHECK(
> [ignore])
> AT_CLEANUP
>
> +AT_SETUP([ovsdb-server/add-remote and remove-remote])
> +AT_KEYWORDS([ovsdb server positive])
> +OVS_RUNDIR=`pwd`; export OVS_RUNDIR
> +OVS_LOGDIR=`pwd`; export OVS_LOGDIR
> +ordinal_schema > schema
> +AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
> +ON_EXIT([kill `cat *.pid`])
> +AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
> +
> +AT_CHECK([test ! -e socket1])
> +AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote
> punix:socket1])
> +OVS_WAIT_UNTIL([test -S socket1])
> +AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
> + [0], [punix:socket1
> +])
> +
> +AT_CHECK([test ! -e socket2])
> +AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote
> punix:socket2])
> +OVS_WAIT_UNTIL([test -S socket2])
> +AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
> + [0], [punix:socket1
> +punix:socket2
> +])
> +
> +AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote
> punix:socket1])
> +OVS_WAIT_UNTIL([test ! -e socket1])
> +AT_CHECK([test -S socket2])
> +AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
> + [0], [punix:socket2
> +])
> +
> +AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote
> punix:socket2])
> +OVS_WAIT_UNTIL([test ! -e socket2])
> +AT_CHECK([test ! -e socket1])
> +AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
> +AT_CLEANUP
> +
> AT_SETUP([SSL db: implementation])
> AT_KEYWORDS([ovsdb server positive ssl $5])
> AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
> --
> 1.7.10.4
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20130410/2f0ee42a/attachment-0003.html>
More information about the dev
mailing list