OVS_VSCTL_CLEANUP
AT_CLEANUP
+AT_SETUP([--id option on create, get commands])
+AT_KEYWORDS([ovs-vsctl])
+OVS_VSCTL_SETUP
+AT_CHECK([RUN_OVS_VSCTL([add-br br0],
+ [add-port br0 eth0],
+ [add-port br0 eth1])])
+AT_CHECK(
+ [RUN_OVS_VSCTL_TOGETHER(
+ [set bridge br0 mirrors=@m],
+ [--id=@eth0 get port eth0],
+ [--id=@eth1 get port eth1],
+ [--id=@m create mirror name=mymirror select-dst-port=@eth0 select-src-port=@eth0 output-port=@eth1])],
+ [0], [stdout], [], [OVS_VSCTL_CLEANUP])
+AT_CHECK(
+ [perl $srcdir/uuidfilt.pl stdout], [0], [dnl
+
+
+
+<0>
+],
+ [], [OVS_VSCTL_CLEANUP])
+AT_CHECK(
+ [RUN_OVS_VSCTL(
+ [list port eth0 eth1],
+ [list mirror],
+ [list bridge br0])],
+ [0], [stdout], [], [OVS_VSCTL_CLEANUP])
+AT_CHECK(
+ [sed -n -e '/uuid/p' -e '/name/p' -e '/mirrors/p' -e '/select/p' -e '/output/p' < stdout | $srcdir/uuidfilt.pl], [0], [dnl
+[_uuid : <0>
+name : "eth0"
+_uuid : <1>
+name : "eth1"
+_uuid : <2>
+name : mymirror
+output_port : <1>
+output_vlan : []
+select_all : false
+select_dst_port : [<0>]
+select_src_port : [<0>]
+select_vlan : []
+_uuid : <3>
+mirrors : [<2>]
+name : "br0"
+]],
+ [], [OVS_VSCTL_CLEANUP])
+OVS_VSCTL_CLEANUP
+AT_CLEANUP
+
dnl This test really shows a bug -- "create" followed by "list" in
dnl the same execution shows the wrong UUID on the "list" command.
dnl The bug is documented in ovs-vsctl.8.
.IP "UUID"
Either a universally unique identifier in the style of RFC 4122,
e.g. \fBf81d4fae\-7dec\-11d0\-a765\-00a0c91e6bf6\fR, or an \fB@\fIname\fR
-defined by the \fBcreate\fR command within the same \fBovs\-vsctl\fR
+defined by a \fBget\fR or \fBcreate\fR command within the same \fBovs\-vsctl\fR
invocation.
.PP
Multiple values in a single column may be separated by spaces or a
The UUIDs shown for rows created in the same \fBovs\-vsctl\fR
invocation will be wrong.
.
-.IP "[\fB\-\-if\-exists\fR] \fBget \fItable record column\fR[\fB:\fIkey\fR]..."
+.IP "[\fB\-\-id=@\fIname\fR] [\fB\-\-if\-exists\fR] \fBget \fItable record \fR[\fIcolumn\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 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
+If \fB@\fIname\fR is specified, then the UUID for \fIrecord\fR may be
+referred to by that name later in the same \fBovs\-vsctl\fR
+invocation in contexts where a UUID is expected.
.
.IP "\fBset \fItable record column\fR[\fB:\fIkey\fR]\fB=\fIvalue\fR..."
Sets the value of each specified \fIcolumn\fR in the given
}
}
+static struct uuid *
+create_symbol(struct ovsdb_symbol_table *symtab, const char *id, bool *newp)
+{
+ struct ovsdb_symbol *symbol;
+
+ if (id[0] != '@') {
+ vsctl_fatal("row id \"%s\" does not begin with \"@\"", id);
+ }
+
+ if (newp) {
+ *newp = ovsdb_symbol_table_get(symtab, id) == NULL;
+ }
+
+ symbol = ovsdb_symbol_table_insert(symtab, id);
+ if (symbol->used) {
+ vsctl_fatal("row id \"%s\" may only be specified on one --id option",
+ id);
+ }
+ symbol->used = true;
+ return &symbol->uuid;
+}
+
static char *
missing_operator_error(const char *arg, const char **allowed_operators,
size_t n_allowed)
static void
cmd_get(struct vsctl_context *ctx)
{
+ const char *id = shash_find_data(&ctx->options, "--id");
bool if_exists = shash_find(&ctx->options, "--if-exists");
const char *table_name = ctx->argv[1];
const char *record_id = ctx->argv[2];
table = get_table(table_name);
row = must_get_row(ctx, table, record_id);
+ if (id) {
+ bool new;
+
+ *create_symbol(ctx->symtab, id, &new) = row->uuid;
+ if (!new) {
+ vsctl_fatal("row id \"%s\" specified on \"get\" command was used "
+ "before it was defined", id);
+ }
+ }
for (i = 3; i < ctx->argc; i++) {
const struct ovsdb_idl_column *column;
const struct ovsdb_datum *datum;
const struct uuid *uuid;
int i;
- if (id) {
- struct ovsdb_symbol *symbol;
-
- if (id[0] != '@') {
- vsctl_fatal("row id \"%s\" does not begin with \"@\"", id);
- }
-
- symbol = ovsdb_symbol_table_insert(ctx->symtab, id);
- if (symbol->used) {
- vsctl_fatal("row id \"%s\" may only be used to insert a single "
- "row", id);
- }
- symbol->used = true;
-
- uuid = &symbol->uuid;
- } else {
- uuid = NULL;
- }
+ uuid = id ? create_symbol(ctx->symtab, id, NULL) : NULL;
table = get_table(table_name);
row = ovsdb_idl_txn_insert(ctx->txn, table->class, uuid);
{"emer-reset", 0, 0, cmd_emer_reset, NULL, ""},
/* Parameter commands. */
- {"get", 3, INT_MAX, cmd_get, NULL, "--if-exists"},
+ {"get", 2, INT_MAX, cmd_get, NULL, "--if-exists,--id="},
{"list", 1, INT_MAX, cmd_list, NULL, ""},
{"set", 3, INT_MAX, cmd_set, NULL, ""},
{"add", 4, INT_MAX, cmd_add, NULL, ""},