db-ctl-base: Improve show command.
authorAlex Wang <alexw@nicira.com>
Fri, 12 Jun 2015 02:29:40 +0000 (19:29 -0700)
committerAlex Wang <alexw@nicira.com>
Tue, 23 Jun 2015 16:43:24 +0000 (09:43 -0700)
This commit adds improvement to 'show' command logic and allows it
to print key->table_ref maps.  The direct effect can be observed
from the tests/vtep-ctl.at change.  The improvement will also be
used in the ovn-sbctl implementation.

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/db-ctl-base.c
tests/vtep-ctl.at
vtep/vtep-ctl.c

index a1147aa..10884b4 100644 (file)
@@ -1595,6 +1595,45 @@ cmd_show_row(struct ctl_context *ctx, const struct ovsdb_idl_row *row,
                 }
                 continue;
             }
+        } else if (ovsdb_type_is_map(&column->type) &&
+                   column->type.value.type == OVSDB_TYPE_UUID &&
+                   column->type.value.u.uuid.refTableName) {
+            struct cmd_show_table *ref_show;
+            size_t j;
+
+            /* Prints the key to ref'ed table name map if the ref'ed table
+             * is also defined in 'cmd_show_tables'.  */
+            ref_show = cmd_show_find_table_by_name(
+                column->type.value.u.uuid.refTableName);
+            if (ref_show && ref_show->name_column) {
+                ds_put_char_multiple(&ctx->output, ' ', (level + 1) * 4);
+                ds_put_format(&ctx->output, "%s:\n", column->name);
+                for (j = 0; j < datum->n; j++) {
+                    const struct ovsdb_idl_row *ref_row;
+
+                    ref_row = ovsdb_idl_get_row_for_uuid(ctx->idl,
+                                                         ref_show->table,
+                                                         &datum->values[j].uuid);
+
+                    ds_put_char_multiple(&ctx->output, ' ', (level + 2) * 4);
+                    ovsdb_atom_to_string(&datum->keys[j], column->type.key.type,
+                                         &ctx->output);
+                    ds_put_char(&ctx->output, '=');
+                    if (ref_row) {
+                        const struct ovsdb_datum *ref_datum;
+
+                        ref_datum = ovsdb_idl_read(ref_row,
+                                                   ref_show->name_column);
+                        ovsdb_datum_to_string(ref_datum,
+                                              &ref_show->name_column->type,
+                                              &ctx->output);
+                    } else {
+                        ds_put_cstr(&ctx->output, "\"<null>\"");
+                    }
+                    ds_put_char(&ctx->output, '\n');
+                }
+                continue;
+            }
         }
 
         if (!ovsdb_datum_is_default(datum, &column->type)) {
index 67007bf..bb2df4f 100644 (file)
@@ -897,14 +897,16 @@ AT_CHECK([RUN_VTEP_CTL(
   [add-port a a1],
   [add-ls ls1],
   [bind-ls a a1 100 ls1],
-  [set Physical_Switch a tunnel_ips=[[1.2.3.4]]])], [0], [ignore], [], [VTEP_CTL_CLEANUP])
+  [set Physical_Switch a management_ips=[[4.3.2.1]] tunnel_ips=[[1.2.3.4]]])], [0], [ignore], [], [VTEP_CTL_CLEANUP])
 
 AT_CHECK([vtep-ctl --timeout=5 -vreconnect:emer --db=unix:socket show | tail -n+2 | sed 's/=[[a-f0-9-]][[a-f0-9-]]*\}/=<ls>\}/' ], [0], [dnl
     Manager "tcp:4.5.6.7"
     Physical_Switch a
+        management_ips: [["4.3.2.1"]]
         tunnel_ips: [["1.2.3.4"]]
         Physical_Port "a1"
-            vlan_bindings: {100=<ls>}
+            vlan_bindings:
+                100="ls1"
 ], [], [VTEP_CTL_CLEANUP])
 
 VTEP_CTL_CLEANUP
index 309c0b3..7f455df 100644 (file)
@@ -357,9 +357,9 @@ struct cmd_show_table cmd_show_tables[] = {
 
     {&vteprec_table_physical_switch,
      &vteprec_physical_switch_col_name,
-     {&vteprec_physical_switch_col_tunnel_ips,
-      &vteprec_physical_switch_col_ports,
-      NULL},
+     {&vteprec_physical_switch_col_management_ips,
+      &vteprec_physical_switch_col_tunnel_ips,
+      &vteprec_physical_switch_col_ports},
      false},
 
     {&vteprec_table_physical_port,
@@ -369,6 +369,13 @@ struct cmd_show_table cmd_show_tables[] = {
       NULL},
      false},
 
+    {&vteprec_table_logical_switch,
+     &vteprec_logical_switch_col_name,
+     {NULL,
+      NULL,
+      NULL},
+     false},
+
     {NULL, NULL, {NULL, NULL, NULL}, false}
 };