Adds a new "show-console" command to ovs-vsctl which displays the contents of the new "console" column.
Signed-off-by: Thomas Graf <tg...@redhat.com> --- utilities/ovs-vsctl.8.in | 11 ++++++++ utilities/ovs-vsctl.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in index 1b80d05..9a04de4 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -456,6 +456,17 @@ require the controller to send the CA certificate, but \fBovs\-controller\fR(8) can be configured to do so with the \fB\-\-peer\-ca\-cert\fR option. . +.SS "Console Commands" +. +These commands query and control the logging console. +. +.IP "[\fB\-\-show\-meta] \fBshow\-console\fR" +Prints contents of logging console. +.IP +If \fB\-\-show\-meta\fR is specified, additional meta data is printed +including the message number and the configuration database sequence +number. +. .SS "Database Commands" . These commands query and modify the contents of \fBovsdb\fR tables. diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index fda3a89..8d85e75 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -1415,6 +1415,76 @@ cmd_emer_reset(struct vsctl_context *ctx) } static void +pre_cmd_show_console(struct vsctl_context *ctx) +{ + ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_console); +} + +static void +extract_key_and_seq(const struct smap_node *node, int *key, int *seq) +{ + char *nptr; + + *key = strtoul(node->key, &nptr, 10); + *seq = *nptr == ':' ? strtoul(++nptr, NULL, 10) : 0; +} + +static int +compare_log_key(const void *a_, const void *b_) +{ + const struct smap_node *const *a = a_; + const struct smap_node *const *b = b_; + int ret, cfg_a, cfg_b, seq_a, seq_b; + + extract_key_and_seq(*a, &cfg_a, &seq_a); + extract_key_and_seq(*b, &cfg_b, &seq_b); + + ret = cfg_a - cfg_b; + if (!ret) + ret = seq_a - seq_b; + + return ret; +} + +static void +show_console(const struct ovsrec_open_vswitch *ovs, bool print_key) +{ + const struct smap_node **sorted; + struct smap_node *node; + size_t i, n; + + if (smap_is_empty(&ovs->console)) + return; + + n = smap_count(&ovs->console); + sorted = xmalloc(n * sizeof(*sorted)); + i = 0; + SMAP_FOR_EACH (node, &ovs->console) { + sorted[i++] = node; + } + assert(i == n); + + qsort(sorted, n, sizeof(*sorted), compare_log_key); + + for (i = 0; i < smap_count(&ovs->console); i++) { + if (print_key) + printf("%s ", sorted[i]->key); + + printf("%s\n", sorted[i]->value); + } + + free(sorted); +} +static void +cmd_show_console(struct vsctl_context *ctx) +{ + const struct ovsrec_open_vswitch *ovs = ctx->ovs; + bool show_key = shash_find(&ctx->options, "--show-meta"); + + show_console(ovs, show_key); +} + +static void cmd_add_br(struct vsctl_context *ctx) { bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL; @@ -4006,6 +4076,9 @@ static const struct vsctl_command_syntax all_commands[] = { /* Switch commands. */ {"emer-reset", 0, 0, pre_cmd_emer_reset, cmd_emer_reset, NULL, "", RW}, + /* Console commands. */ + {"show-console", 0, 0, pre_cmd_show_console, cmd_show_console, NULL, "--show-meta", RO}, + /* Database commands. */ {"comment", 0, INT_MAX, NULL, NULL, NULL, "", RO}, {"get", 2, INT_MAX, pre_cmd_get, cmd_get, NULL, "--if-exists,--id=", RO}, -- 1.7.11.7 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev