From: Ben Pfaff Date: Thu, 28 Jan 2010 22:00:22 +0000 (-0800) Subject: ovs-vsctl: Make "create" command print new row's UUID. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ef917b5699874c46131c1d8731fafc5246c0dd1;p=openvswitch ovs-vsctl: Make "create" command print new row's UUID. Also, document limitations of other commands regarding UUIDs of new rows. --- diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in index 84e978e6..d80310bf 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -455,6 +455,9 @@ overridden this way. .IP "\fBlist \fItable \fR[\fIrecord\fR]..." List the values of all columns of each specified \fIrecord\fR. If no records are specified, lists all the records in \fItable\fR. +.IP +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]..." Prints the value of each specified \fIcolumn\fR in the given @@ -498,7 +501,7 @@ that are allowed to be empty. .IP "\fB\-\-force create \fItable column\fR[\fB:\fIkey\fR]\fB=\fIvalue\fR..." Creates a new record in \fItable\fR and sets the initial values of each \fIcolumn\fR. Columns not explicitly set will receive their -default values. +default values. Outputs the UUID of the new row. .IP This command requires the \fB\-\-force\fR option. . diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index a555565a..60ab0f5b 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -2348,6 +2348,30 @@ cmd_create(struct vsctl_context *ctx) ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(&row->uuid)); } +/* This function may be used as the 'postprocess' function for commands that + * insert new rows into the database. It expects that the command's 'run' + * function prints the UUID reported by ovsdb_idl_txn_insert() as the command's + * sole output. It replaces that output by the row's permanent UUID assigned + * by the database server and appends a new-line. + * + * Currently we use this only for "create", because the higher-level commands + * are supposed to be independent of the actual structure of the vswitch + * configuration. */ +static void +post_create(struct vsctl_context *ctx) +{ + const struct uuid *real; + struct uuid dummy; + + uuid_from_string(&dummy, ds_cstr(&ctx->output)); + real = ovsdb_idl_txn_get_insert_uuid(ctx->txn, &dummy); + if (real) { + ds_clear(&ctx->output); + ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(real)); + } + ds_put_char(&ctx->output, '\n'); +} + static void cmd_destroy(struct vsctl_context *ctx) { @@ -2585,7 +2609,7 @@ static const struct vsctl_command_syntax all_commands[] = { {"add", 4, INT_MAX, cmd_add, NULL, "--force"}, {"remove", 4, INT_MAX, cmd_remove, NULL, "--force"}, {"clear", 3, INT_MAX, cmd_clear, NULL, "--force"}, - {"create", 2, INT_MAX, cmd_create, NULL, "--force"}, + {"create", 2, INT_MAX, cmd_create, post_create, "--force"}, {"destroy", 1, INT_MAX, cmd_destroy, NULL, "--force,--if-exists"}, {NULL, 0, 0, NULL, NULL, NULL},