Skip to content

Commit

Permalink
db-ctl-base: Improve show command.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
yew011 committed Jun 23, 2015
1 parent 3935f67 commit 31d2b7c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
39 changes: 39 additions & 0 deletions lib/db-ctl-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
6 changes: 4 additions & 2 deletions tests/vtep-ctl.at
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions vtep/vtep-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}
};

Expand Down

0 comments on commit 31d2b7c

Please sign in to comment.