[ovs-dev] [PATCH] ovn-nbctl: Add "show" command.

Justin Pettit jpettit at nicira.com
Tue Apr 21 23:54:37 UTC 2015


It's often useful to see an overview of the configuration.

Signed-off-by: Justin Pettit <jpettit at nicira.com>
---
 ovn/ovn-nbctl.8.xml |   11 +++++++++
 ovn/ovn-nbctl.c     |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/ovn/ovn-nbctl.8.xml b/ovn/ovn-nbctl.8.xml
index 2cf1257..7100652 100644
--- a/ovn/ovn-nbctl.8.xml
+++ b/ovn/ovn-nbctl.8.xml
@@ -9,6 +9,17 @@
     <h1>Description</h1>
     <p>This utility can be used to manage the OVN northbound database.</p>
 
+    <h1>General Commands</h1>
+
+    <dl>
+      <dt><code>show [<var>lswitch</var>]</code></dt>
+      <dd>
+        Prints a brief overview of the database contents.  If
+        <var>lswitch</var> is provided, only records related to that
+        logical switch are shown.
+      </dd>
+    </dl>
+
     <h1>Logical Switch Commands</h1>
 
     <dl>
diff --git a/ovn/ovn-nbctl.c b/ovn/ovn-nbctl.c
index ddc7b51..aff3c26 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\
@@ -130,6 +133,53 @@ lswitch_by_name_or_uuid(struct nbctl_context *nb_ctx, const char *id)
 }
 
 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)
 {
     struct nbctl_context *nb_ctx = ctx->pvt;
@@ -575,6 +625,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]",
         .min_args = 0,
-- 
1.7.5.4




More information about the dev mailing list