From 24b8b259bb06af4e6ded4401a6eb41672ca0a58f Mon Sep 17 00:00:00 2001 From: Andrew Evans Date: Fri, 4 Feb 2011 13:30:02 -0800 Subject: [PATCH] ovs-vsctl: Add commands to get/delete/set manager connections. --- tests/ovs-vsctl.at | 26 +++++++++ utilities/ovs-vsctl.8.in | 24 ++++++++ utilities/ovs-vsctl.c | 120 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) diff --git a/tests/ovs-vsctl.at b/tests/ovs-vsctl.at index a05e8055..bb494502 100644 --- a/tests/ovs-vsctl.at +++ b/tests/ovs-vsctl.at @@ -503,6 +503,32 @@ CHECK_BRIDGES OVS_VSCTL_CLEANUP AT_CLEANUP +dnl ---------------------------------------------------------------------- +AT_BANNER([ovs-vsctl unit tests -- manager commands]) + +AT_SETUP([managers]) +AT_KEYWORDS([manager ovs-vsctl]) +OVS_VSCTL_SETUP +AT_CHECK([RUN_OVS_VSCTL_TOGETHER( + [del-manager], + [get-manager], + [set-manager tcp:4.5.6.7], + [get-manager], + [set-manager tcp:8.9.10.11 tcp:5.4.3.2], + [get-manager], + [del-manager], + [get-manager])], [0], [ + + +tcp:4.5.6.7 + +tcp:5.4.3.2\ntcp:8.9.10.11 + + +], [], [OVS_VSCTL_CLEANUP]) +OVS_VSCTL_CLEANUP +AT_CLEANUP + dnl ---------------------------------------------------------------------- AT_BANNER([ovs-vsctl unit tests -- database commands]) diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in index c550909f..5e3ab39e 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -360,6 +360,30 @@ Deletes the configured failure mode. .IP "\fBset\-fail\-mode\fR \fIbridge\fR \fBstandalone\fR|\fBsecure\fR" Sets the configured failure mode. . +.SS "Manager Connectivity" +. +These commands manipulate the \fBmanagers\fR and \fBmanager_options\fR columns +in the \fBOpen_vSwitch\fR table and rows in the \fBManagers\fR table. When +\fBovsdb\-server\fR is configured to use those rows and columns for OVSDB +connections, as described in \fBINSTALL.Linux\fR and in the startup scripts +provided with Open vSwitch, this allows the administrator to use +\fBovs\-vsctl\fR to configure database connections. +. +.IP "\fBget\-manager\fR" +Prints the configured manager(s). +. +.IP "\fBdel\-manager\fR" +Deletes the configured manager(s). +. +.IP "\fBset\-manager\fR \fItarget\fR\&..." +Sets the configured manager target or targets. Each \fItarget\fR may +use any of the following forms: +. +.RS +.so ovsdb/remote-active.man +.so ovsdb/remote-passive.man +.RE +. .SS "SSL Configuration" When \fBovs\-vswitchd\fR is configured to connect over SSL for management or controller connectivity, the following parameters are required: diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index fd9f8f4a..911d8fe8 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -493,6 +493,11 @@ Controller commands:\n\ del-fail-mode BRIDGE delete the fail-mode for BRIDGE\n\ set-fail-mode BRIDGE MODE set the fail-mode for BRIDGE to MODE\n\ \n\ +Manager commands:\n\ + get-manager print all manager(s)\n\ + del-manager delete all manager(s)\n\ + set-manager TARGET... set the list of manager(s) to TARGET(s)\n\ +\n\ SSL commands:\n\ get-ssl print the SSL configuration\n\ del-ssl delete the SSL configuration\n\ @@ -1861,6 +1866,116 @@ cmd_set_fail_mode(struct vsctl_context *ctx) free_info(&info); } +static void +verify_managers(const struct ovsrec_open_vswitch *ovs) +{ + size_t i; + + ovsrec_open_vswitch_verify_managers(ovs); + ovsrec_open_vswitch_verify_manager_options(ovs); + + for (i = 0; i < ovs->n_manager_options; ++i) { + const struct ovsrec_manager *mgr = ovs->manager_options[i]; + + ovsrec_manager_verify_target(mgr); + } +} + +static void +pre_manager(struct vsctl_context *ctx) +{ + ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_managers); + ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_manager_options); + ovsdb_idl_add_column(ctx->idl, &ovsrec_manager_col_target); +} + +static void +cmd_get_manager(struct vsctl_context *ctx) +{ + const struct ovsrec_open_vswitch *ovs = ctx->ovs; + struct svec targets; + size_t i; + + verify_managers(ovs); + + /* Print the targets in sorted order for reproducibility. */ + svec_init(&targets); + + /* First, add all targets found in deprecated 'managers' column. */ + for (i = 0; i < ovs->n_managers; i++) { + svec_add(&targets, ovs->managers[i]); + } + + /* Second, add all targets pointed to by 'manager_options' column. */ + for (i = 0; i < ovs->n_manager_options; i++) { + svec_add(&targets, ovs->manager_options[i]->target); + } + + svec_sort_unique(&targets); + for (i = 0; i < targets.n; i++) { + ds_put_format(&ctx->output, "%s\n", targets.names[i]); + } + svec_destroy(&targets); +} + +static void +delete_managers(const struct vsctl_context *ctx) +{ + const struct ovsrec_open_vswitch *ovs = ctx->ovs; + size_t i; + + /* Delete manager targets in deprecated 'managers' column. */ + ovsrec_open_vswitch_set_managers(ovs, NULL, 0); + + /* Delete Manager rows pointed to by 'manager_options' column. */ + for (i = 0; i < ovs->n_manager_options; i++) { + ovsrec_manager_delete(ovs->manager_options[i]); + } + + /* Delete 'Manager' row refs in 'manager_options' column. */ + ovsrec_open_vswitch_set_manager_options(ovs, NULL, 0); +} + +static void +cmd_del_manager(struct vsctl_context *ctx) +{ + const struct ovsrec_open_vswitch *ovs = ctx->ovs; + + verify_managers(ovs); + delete_managers(ctx); +} + +static void +insert_managers(struct vsctl_context *ctx, char *targets[], size_t n) +{ + struct ovsrec_manager **managers; + size_t i; + + /* Store in deprecated 'manager' column. */ + ovsrec_open_vswitch_set_managers(ctx->ovs, targets, n); + + /* Insert each manager in a new row in Manager table. */ + managers = xmalloc(n * sizeof *managers); + for (i = 0; i < n; i++) { + managers[i] = ovsrec_manager_insert(ctx->txn); + ovsrec_manager_set_target(managers[i], targets[i]); + } + + /* Store uuids of new Manager rows in 'manager_options' column. */ + ovsrec_open_vswitch_set_manager_options(ctx->ovs, managers, n); + free(managers); +} + +static void +cmd_set_manager(struct vsctl_context *ctx) +{ + const size_t n = ctx->argc - 1; + + verify_managers(ctx->ovs); + delete_managers(ctx); + insert_managers(ctx, &ctx->argv[1], n); +} + static void pre_cmd_get_ssl(struct vsctl_context *ctx) { @@ -3287,6 +3402,11 @@ static const struct vsctl_command_syntax all_commands[] = { {"del-fail-mode", 1, 1, pre_get_info, cmd_del_fail_mode, NULL, "", RW}, {"set-fail-mode", 2, 2, pre_get_info, cmd_set_fail_mode, NULL, "", RW}, + /* Manager commands. */ + {"get-manager", 0, 0, pre_manager, cmd_get_manager, NULL, "", RO}, + {"del-manager", 0, INT_MAX, pre_manager, cmd_del_manager, NULL, "", RW}, + {"set-manager", 1, INT_MAX, pre_manager, cmd_set_manager, NULL, "", RW}, + /* SSL commands. */ {"get-ssl", 0, 0, pre_cmd_get_ssl, cmd_get_ssl, NULL, "", RO}, {"del-ssl", 0, 0, pre_cmd_del_ssl, cmd_del_ssl, NULL, "", RW}, -- 2.30.2