From: Ben Pfaff Date: Fri, 29 Jan 2010 00:03:52 +0000 (-0800) Subject: ovs-vsctl: Add --if-exists option to "get" command, for map columns. X-Git-Tag: v1.0.0~259^2~216 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=870aeb4aa05cf68b90e3e138dfe45b787e29ec55;p=sliver-openvswitch.git ovs-vsctl: Add --if-exists option to "get" command, for map columns. --- diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in index d80310bf4..84565b970 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -459,11 +459,16 @@ records are specified, lists all the records in \fItable\fR. The UUIDs shown for rows created in the same \fBovs\-vsctl\fR invocation will be wrong. . -.IP "\fBget \fItable record column\fR[\fB:\fIkey\fR]..." +.IP "[\fB\-\-if\-exists\fR] \fBget \fItable record column\fR[\fB:\fIkey\fR]..." Prints the value of each specified \fIcolumn\fR in the given \fIrecord\fR in \fItable\fR. For map columns, a \fIkey\fR may optionally be specified, in which case the value associated with \fIkey\fR in the column is printed, instead of the entire map. +.IP +For a map column, without \fB\-\-if\-exists\fR it is an error if +\fIkey\fR does not exist; with it, a blank line is printed. If +\fIcolumn\fR is not a map column or if \fIkey\fR is not specified, +\fB\-\-if\-exists\fR has no effect. . .IP "[\fB\-\-force\fR] \fBset \fItable record column\fR[\fB:\fIkey\fR]\fB=\fIvalue\fR..." Sets the value of each specified \fIcolumn\fR in the given diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index dcc4927a5..e180af430 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -1931,6 +1931,7 @@ error: static void cmd_get(struct vsctl_context *ctx) { + bool if_exists = shash_find(&ctx->options, "--if-exists"); const char *table_name = ctx->argv[1]; const char *record_id = ctx->argv[2]; const struct vsctl_table_class *table; @@ -1965,14 +1966,15 @@ cmd_get(struct vsctl_context *ctx) idx = ovsdb_datum_find_key(&datum, &key, column->idl->type.key_type); if (idx == UINT_MAX) { - ovs_fatal(0, "no key %s in %s record \"%s\" column %s", - key_string, table_name, record_id, - column->idl->name); - + if (!if_exists) { + ovs_fatal(0, "no key \"%s\" in %s record \"%s\" column %s", + key_string, table->class->name, record_id, + column->idl->name); + } + } else { + ovsdb_atom_to_string(&datum.values[idx], + column->idl->type.value_type, out); } - ovsdb_atom_to_string(&datum.values[idx], - column->idl->type.value_type, out); - ovsdb_atom_destroy(&key, column->idl->type.key_type); } else { ovsdb_datum_to_string(&datum, &column->idl->type, out); @@ -2607,7 +2609,7 @@ static const struct vsctl_command_syntax all_commands[] = { {"set-ssl", 3, 3, cmd_set_ssl, NULL, "--bootstrap"}, /* Parameter commands. */ - {"get", 3, INT_MAX, cmd_get, NULL, ""}, + {"get", 3, INT_MAX, cmd_get, NULL, "--if-exists"}, {"list", 1, INT_MAX, cmd_list, NULL, ""}, {"set", 3, INT_MAX, cmd_set, NULL, "--force"}, {"add", 4, INT_MAX, cmd_add, NULL, "--force"},