int min_args;
int max_args;
vsctl_handler_func *run;
+ vsctl_handler_func *postprocess;
const char *options;
};
};
static const struct vsctl_column bridge_columns[] = {
+ {&ovsrec_bridge_col_controller, VSCF_READONLY, NULL},
{&ovsrec_bridge_col_datapath_id, VSCF_READONLY, NULL},
{&ovsrec_bridge_col_datapath_type, VSCF_READONLY, NULL},
- {&ovsrec_bridge_col_name, VSCF_READONLY, NULL},
- {&ovsrec_bridge_col_mirrors, VSCF_READONLY, NULL},
- {&ovsrec_bridge_col_other_config, 0, NULL},
+ {&ovsrec_bridge_col_external_ids, 0, NULL},
{&ovsrec_bridge_col_flood_vlans, 0, "[1,4095]"},
- {&ovsrec_bridge_col_controller, VSCF_READONLY, NULL},
+ {&ovsrec_bridge_col_mirrors, VSCF_READONLY, NULL},
+ {&ovsrec_bridge_col_name, VSCF_READONLY, NULL},
{&ovsrec_bridge_col_netflow, VSCF_READONLY, NULL},
- {&ovsrec_bridge_col_external_ids, 0, NULL},
+ {&ovsrec_bridge_col_other_config, 0, NULL},
{&ovsrec_bridge_col_ports, VSCF_READONLY, NULL},
{NULL, 0, NULL},
};
static const struct vsctl_column netflow_columns[] = {
{&ovsrec_netflow_col_active_timeout, 0, "[-1,]"},
{&ovsrec_netflow_col_add_id_to_interface, 0, NULL},
- {&ovsrec_netflow_col_targets, 0, IP_RE":"PORT_RE},
- {&ovsrec_netflow_col_engine_type, 0, "[0,255]"},
{&ovsrec_netflow_col_engine_id, 0, "[0,255]"},
+ {&ovsrec_netflow_col_engine_type, 0, "[0,255]"},
+ {&ovsrec_netflow_col_targets, 0, IP_RE":"PORT_RE},
{NULL, 0, NULL},
};
{&ovsrec_open_vswitch_col_bridges, VSCF_READONLY, NULL},
{&ovsrec_open_vswitch_col_controller, VSCF_READONLY, NULL},
{&ovsrec_open_vswitch_col_cur_cfg, VSCF_HIDDEN, NULL},
- {&ovsrec_open_vswitch_col_management_id, 0, "[0-9a-fA-F]{12}"},
{&ovsrec_open_vswitch_col_managers, 0, "p?(ssl|tcp|unix):.*"},
{&ovsrec_open_vswitch_col_next_cfg, VSCF_HIDDEN, NULL},
{&ovsrec_open_vswitch_col_ssl, VSCF_READONLY, NULL},
};
static const struct vsctl_column port_columns[] = {
- {&ovsrec_port_col_bond_updelay, 0, "[0,]"},
{&ovsrec_port_col_bond_downdelay, 0, "[0,]"},
{&ovsrec_port_col_bond_fake_iface, VSCF_READONLY, NULL},
+ {&ovsrec_port_col_bond_updelay, 0, "[0,]"},
{&ovsrec_port_col_external_ids, 0, NULL},
{&ovsrec_port_col_fake_bridge, VSCF_READONLY, NULL},
{&ovsrec_port_col_interfaces, VSCF_READONLY, NULL},
}
ovsdb_datum_destroy(&name, &id->name_column->type);
}
+ if (best_score && !referrer) {
+ ovs_fatal(0, "multiple rows in %s match \"%s\"",
+ table->class->name, record_id);
+ }
}
if (!referrer) {
return NULL;
*valuep = NULL;
}
if (*p != '\0') {
- error = xasprintf("%s: trailing garbage in argument at offset %td",
- arg, p - arg);
+ error = xasprintf("%s: trailing garbage \"%s\" in argument",
+ arg, p);
goto 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;
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);
table = get_table(table_name);
row = must_get_row(ctx, table, record_id);
die_if_error(get_column(table, column_name, &column));
+ if (column->flags & VSCF_READONLY && !force) {
+ ovs_fatal(0, "cannot modify read-only column %s in table %s",
+ column->idl->name, table->class->name);
+ }
+
type = &column->idl->type;
ovsdb_idl_txn_read(row, column->idl, &old);
for (i = 4; i < ctx->argc; i++) {
struct ovsdb_type add_type;
struct ovsdb_datum add;
- if (column->flags & VSCF_READONLY && !force) {
- ovs_fatal(0, "%s: cannot modify read-only column %s in table %s",
- ctx->argv[i], column->idl->name, table_name);
- }
-
add_type = *type;
add_type.n_min = 1;
add_type.n_max = UINT_MAX;
}
if (old.n > type->n_max) {
ovs_fatal(0, "\"add\" operation would put %u %s in column %s of "
- "table %s but at most %u are allowed",
+ "table %s but the maximum number is %u",
old.n,
type->value_type == OVSDB_TYPE_VOID ? "values" : "pairs",
- column->idl->name, table_name, type->n_max);
+ column->idl->name, table->class->name, type->n_max);
}
ovsdb_idl_txn_write(row, column->idl, &old);
}
table = get_table(table_name);
row = must_get_row(ctx, table, record_id);
die_if_error(get_column(table, column_name, &column));
+ if (column->flags & VSCF_READONLY && !force) {
+ ovs_fatal(0, "cannot modify read-only column %s in table %s",
+ column->idl->name, table->class->name);
+ }
+
type = &column->idl->type;
ovsdb_idl_txn_read(row, column->idl, &old);
for (i = 4; i < ctx->argc; i++) {
struct ovsdb_datum rm;
char *error;
- if (column->flags & VSCF_READONLY && !force) {
- ovs_fatal(0, "%s: cannot modify read-only column %s in table %s",
- ctx->argv[i], column->idl->name, table_name);
- }
-
rm_type = *type;
rm_type.n_min = 1;
rm_type.n_max = UINT_MAX;
}
if (old.n < type->n_min) {
ovs_fatal(0, "\"remove\" operation would put %u %s in column %s of "
- "table %s but at least %u are required",
+ "table %s but the minimun number is %u",
old.n,
type->value_type == OVSDB_TYPE_VOID ? "values" : "pairs",
- column->idl->name, table_name, type->n_min);
+ column->idl->name, table->class->name, type->n_min);
}
ovsdb_idl_txn_write(row, column->idl, &old);
}
type = &column->idl->type;
if (column->flags & VSCF_READONLY && !force) {
- ovs_fatal(0, "%s: cannot modify read-only column %s in table %s",
- ctx->argv[i], column->idl->name, table_name);
+ ovs_fatal(0, "cannot modify read-only column %s in table %s",
+ column->idl->name, table->class->name);
} else if (type->n_min > 0) {
ovs_fatal(0, "\"clear\" operation cannot be applied to column %s "
"of table %s, which is not allowed to be empty",
- column->idl->name, table_name);
+ column->idl->name, table->class->name);
}
ovsdb_datum_init_empty(&datum);
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)
{
if (wait_for_reload && status == TXN_SUCCESS) {
next_cfg = ovsdb_idl_txn_get_increment_new_value(txn);
}
+ for (c = commands; c < &commands[n_commands]; c++) {
+ if (c->syntax->postprocess) {
+ struct vsctl_context ctx;
+
+ vsctl_context_init(&ctx, c, idl, txn, ovs);
+ (c->syntax->postprocess)(&ctx);
+ vsctl_context_done(&ctx, c);
+ }
+ }
ovsdb_idl_txn_destroy(txn);
switch (status) {
static const struct vsctl_command_syntax all_commands[] = {
/* Open vSwitch commands. */
- {"init", 0, 0, cmd_init, ""},
+ {"init", 0, 0, cmd_init, NULL, ""},
/* Bridge commands. */
- {"add-br", 1, 3, cmd_add_br, ""},
- {"del-br", 1, 1, cmd_del_br, "--if-exists"},
- {"list-br", 0, 0, cmd_list_br, ""},
- {"br-exists", 1, 1, cmd_br_exists, ""},
- {"br-to-vlan", 1, 1, cmd_br_to_vlan, ""},
- {"br-to-parent", 1, 1, cmd_br_to_parent, ""},
- {"br-set-external-id", 2, 3, cmd_br_set_external_id, ""},
- {"br-get-external-id", 1, 2, cmd_br_get_external_id, ""},
+ {"add-br", 1, 3, cmd_add_br, NULL, ""},
+ {"del-br", 1, 1, cmd_del_br, NULL, "--if-exists"},
+ {"list-br", 0, 0, cmd_list_br, NULL, ""},
+ {"br-exists", 1, 1, cmd_br_exists, NULL, ""},
+ {"br-to-vlan", 1, 1, cmd_br_to_vlan, NULL, ""},
+ {"br-to-parent", 1, 1, cmd_br_to_parent, NULL, ""},
+ {"br-set-external-id", 2, 3, cmd_br_set_external_id, NULL, ""},
+ {"br-get-external-id", 1, 2, cmd_br_get_external_id, NULL, ""},
/* Port commands. */
- {"list-ports", 1, 1, cmd_list_ports, ""},
- {"add-port", 2, 2, cmd_add_port, ""},
- {"add-bond", 4, INT_MAX, cmd_add_bond, "--fake-iface"},
- {"del-port", 1, 2, cmd_del_port, "--if-exists"},
- {"port-to-br", 1, 1, cmd_port_to_br, ""},
+ {"list-ports", 1, 1, cmd_list_ports, NULL, ""},
+ {"add-port", 2, 2, cmd_add_port, NULL, ""},
+ {"add-bond", 4, INT_MAX, cmd_add_bond, NULL, "--fake-iface"},
+ {"del-port", 1, 2, cmd_del_port, NULL, "--if-exists"},
+ {"port-to-br", 1, 1, cmd_port_to_br, NULL, ""},
/* Interface commands. */
- {"list-ifaces", 1, 1, cmd_list_ifaces, ""},
- {"iface-to-br", 1, 1, cmd_iface_to_br, ""},
+ {"list-ifaces", 1, 1, cmd_list_ifaces, NULL, ""},
+ {"iface-to-br", 1, 1, cmd_iface_to_br, NULL, ""},
/* Controller commands. */
- {"get-controller", 0, 1, cmd_get_controller, ""},
- {"del-controller", 0, 1, cmd_del_controller, ""},
- {"set-controller", 1, 2, cmd_set_controller, ""},
- {"get-fail-mode", 0, 1, cmd_get_fail_mode, ""},
- {"del-fail-mode", 0, 1, cmd_del_fail_mode, ""},
- {"set-fail-mode", 1, 2, cmd_set_fail_mode, ""},
+ {"get-controller", 0, 1, cmd_get_controller, NULL, ""},
+ {"del-controller", 0, 1, cmd_del_controller, NULL, ""},
+ {"set-controller", 1, 2, cmd_set_controller, NULL, ""},
+ {"get-fail-mode", 0, 1, cmd_get_fail_mode, NULL, ""},
+ {"del-fail-mode", 0, 1, cmd_del_fail_mode, NULL, ""},
+ {"set-fail-mode", 1, 2, cmd_set_fail_mode, NULL, ""},
/* SSL commands. */
- {"get-ssl", 0, 0, cmd_get_ssl, ""},
- {"del-ssl", 0, 0, cmd_del_ssl, ""},
- {"set-ssl", 3, 3, cmd_set_ssl, "--bootstrap"},
+ {"get-ssl", 0, 0, cmd_get_ssl, NULL, ""},
+ {"del-ssl", 0, 0, cmd_del_ssl, NULL, ""},
+ {"set-ssl", 3, 3, cmd_set_ssl, NULL, "--bootstrap"},
/* Parameter commands. */
- {"get", 3, INT_MAX, cmd_get, ""},
- {"list", 1, INT_MAX, cmd_list, ""},
- {"set", 3, INT_MAX, cmd_set, "--force"},
- {"add", 4, INT_MAX, cmd_add, "--force"},
- {"remove", 4, INT_MAX, cmd_remove, "--force"},
- {"clear", 3, INT_MAX, cmd_clear, "--force"},
- {"create", 2, INT_MAX, cmd_create, "--force"},
- {"destroy", 1, INT_MAX, cmd_destroy, "--force,--if-exists"},
-
- {NULL, 0, 0, NULL, 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"},
+ {"remove", 4, INT_MAX, cmd_remove, NULL, "--force"},
+ {"clear", 3, INT_MAX, cmd_clear, 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},
};