From 907a0edf84437f4f6951bc06747ccd18777863ca Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Tue, 21 Apr 2015 16:51:21 -0700 Subject: [PATCH] ovn-nbctl: Add "show" command. It's often useful to see an overview of the configuration. Signed-off-by: Justin Pettit Acked-by: Ben Pfaff --- ovn/ovn-nbctl.8.xml | 11 +++++++++ ovn/ovn-nbctl.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/ovn/ovn-nbctl.8.xml b/ovn/ovn-nbctl.8.xml index 2cf1257c6..710065236 100644 --- a/ovn/ovn-nbctl.8.xml +++ b/ovn/ovn-nbctl.8.xml @@ -9,6 +9,17 @@

Description

This utility can be used to manage the OVN northbound database.

+

General Commands

+ +
+
show [lswitch]
+
+ Prints a brief overview of the database contents. If + lswitch is provided, only records related to that + logical switch are shown. +
+
+

Logical Switch Commands

diff --git a/ovn/ovn-nbctl.c b/ovn/ovn-nbctl.c index ddc7b5177..38cdd3acb 100644 --- a/ovn/ovn-nbctl.c +++ b/ovn/ovn-nbctl.c @@ -48,6 +48,9 @@ usage(void) %s: OVN northbound DB management utility\n\ usage: %s [OPTIONS] COMMAND [ARG...]\n\ \n\ +General commands:\n\ + show print overview of database contents\n\ +\n\ Logical switch commands:\n\ lswitch-add [LSWITCH] create a logical switch named LSWITCH\n\ lswitch-del LSWITCH delete LSWITCH and all its ports\n\ @@ -129,6 +132,53 @@ lswitch_by_name_or_uuid(struct nbctl_context *nb_ctx, const char *id) return lswitch; } +static void +print_lswitch(const struct nbctl_context *nb_ctx, + const struct nbrec_logical_switch *lswitch) +{ + const struct nbrec_logical_port *lport; + + printf(" lswitch "UUID_FMT" (%s)\n", + UUID_ARGS(&lswitch->header_.uuid), lswitch->name); + + NBREC_LOGICAL_PORT_FOR_EACH(lport, nb_ctx->idl) { + int i; + + if (lport->lswitch == lswitch) { + printf(" lport %s\n", lport->name); + if (lport->parent_name && lport->n_tag) { + printf(" parent: %s, tag:%"PRIu64"\n", + lport->parent_name, lport->tag[0]); + } + if (lport->n_macs) { + printf(" macs:"); + for (i=0; i < lport->n_macs; i++) { + printf(" %s", lport->macs[i]); + } + printf("\n"); + } + } + } +} + +static void +do_show(struct ovs_cmdl_context *ctx) +{ + struct nbctl_context *nb_ctx = ctx->pvt; + const struct nbrec_logical_switch *lswitch; + + if (ctx->argc == 2) { + lswitch = lswitch_by_name_or_uuid(nb_ctx, ctx->argv[1]); + if (lswitch) { + print_lswitch(nb_ctx, lswitch); + } + } else { + NBREC_LOGICAL_SWITCH_FOR_EACH(lswitch, nb_ctx->idl) { + print_lswitch(nb_ctx, lswitch); + } + } +} + static void do_lswitch_add(struct ovs_cmdl_context *ctx) { @@ -574,6 +624,13 @@ parse_options(int argc, char *argv[]) } static const struct ovs_cmdl_command all_commands[] = { + { + .name = "show", + .usage = "[LSWITCH]", + .min_args = 0, + .max_args = 1, + .handler = do_show, + }, { .name = "lswitch-add", .usage = "[LSWITCH]", -- 2.39.5