2 * Copyright (c) 2009, 2010 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
30 #include "command-line.h"
33 #include "dynamic-string.h"
35 #include "ovsdb-data.h"
36 #include "ovsdb-idl.h"
37 #include "poll-loop.h"
39 #include "stream-ssl.h"
41 #include "vswitchd/vswitch-idl.h"
46 VLOG_DEFINE_THIS_MODULE(vsctl);
48 /* vsctl_fatal() also logs the error, so it is preferred in this file. */
49 #define ovs_fatal please_use_vsctl_fatal_instead_of_ovs_fatal
53 /* A command supported by ovs-vsctl. */
54 struct vsctl_command_syntax {
55 const char *name; /* e.g. "add-br" */
56 int min_args; /* Min number of arguments following name. */
57 int max_args; /* Max number of arguments following name. */
59 /* If nonnull, calls ovsdb_idl_add_column() or ovsdb_idl_add_table() for
60 * each column or table in ctx->idl that it uses. */
61 void (*prerequisites)(struct vsctl_context *ctx);
63 /* Does the actual work of the command and puts the command's output, if
64 * any, in ctx->output.
66 * Alternatively, if some prerequisite of the command is not met and the
67 * caller should wait for something to change and then retry, it may set
68 * ctx->try_again to true. (Only the "wait-until" command currently does
70 void (*run)(struct vsctl_context *ctx);
72 /* If nonnull, called after the transaction has been successfully
73 * committed. ctx->output is the output from the "run" function, which
74 * this function may modify and otherwise postprocess as needed. (Only the
75 * "create" command currently does any postprocessing.) */
76 void (*postprocess)(struct vsctl_context *ctx);
78 /* A comma-separated list of supported options, e.g. "--a,--b", or the
79 * empty string if the command does not support any options. */
81 enum { RO, RW } mode; /* Does this command modify the database? */
84 struct vsctl_command {
85 /* Data that remains constant after initialization. */
86 const struct vsctl_command_syntax *syntax;
91 /* Data modified by commands. */
95 /* --db: The database server to contact. */
96 static const char *db;
98 /* --oneline: Write each command's output as a single line? */
101 /* --dry-run: Do not commit any changes. */
104 /* --no-wait: Wait for ovs-vswitchd to reload its configuration? */
105 static bool wait_for_reload = true;
107 /* --timeout: Time to wait for a connection to 'db'. */
110 /* All supported commands. */
111 static const struct vsctl_command_syntax all_commands[];
113 /* The IDL we're using and the current transaction, if any.
114 * This is for use by vsctl_exit() only, to allow it to clean up.
115 * Other code should use its context arguments. */
116 static struct ovsdb_idl *the_idl;
117 static struct ovsdb_idl_txn *the_idl_txn;
119 static void vsctl_exit(int status) NO_RETURN;
120 static void vsctl_fatal(const char *, ...) PRINTF_FORMAT(1, 2) NO_RETURN;
121 static char *default_db(void);
122 static void usage(void) NO_RETURN;
123 static void parse_options(int argc, char *argv[]);
124 static bool might_write_to_db(char **argv);
126 static struct vsctl_command *parse_commands(int argc, char *argv[],
127 size_t *n_commandsp);
128 static void parse_command(int argc, char *argv[], struct vsctl_command *);
129 static const struct vsctl_command_syntax *find_command(const char *name);
130 static void run_prerequisites(struct vsctl_command[], size_t n_commands,
132 static void do_vsctl(const char *args,
133 struct vsctl_command *, size_t n_commands,
136 static const struct vsctl_table_class *get_table(const char *table_name);
137 static void set_column(const struct vsctl_table_class *,
138 const struct ovsdb_idl_row *, const char *arg,
139 struct ovsdb_symbol_table *);
142 main(int argc, char *argv[])
144 extern struct vlog_module VLM_reconnect;
145 struct ovsdb_idl *idl;
146 struct vsctl_command *commands;
150 set_program_name(argv[0]);
151 signal(SIGPIPE, SIG_IGN);
152 vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
153 vlog_set_levels(&VLM_reconnect, VLF_ANY_FACILITY, VLL_WARN);
156 /* Log our arguments. This is often valuable for debugging systems. */
157 args = process_escape_args(argv);
158 VLOG(might_write_to_db(argv) ? VLL_INFO : VLL_DBG, "Called as %s", args);
160 /* Parse command line. */
161 parse_options(argc, argv);
162 commands = parse_commands(argc - optind, argv + optind, &n_commands);
168 /* Initialize IDL. */
169 idl = the_idl = ovsdb_idl_create(db, &ovsrec_idl_class, false);
170 run_prerequisites(commands, n_commands, idl);
172 /* Now execute the commands. */
174 if (ovsdb_idl_run(idl)) {
175 do_vsctl(args, commands, n_commands, idl);
184 parse_options(int argc, char *argv[])
187 OPT_DB = UCHAR_MAX + 1,
195 static struct option long_options[] = {
196 {"db", required_argument, 0, OPT_DB},
197 {"no-syslog", no_argument, 0, OPT_NO_SYSLOG},
198 {"no-wait", no_argument, 0, OPT_NO_WAIT},
199 {"dry-run", no_argument, 0, OPT_DRY_RUN},
200 {"oneline", no_argument, 0, OPT_ONELINE},
201 {"timeout", required_argument, 0, 't'},
202 {"help", no_argument, 0, 'h'},
203 {"version", no_argument, 0, 'V'},
206 STREAM_SSL_LONG_OPTIONS
207 {"peer-ca-cert", required_argument, 0, OPT_PEER_CA_CERT},
211 char *tmp, *short_options;
213 tmp = long_options_to_short_options(long_options);
214 short_options = xasprintf("+%s", tmp);
220 c = getopt_long(argc, argv, short_options, long_options, NULL);
235 vlog_set_levels(&VLM_vsctl, VLF_SYSLOG, VLL_WARN);
239 wait_for_reload = false;
250 OVS_PRINT_VERSION(0, 0);
254 timeout = strtoul(optarg, NULL, 10);
256 vsctl_fatal("value %s on -t or --timeout is invalid",
264 STREAM_SSL_OPTION_HANDLERS
266 case OPT_PEER_CA_CERT:
267 stream_ssl_set_peer_ca_cert_file(optarg);
285 static struct vsctl_command *
286 parse_commands(int argc, char *argv[], size_t *n_commandsp)
288 struct vsctl_command *commands;
289 size_t n_commands, allocated_commands;
293 n_commands = allocated_commands = 0;
295 for (start = i = 0; i <= argc; i++) {
296 if (i == argc || !strcmp(argv[i], "--")) {
298 if (n_commands >= allocated_commands) {
299 struct vsctl_command *c;
301 commands = x2nrealloc(commands, &allocated_commands,
303 for (c = commands; c < &commands[n_commands]; c++) {
304 shash_moved(&c->options);
307 parse_command(i - start, &argv[start],
308 &commands[n_commands++]);
314 vsctl_fatal("missing command name (use --help for help)");
316 *n_commandsp = n_commands;
321 parse_command(int argc, char *argv[], struct vsctl_command *command)
323 const struct vsctl_command_syntax *p;
324 struct shash_node *node;
328 shash_init(&command->options);
329 for (i = 0; i < argc; i++) {
330 const char *option = argv[i];
334 if (option[0] != '-') {
338 equals = strchr(option, '=');
340 key = xmemdup0(option, equals - option);
341 value = xstrdup(equals + 1);
343 key = xstrdup(option);
347 if (shash_find(&command->options, key)) {
348 vsctl_fatal("'%s' option specified multiple times", argv[i]);
350 shash_add_nocopy(&command->options, key, value);
353 vsctl_fatal("missing command name");
356 p = find_command(argv[i]);
358 vsctl_fatal("unknown command '%s'; use --help for help", argv[i]);
361 SHASH_FOR_EACH (node, &command->options) {
362 const char *s = strstr(p->options, node->name);
363 int end = s ? s[strlen(node->name)] : EOF;
365 if (end != '=' && end != ',' && end != ' ' && end != '\0') {
366 vsctl_fatal("'%s' command has no '%s' option",
367 argv[i], node->name);
369 if ((end == '=') != (node->data != NULL)) {
371 vsctl_fatal("missing argument to '%s' option on '%s' "
372 "command", node->name, argv[i]);
374 vsctl_fatal("'%s' option on '%s' does not accept an "
375 "argument", node->name, argv[i]);
380 n_arg = argc - i - 1;
381 if (n_arg < p->min_args) {
382 vsctl_fatal("'%s' command requires at least %d arguments",
383 p->name, p->min_args);
384 } else if (n_arg > p->max_args) {
387 for (j = i + 1; j < argc; j++) {
388 if (argv[j][0] == '-') {
389 vsctl_fatal("'%s' command takes at most %d arguments "
390 "(note that options must precede command "
391 "names and follow a \"--\" argument)",
392 p->name, p->max_args);
396 vsctl_fatal("'%s' command takes at most %d arguments",
397 p->name, p->max_args);
401 command->argc = n_arg + 1;
402 command->argv = &argv[i];
405 /* Returns the "struct vsctl_command_syntax" for a given command 'name', or a
406 * null pointer if there is none. */
407 static const struct vsctl_command_syntax *
408 find_command(const char *name)
410 static struct shash commands = SHASH_INITIALIZER(&commands);
412 if (shash_is_empty(&commands)) {
413 const struct vsctl_command_syntax *p;
415 for (p = all_commands; p->name; p++) {
416 shash_add_assert(&commands, p->name, p);
420 return shash_find_data(&commands, name);
424 vsctl_fatal(const char *format, ...)
429 va_start(args, format);
430 message = xvasprintf(format, args);
433 vlog_set_levels(&VLM_vsctl, VLF_CONSOLE, VLL_EMER);
434 VLOG_ERR("%s", message);
435 ovs_error(0, "%s", message);
436 vsctl_exit(EXIT_FAILURE);
439 /* Frees the current transaction and the underlying IDL and then calls
442 * Freeing the transaction and the IDL is not strictly necessary, but it makes
443 * for a clean memory leak report from valgrind in the normal case. That makes
444 * it easier to notice real memory leaks. */
446 vsctl_exit(int status)
449 ovsdb_idl_txn_abort(the_idl_txn);
450 ovsdb_idl_txn_destroy(the_idl_txn);
452 ovsdb_idl_destroy(the_idl);
460 %s: ovs-vswitchd management utility\n\
461 usage: %s [OPTIONS] COMMAND [ARG...]\n\
464 add-br BRIDGE create a new bridge named BRIDGE\n\
465 add-br BRIDGE PARENT VLAN create new fake BRIDGE in PARENT on VLAN\n\
466 del-br BRIDGE delete BRIDGE and all of its ports\n\
467 list-br print the names of all the bridges\n\
468 br-exists BRIDGE test whether BRIDGE exists\n\
469 br-to-vlan BRIDGE print the VLAN which BRIDGE is on\n\
470 br-to-parent BRIDGE print the parent of BRIDGE\n\
471 br-set-external-id BRIDGE KEY VALUE set KEY on BRIDGE to VALUE\n\
472 br-set-external-id BRIDGE KEY unset KEY on BRIDGE\n\
473 br-get-external-id BRIDGE KEY print value of KEY on BRIDGE\n\
474 br-get-external-id BRIDGE list key-value pairs on BRIDGE\n\
477 list-ports BRIDGE print the names of all the ports on BRIDGE\n\
478 add-port BRIDGE PORT add network device PORT to BRIDGE\n\
479 add-bond BRIDGE PORT IFACE... add bonded port PORT in BRIDGE from IFACES\n\
480 del-port [BRIDGE] PORT delete PORT (which may be bonded) from BRIDGE\n\
481 port-to-br PORT print name of bridge that contains PORT\n\
482 A bond is considered to be a single port.\n\
484 Interface commands (a bond consists of multiple interfaces):\n\
485 list-ifaces BRIDGE print the names of all interfaces on BRIDGE\n\
486 iface-to-br IFACE print name of bridge that contains IFACE\n\
488 Controller commands:\n\
489 get-controller BRIDGE print the controller for BRIDGE\n\
490 del-controller BRIDGE delete the controller for BRIDGE\n\
491 set-controller BRIDGE TARGET set the controller for BRIDGE to TARGET\n\
492 get-fail-mode BRIDGE print the fail-mode for BRIDGE\n\
493 del-fail-mode BRIDGE delete the fail-mode for BRIDGE\n\
494 set-fail-mode BRIDGE MODE set the fail-mode for BRIDGE to MODE\n\
497 get-manager print all manager(s)\n\
498 del-manager delete all manager(s)\n\
499 set-manager TARGET... set the list of manager(s) to TARGET(s)\n\
502 get-ssl print the SSL configuration\n\
503 del-ssl delete the SSL configuration\n\
504 set-ssl PRIV-KEY CERT CA-CERT set the SSL configuration\n\
507 emer-reset reset switch to known good state\n\
509 Database commands:\n\
510 list TBL [REC] list RECord (or all records) in TBL\n\
511 get TBL REC COL[:KEY] print values of COLumns in RECord in TBL\n\
512 set TBL REC COL[:KEY]=VALUE set COLumn values in RECord in TBL\n\
513 add TBL REC COL [KEY=]VALUE add (KEY=)VALUE to COLumn in RECord in TBL\n\
514 remove TBL REC COL [KEY=]VALUE remove (KEY=)VALUE from COLumn\n\
515 clear TBL REC COL clear values from COLumn in RECord in TBL\n\
516 create TBL COL[:KEY]=VALUE create and initialize new record\n\
517 destroy TBL REC delete RECord from TBL\n\
518 wait-until TBL REC [COL[:KEY]=VALUE] wait until condition is true\n\
519 Potentially unsafe database commands require --force option.\n\
522 --db=DATABASE connect to DATABASE\n\
524 --oneline print exactly one line of output per command\n",
525 program_name, program_name, default_db());
529 -h, --help display this help message\n\
530 -V, --version display version information\n");
539 def = xasprintf("unix:%s/db.sock", ovs_rundir());
544 /* Returns true if it looks like this set of arguments might modify the
545 * database, otherwise false. (Not very smart, so it's prone to false
548 might_write_to_db(char **argv)
550 for (; *argv; argv++) {
551 const struct vsctl_command_syntax *p = find_command(*argv);
552 if (p && p->mode == RW) {
559 struct vsctl_context {
563 struct shash options;
565 /* Modifiable state. */
567 struct ovsdb_idl *idl;
568 struct ovsdb_idl_txn *txn;
569 struct ovsdb_symbol_table *symtab;
570 const struct ovsrec_open_vswitch *ovs;
573 /* A command may set this member to true if some prerequisite is not met
574 * and the caller should wait for something to change and then retry. */
578 struct vsctl_bridge {
579 struct ovsrec_bridge *br_cfg;
581 struct ovsrec_controller **ctrl;
584 struct vsctl_bridge *parent;
589 struct ovsrec_port *port_cfg;
590 struct vsctl_bridge *bridge;
594 struct ovsrec_interface *iface_cfg;
595 struct vsctl_port *port;
599 struct vsctl_context *ctx;
600 struct shash bridges; /* Maps from bridge name to struct vsctl_bridge. */
601 struct shash ports; /* Maps from port name to struct vsctl_port. */
602 struct shash ifaces; /* Maps from port name to struct vsctl_iface. */
606 vsctl_context_to_string(const struct vsctl_context *ctx)
608 const struct shash_node *node;
614 SHASH_FOR_EACH (node, &ctx->options) {
615 svec_add(&words, node->name);
617 for (i = 0; i < ctx->argc; i++) {
618 svec_add(&words, ctx->argv[i]);
620 svec_terminate(&words);
622 s = process_escape_args(words.names);
624 svec_destroy(&words);
630 verify_ports(struct vsctl_context *ctx)
632 if (!ctx->verified_ports) {
633 const struct ovsrec_bridge *bridge;
634 const struct ovsrec_port *port;
636 ovsrec_open_vswitch_verify_bridges(ctx->ovs);
637 OVSREC_BRIDGE_FOR_EACH (bridge, ctx->idl) {
638 ovsrec_bridge_verify_ports(bridge);
640 OVSREC_PORT_FOR_EACH (port, ctx->idl) {
641 ovsrec_port_verify_interfaces(port);
644 ctx->verified_ports = true;
648 static struct vsctl_bridge *
649 add_bridge(struct vsctl_info *b,
650 struct ovsrec_bridge *br_cfg, const char *name,
651 struct vsctl_bridge *parent, int vlan)
653 struct vsctl_bridge *br = xmalloc(sizeof *br);
655 br->name = xstrdup(name);
659 br->ctrl = parent->br_cfg->controller;
660 br->n_ctrl = parent->br_cfg->n_controller;
661 br->fail_mode = parent->br_cfg->fail_mode;
663 br->ctrl = br_cfg->controller;
664 br->n_ctrl = br_cfg->n_controller;
665 br->fail_mode = br_cfg->fail_mode;
667 shash_add(&b->bridges, br->name, br);
672 port_is_fake_bridge(const struct ovsrec_port *port_cfg)
674 return (port_cfg->fake_bridge
676 && *port_cfg->tag >= 1 && *port_cfg->tag <= 4095);
679 static struct vsctl_bridge *
680 find_vlan_bridge(struct vsctl_info *info,
681 struct vsctl_bridge *parent, int vlan)
683 struct shash_node *node;
685 SHASH_FOR_EACH (node, &info->bridges) {
686 struct vsctl_bridge *br = node->data;
687 if (br->parent == parent && br->vlan == vlan) {
696 free_info(struct vsctl_info *info)
698 struct shash_node *node;
700 SHASH_FOR_EACH (node, &info->bridges) {
701 struct vsctl_bridge *bridge = node->data;
705 shash_destroy(&info->bridges);
707 shash_destroy_free_data(&info->ports);
708 shash_destroy_free_data(&info->ifaces);
712 pre_get_info(struct vsctl_context *ctx)
714 ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_bridges);
716 ovsdb_idl_add_column(ctx->idl, &ovsrec_bridge_col_name);
717 ovsdb_idl_add_column(ctx->idl, &ovsrec_bridge_col_controller);
718 ovsdb_idl_add_column(ctx->idl, &ovsrec_bridge_col_fail_mode);
719 ovsdb_idl_add_column(ctx->idl, &ovsrec_bridge_col_ports);
721 ovsdb_idl_add_column(ctx->idl, &ovsrec_port_col_name);
722 ovsdb_idl_add_column(ctx->idl, &ovsrec_port_col_fake_bridge);
723 ovsdb_idl_add_column(ctx->idl, &ovsrec_port_col_tag);
724 ovsdb_idl_add_column(ctx->idl, &ovsrec_port_col_interfaces);
726 ovsdb_idl_add_column(ctx->idl, &ovsrec_interface_col_name);
730 get_info(struct vsctl_context *ctx, struct vsctl_info *info)
732 const struct ovsrec_open_vswitch *ovs = ctx->ovs;
733 struct shash bridges, ports;
737 shash_init(&info->bridges);
738 shash_init(&info->ports);
739 shash_init(&info->ifaces);
741 shash_init(&bridges);
743 for (i = 0; i < ovs->n_bridges; i++) {
744 struct ovsrec_bridge *br_cfg = ovs->bridges[i];
745 struct vsctl_bridge *br;
748 if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
749 VLOG_WARN("%s: database contains duplicate bridge name",
753 br = add_bridge(info, br_cfg, br_cfg->name, NULL, 0);
758 for (j = 0; j < br_cfg->n_ports; j++) {
759 struct ovsrec_port *port_cfg = br_cfg->ports[j];
761 if (!shash_add_once(&ports, port_cfg->name, NULL)) {
762 VLOG_WARN("%s: database contains duplicate port name",
767 if (port_is_fake_bridge(port_cfg)
768 && shash_add_once(&bridges, port_cfg->name, NULL)) {
769 add_bridge(info, NULL, port_cfg->name, br, *port_cfg->tag);
773 shash_destroy(&bridges);
774 shash_destroy(&ports);
776 shash_init(&bridges);
778 for (i = 0; i < ovs->n_bridges; i++) {
779 struct ovsrec_bridge *br_cfg = ovs->bridges[i];
780 struct vsctl_bridge *br;
783 if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
786 br = shash_find_data(&info->bridges, br_cfg->name);
787 for (j = 0; j < br_cfg->n_ports; j++) {
788 struct ovsrec_port *port_cfg = br_cfg->ports[j];
789 struct vsctl_port *port;
792 if (!shash_add_once(&ports, port_cfg->name, NULL)) {
796 if (port_is_fake_bridge(port_cfg)
797 && !shash_add_once(&bridges, port_cfg->name, NULL)) {
801 port = xmalloc(sizeof *port);
802 port->port_cfg = port_cfg;
804 && *port_cfg->tag >= 1 && *port_cfg->tag <= 4095) {
805 port->bridge = find_vlan_bridge(info, br, *port_cfg->tag);
812 shash_add(&info->ports, port_cfg->name, port);
814 for (k = 0; k < port_cfg->n_interfaces; k++) {
815 struct ovsrec_interface *iface_cfg = port_cfg->interfaces[k];
816 struct vsctl_iface *iface;
818 if (shash_find(&info->ifaces, iface_cfg->name)) {
819 VLOG_WARN("%s: database contains duplicate interface name",
824 iface = xmalloc(sizeof *iface);
825 iface->iface_cfg = iface_cfg;
827 shash_add(&info->ifaces, iface_cfg->name, iface);
831 shash_destroy(&bridges);
832 shash_destroy(&ports);
836 check_conflicts(struct vsctl_info *info, const char *name,
839 struct vsctl_iface *iface;
840 struct vsctl_port *port;
842 verify_ports(info->ctx);
844 if (shash_find(&info->bridges, name)) {
845 vsctl_fatal("%s because a bridge named %s already exists",
849 port = shash_find_data(&info->ports, name);
851 vsctl_fatal("%s because a port named %s already exists on "
852 "bridge %s", msg, name, port->bridge->name);
855 iface = shash_find_data(&info->ifaces, name);
857 vsctl_fatal("%s because an interface named %s already exists "
858 "on bridge %s", msg, name, iface->port->bridge->name);
864 static struct vsctl_bridge *
865 find_bridge(struct vsctl_info *info, const char *name, bool must_exist)
867 struct vsctl_bridge *br = shash_find_data(&info->bridges, name);
868 if (must_exist && !br) {
869 vsctl_fatal("no bridge named %s", name);
871 ovsrec_open_vswitch_verify_bridges(info->ctx->ovs);
875 static struct vsctl_bridge *
876 find_real_bridge(struct vsctl_info *info, const char *name, bool must_exist)
878 struct vsctl_bridge *br = find_bridge(info, name, must_exist);
879 if (br && br->parent) {
880 vsctl_fatal("%s is a fake bridge", name);
885 static struct vsctl_port *
886 find_port(struct vsctl_info *info, const char *name, bool must_exist)
888 struct vsctl_port *port = shash_find_data(&info->ports, name);
889 if (port && !strcmp(name, port->bridge->name)) {
892 if (must_exist && !port) {
893 vsctl_fatal("no port named %s", name);
895 verify_ports(info->ctx);
899 static struct vsctl_iface *
900 find_iface(struct vsctl_info *info, const char *name, bool must_exist)
902 struct vsctl_iface *iface = shash_find_data(&info->ifaces, name);
903 if (iface && !strcmp(name, iface->port->bridge->name)) {
906 if (must_exist && !iface) {
907 vsctl_fatal("no interface named %s", name);
909 verify_ports(info->ctx);
914 bridge_insert_port(struct ovsrec_bridge *br, struct ovsrec_port *port)
916 struct ovsrec_port **ports;
919 ports = xmalloc(sizeof *br->ports * (br->n_ports + 1));
920 for (i = 0; i < br->n_ports; i++) {
921 ports[i] = br->ports[i];
923 ports[br->n_ports] = port;
924 ovsrec_bridge_set_ports(br, ports, br->n_ports + 1);
929 bridge_delete_port(struct ovsrec_bridge *br, struct ovsrec_port *port)
931 struct ovsrec_port **ports;
934 ports = xmalloc(sizeof *br->ports * br->n_ports);
935 for (i = n = 0; i < br->n_ports; i++) {
936 if (br->ports[i] != port) {
937 ports[n++] = br->ports[i];
940 ovsrec_bridge_set_ports(br, ports, n);
945 ovs_insert_bridge(const struct ovsrec_open_vswitch *ovs,
946 struct ovsrec_bridge *bridge)
948 struct ovsrec_bridge **bridges;
951 bridges = xmalloc(sizeof *ovs->bridges * (ovs->n_bridges + 1));
952 for (i = 0; i < ovs->n_bridges; i++) {
953 bridges[i] = ovs->bridges[i];
955 bridges[ovs->n_bridges] = bridge;
956 ovsrec_open_vswitch_set_bridges(ovs, bridges, ovs->n_bridges + 1);
961 ovs_delete_bridge(const struct ovsrec_open_vswitch *ovs,
962 struct ovsrec_bridge *bridge)
964 struct ovsrec_bridge **bridges;
967 bridges = xmalloc(sizeof *ovs->bridges * ovs->n_bridges);
968 for (i = n = 0; i < ovs->n_bridges; i++) {
969 if (ovs->bridges[i] != bridge) {
970 bridges[n++] = ovs->bridges[i];
973 ovsrec_open_vswitch_set_bridges(ovs, bridges, n);
978 cmd_init(struct vsctl_context *ctx OVS_UNUSED)
983 pre_cmd_emer_reset(struct vsctl_context *ctx)
985 ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_managers);
986 ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_manager_options);
987 ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_ssl);
989 ovsdb_idl_add_column(ctx->idl, &ovsrec_bridge_col_controller);
990 ovsdb_idl_add_column(ctx->idl, &ovsrec_bridge_col_fail_mode);
991 ovsdb_idl_add_column(ctx->idl, &ovsrec_bridge_col_mirrors);
992 ovsdb_idl_add_column(ctx->idl, &ovsrec_bridge_col_netflow);
993 ovsdb_idl_add_column(ctx->idl, &ovsrec_bridge_col_sflow);
994 ovsdb_idl_add_column(ctx->idl, &ovsrec_bridge_col_flood_vlans);
995 ovsdb_idl_add_column(ctx->idl, &ovsrec_bridge_col_other_config);
997 ovsdb_idl_add_column(ctx->idl, &ovsrec_port_col_other_config);
999 ovsdb_idl_add_column(ctx->idl,
1000 &ovsrec_interface_col_ingress_policing_rate);
1001 ovsdb_idl_add_column(ctx->idl,
1002 &ovsrec_interface_col_ingress_policing_burst);
1006 cmd_emer_reset(struct vsctl_context *ctx)
1008 const struct ovsdb_idl *idl = ctx->idl;
1009 const struct ovsrec_bridge *br;
1010 const struct ovsrec_port *port;
1011 const struct ovsrec_interface *iface;
1012 const struct ovsrec_mirror *mirror, *next_mirror;
1013 const struct ovsrec_controller *ctrl, *next_ctrl;
1014 const struct ovsrec_manager *mgr, *next_mgr;
1015 const struct ovsrec_netflow *nf, *next_nf;
1016 const struct ovsrec_ssl *ssl, *next_ssl;
1017 const struct ovsrec_sflow *sflow, *next_sflow;
1019 /* Reset the Open_vSwitch table. */
1020 ovsrec_open_vswitch_set_managers(ctx->ovs, NULL, 0);
1021 ovsrec_open_vswitch_set_manager_options(ctx->ovs, NULL, 0);
1022 ovsrec_open_vswitch_set_ssl(ctx->ovs, NULL);
1024 OVSREC_BRIDGE_FOR_EACH (br, idl) {
1026 char *hw_key = "hwaddr";
1027 char *hw_val = NULL;
1029 ovsrec_bridge_set_controller(br, NULL, 0);
1030 ovsrec_bridge_set_fail_mode(br, NULL);
1031 ovsrec_bridge_set_mirrors(br, NULL, 0);
1032 ovsrec_bridge_set_netflow(br, NULL);
1033 ovsrec_bridge_set_sflow(br, NULL);
1034 ovsrec_bridge_set_flood_vlans(br, NULL, 0);
1036 /* We only want to save the "hwaddr" key from other_config. */
1037 for (i=0; i < br->n_other_config; i++) {
1038 if (!strcmp(br->key_other_config[i], hw_key)) {
1039 hw_val = br->value_other_config[i];
1044 char *val = xstrdup(hw_val);
1045 ovsrec_bridge_set_other_config(br, &hw_key, &val, 1);
1048 ovsrec_bridge_set_other_config(br, NULL, NULL, 0);
1052 OVSREC_PORT_FOR_EACH (port, idl) {
1053 ovsrec_port_set_other_config(port, NULL, NULL, 0);
1056 OVSREC_INTERFACE_FOR_EACH (iface, idl) {
1057 /* xxx What do we do about gre/patch devices created by mgr? */
1059 ovsrec_interface_set_ingress_policing_rate(iface, 0);
1060 ovsrec_interface_set_ingress_policing_burst(iface, 0);
1063 OVSREC_MIRROR_FOR_EACH_SAFE (mirror, next_mirror, idl) {
1064 ovsrec_mirror_delete(mirror);
1067 OVSREC_CONTROLLER_FOR_EACH_SAFE (ctrl, next_ctrl, idl) {
1068 ovsrec_controller_delete(ctrl);
1071 OVSREC_MANAGER_FOR_EACH_SAFE (mgr, next_mgr, idl) {
1072 ovsrec_manager_delete(mgr);
1075 OVSREC_NETFLOW_FOR_EACH_SAFE (nf, next_nf, idl) {
1076 ovsrec_netflow_delete(nf);
1079 OVSREC_SSL_FOR_EACH_SAFE (ssl, next_ssl, idl) {
1080 ovsrec_ssl_delete(ssl);
1083 OVSREC_SFLOW_FOR_EACH_SAFE (sflow, next_sflow, idl) {
1084 ovsrec_sflow_delete(sflow);
1089 cmd_add_br(struct vsctl_context *ctx)
1091 bool may_exist = shash_find(&ctx->options, "--may-exist") != 0;
1092 const char *br_name, *parent_name;
1093 struct vsctl_info info;
1096 br_name = ctx->argv[1];
1097 if (ctx->argc == 2) {
1100 } else if (ctx->argc == 4) {
1101 parent_name = ctx->argv[2];
1102 vlan = atoi(ctx->argv[3]);
1103 if (vlan < 1 || vlan > 4095) {
1104 vsctl_fatal("%s: vlan must be between 1 and 4095", ctx->argv[0]);
1107 vsctl_fatal("'%s' command takes exactly 1 or 3 arguments",
1111 get_info(ctx, &info);
1113 struct vsctl_bridge *br;
1115 br = find_bridge(&info, br_name, false);
1119 vsctl_fatal("\"--may-exist add-br %s\" but %s is "
1120 "a VLAN bridge for VLAN %d",
1121 br_name, br_name, br->vlan);
1125 vsctl_fatal("\"--may-exist add-br %s %s %d\" but %s "
1126 "is not a VLAN bridge",
1127 br_name, parent_name, vlan, br_name);
1128 } else if (strcmp(br->parent->name, parent_name)) {
1129 vsctl_fatal("\"--may-exist add-br %s %s %d\" but %s "
1130 "has the wrong parent %s",
1131 br_name, parent_name, vlan,
1132 br_name, br->parent->name);
1133 } else if (br->vlan != vlan) {
1134 vsctl_fatal("\"--may-exist add-br %s %s %d\" but %s "
1135 "is a VLAN bridge for the wrong VLAN %d",
1136 br_name, parent_name, vlan, br_name, br->vlan);
1142 check_conflicts(&info, br_name,
1143 xasprintf("cannot create a bridge named %s", br_name));
1146 struct ovsrec_port *port;
1147 struct ovsrec_interface *iface;
1148 struct ovsrec_bridge *br;
1150 iface = ovsrec_interface_insert(ctx->txn);
1151 ovsrec_interface_set_name(iface, br_name);
1152 ovsrec_interface_set_type(iface, "internal");
1154 port = ovsrec_port_insert(ctx->txn);
1155 ovsrec_port_set_name(port, br_name);
1156 ovsrec_port_set_interfaces(port, &iface, 1);
1158 br = ovsrec_bridge_insert(ctx->txn);
1159 ovsrec_bridge_set_name(br, br_name);
1160 ovsrec_bridge_set_ports(br, &port, 1);
1162 ovs_insert_bridge(ctx->ovs, br);
1164 struct vsctl_bridge *parent;
1165 struct ovsrec_port *port;
1166 struct ovsrec_interface *iface;
1167 struct ovsrec_bridge *br;
1170 parent = find_bridge(&info, parent_name, false);
1171 if (parent && parent->vlan) {
1172 vsctl_fatal("cannot create bridge with fake bridge as parent");
1175 vsctl_fatal("parent bridge %s does not exist", parent_name);
1177 br = parent->br_cfg;
1179 iface = ovsrec_interface_insert(ctx->txn);
1180 ovsrec_interface_set_name(iface, br_name);
1181 ovsrec_interface_set_type(iface, "internal");
1183 port = ovsrec_port_insert(ctx->txn);
1184 ovsrec_port_set_name(port, br_name);
1185 ovsrec_port_set_interfaces(port, &iface, 1);
1186 ovsrec_port_set_fake_bridge(port, true);
1187 ovsrec_port_set_tag(port, &tag, 1);
1189 bridge_insert_port(br, port);
1196 del_port(struct vsctl_info *info, struct vsctl_port *port)
1198 struct shash_node *node;
1200 SHASH_FOR_EACH (node, &info->ifaces) {
1201 struct vsctl_iface *iface = node->data;
1202 if (iface->port == port) {
1203 ovsrec_interface_delete(iface->iface_cfg);
1206 ovsrec_port_delete(port->port_cfg);
1208 bridge_delete_port((port->bridge->parent
1209 ? port->bridge->parent->br_cfg
1210 : port->bridge->br_cfg), port->port_cfg);
1214 cmd_del_br(struct vsctl_context *ctx)
1216 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1217 struct vsctl_bridge *bridge;
1218 struct vsctl_info info;
1220 get_info(ctx, &info);
1221 bridge = find_bridge(&info, ctx->argv[1], must_exist);
1223 struct shash_node *node;
1225 SHASH_FOR_EACH (node, &info.ports) {
1226 struct vsctl_port *port = node->data;
1227 if (port->bridge == bridge || port->bridge->parent == bridge
1228 || !strcmp(port->port_cfg->name, bridge->name)) {
1229 del_port(&info, port);
1232 if (bridge->br_cfg) {
1233 ovsrec_bridge_delete(bridge->br_cfg);
1234 ovs_delete_bridge(ctx->ovs, bridge->br_cfg);
1241 output_sorted(struct svec *svec, struct ds *output)
1247 SVEC_FOR_EACH (i, name, svec) {
1248 ds_put_format(output, "%s\n", name);
1253 cmd_list_br(struct vsctl_context *ctx)
1255 struct shash_node *node;
1256 struct vsctl_info info;
1257 struct svec bridges;
1259 get_info(ctx, &info);
1261 svec_init(&bridges);
1262 SHASH_FOR_EACH (node, &info.bridges) {
1263 struct vsctl_bridge *br = node->data;
1264 svec_add(&bridges, br->name);
1266 output_sorted(&bridges, &ctx->output);
1267 svec_destroy(&bridges);
1273 cmd_br_exists(struct vsctl_context *ctx)
1275 struct vsctl_info info;
1277 get_info(ctx, &info);
1278 if (!find_bridge(&info, ctx->argv[1], false)) {
1284 /* Returns true if 'b_prefix' (of length 'b_prefix_len') concatenated with 'b'
1285 * equals 'a', false otherwise. */
1287 key_matches(const char *a,
1288 const char *b_prefix, size_t b_prefix_len, const char *b)
1290 return !strncmp(a, b_prefix, b_prefix_len) && !strcmp(a + b_prefix_len, b);
1294 set_external_id(char **old_keys, char **old_values, size_t old_n,
1295 char *key, char *value,
1296 char ***new_keysp, char ***new_valuesp, size_t *new_np)
1303 new_keys = xmalloc(sizeof *new_keys * (old_n + 1));
1304 new_values = xmalloc(sizeof *new_values * (old_n + 1));
1306 for (i = 0; i < old_n; i++) {
1307 if (strcmp(key, old_keys[i])) {
1308 new_keys[new_n] = old_keys[i];
1309 new_values[new_n] = old_values[i];
1314 new_keys[new_n] = key;
1315 new_values[new_n] = value;
1318 *new_keysp = new_keys;
1319 *new_valuesp = new_values;
1324 pre_cmd_br_set_external_id(struct vsctl_context *ctx)
1327 ovsdb_idl_add_column(ctx->idl, &ovsrec_bridge_col_external_ids);
1328 ovsdb_idl_add_column(ctx->idl, &ovsrec_port_col_external_ids);
1332 cmd_br_set_external_id(struct vsctl_context *ctx)
1334 struct vsctl_info info;
1335 struct vsctl_bridge *bridge;
1336 char **keys, **values;
1339 get_info(ctx, &info);
1340 bridge = find_bridge(&info, ctx->argv[1], true);
1341 if (bridge->br_cfg) {
1342 set_external_id(bridge->br_cfg->key_external_ids,
1343 bridge->br_cfg->value_external_ids,
1344 bridge->br_cfg->n_external_ids,
1345 ctx->argv[2], ctx->argc >= 4 ? ctx->argv[3] : NULL,
1346 &keys, &values, &n);
1347 ovsrec_bridge_verify_external_ids(bridge->br_cfg);
1348 ovsrec_bridge_set_external_ids(bridge->br_cfg, keys, values, n);
1350 char *key = xasprintf("fake-bridge-%s", ctx->argv[2]);
1351 struct vsctl_port *port = shash_find_data(&info.ports, ctx->argv[1]);
1352 set_external_id(port->port_cfg->key_external_ids,
1353 port->port_cfg->value_external_ids,
1354 port->port_cfg->n_external_ids,
1355 key, ctx->argc >= 4 ? ctx->argv[3] : NULL,
1356 &keys, &values, &n);
1357 ovsrec_port_verify_external_ids(port->port_cfg);
1358 ovsrec_port_set_external_ids(port->port_cfg, keys, values, n);
1368 get_external_id(char **keys, char **values, size_t n,
1369 const char *prefix, const char *key,
1372 size_t prefix_len = strlen(prefix);
1377 for (i = 0; i < n; i++) {
1378 if (!key && !strncmp(keys[i], prefix, prefix_len)) {
1379 svec_add_nocopy(&svec, xasprintf("%s=%s",
1380 keys[i] + prefix_len, values[i]));
1381 } else if (key_matches(keys[i], prefix, prefix_len, key)) {
1382 svec_add(&svec, values[i]);
1386 output_sorted(&svec, output);
1387 svec_destroy(&svec);
1391 pre_cmd_br_get_external_id(struct vsctl_context *ctx)
1393 pre_cmd_br_set_external_id(ctx);
1397 cmd_br_get_external_id(struct vsctl_context *ctx)
1399 struct vsctl_info info;
1400 struct vsctl_bridge *bridge;
1402 get_info(ctx, &info);
1403 bridge = find_bridge(&info, ctx->argv[1], true);
1404 if (bridge->br_cfg) {
1405 ovsrec_bridge_verify_external_ids(bridge->br_cfg);
1406 get_external_id(bridge->br_cfg->key_external_ids,
1407 bridge->br_cfg->value_external_ids,
1408 bridge->br_cfg->n_external_ids,
1409 "", ctx->argc >= 3 ? ctx->argv[2] : NULL,
1412 struct vsctl_port *port = shash_find_data(&info.ports, ctx->argv[1]);
1413 ovsrec_port_verify_external_ids(port->port_cfg);
1414 get_external_id(port->port_cfg->key_external_ids,
1415 port->port_cfg->value_external_ids,
1416 port->port_cfg->n_external_ids,
1417 "fake-bridge-", ctx->argc >= 3 ? ctx->argv[2] : NULL, &ctx->output);
1424 cmd_list_ports(struct vsctl_context *ctx)
1426 struct vsctl_bridge *br;
1427 struct shash_node *node;
1428 struct vsctl_info info;
1431 get_info(ctx, &info);
1432 br = find_bridge(&info, ctx->argv[1], true);
1433 ovsrec_bridge_verify_ports(br->br_cfg ? br->br_cfg : br->parent->br_cfg);
1436 SHASH_FOR_EACH (node, &info.ports) {
1437 struct vsctl_port *port = node->data;
1439 if (strcmp(port->port_cfg->name, br->name) && br == port->bridge) {
1440 svec_add(&ports, port->port_cfg->name);
1443 output_sorted(&ports, &ctx->output);
1444 svec_destroy(&ports);
1450 add_port(struct vsctl_context *ctx,
1451 const char *br_name, const char *port_name,
1452 bool may_exist, bool fake_iface,
1453 char *iface_names[], int n_ifaces,
1454 char *settings[], int n_settings)
1456 struct vsctl_info info;
1457 struct vsctl_bridge *bridge;
1458 struct ovsrec_interface **ifaces;
1459 struct ovsrec_port *port;
1462 get_info(ctx, &info);
1464 struct vsctl_port *vsctl_port;
1466 vsctl_port = find_port(&info, port_name, false);
1468 struct svec want_names, have_names;
1470 svec_init(&want_names);
1471 for (i = 0; i < n_ifaces; i++) {
1472 svec_add(&want_names, iface_names[i]);
1474 svec_sort(&want_names);
1476 svec_init(&have_names);
1477 for (i = 0; i < vsctl_port->port_cfg->n_interfaces; i++) {
1478 svec_add(&have_names,
1479 vsctl_port->port_cfg->interfaces[i]->name);
1481 svec_sort(&have_names);
1483 if (strcmp(vsctl_port->bridge->name, br_name)) {
1484 char *command = vsctl_context_to_string(ctx);
1485 vsctl_fatal("\"%s\" but %s is actually attached to bridge %s",
1486 command, port_name, vsctl_port->bridge->name);
1489 if (!svec_equal(&want_names, &have_names)) {
1490 char *have_names_string = svec_join(&have_names, ", ", "");
1491 char *command = vsctl_context_to_string(ctx);
1493 vsctl_fatal("\"%s\" but %s actually has interface(s) %s",
1494 command, port_name, have_names_string);
1497 svec_destroy(&want_names);
1498 svec_destroy(&have_names);
1503 check_conflicts(&info, port_name,
1504 xasprintf("cannot create a port named %s", port_name));
1505 for (i = 0; i < n_ifaces; i++) {
1506 check_conflicts(&info, iface_names[i],
1507 xasprintf("cannot create an interface named %s",
1510 bridge = find_bridge(&info, br_name, true);
1512 ifaces = xmalloc(n_ifaces * sizeof *ifaces);
1513 for (i = 0; i < n_ifaces; i++) {
1514 ifaces[i] = ovsrec_interface_insert(ctx->txn);
1515 ovsrec_interface_set_name(ifaces[i], iface_names[i]);
1518 port = ovsrec_port_insert(ctx->txn);
1519 ovsrec_port_set_name(port, port_name);
1520 ovsrec_port_set_interfaces(port, ifaces, n_ifaces);
1521 ovsrec_port_set_bond_fake_iface(port, fake_iface);
1525 int64_t tag = bridge->vlan;
1526 ovsrec_port_set_tag(port, &tag, 1);
1529 for (i = 0; i < n_settings; i++) {
1530 set_column(get_table("Port"), &port->header_, settings[i],
1534 bridge_insert_port((bridge->parent ? bridge->parent->br_cfg
1535 : bridge->br_cfg), port);
1541 cmd_add_port(struct vsctl_context *ctx)
1543 bool may_exist = shash_find(&ctx->options, "--may-exist") != 0;
1545 add_port(ctx, ctx->argv[1], ctx->argv[2], may_exist, false,
1546 &ctx->argv[2], 1, &ctx->argv[3], ctx->argc - 3);
1550 cmd_add_bond(struct vsctl_context *ctx)
1552 bool may_exist = shash_find(&ctx->options, "--may-exist") != 0;
1553 bool fake_iface = shash_find(&ctx->options, "--fake-iface");
1557 n_ifaces = ctx->argc - 3;
1558 for (i = 3; i < ctx->argc; i++) {
1559 if (strchr(ctx->argv[i], '=')) {
1565 vsctl_fatal("add-bond requires at least 2 interfaces, but only "
1566 "%d were specified", n_ifaces);
1569 add_port(ctx, ctx->argv[1], ctx->argv[2], may_exist, fake_iface,
1570 &ctx->argv[3], n_ifaces,
1571 &ctx->argv[n_ifaces + 3], ctx->argc - 3 - n_ifaces);
1575 cmd_del_port(struct vsctl_context *ctx)
1577 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1578 bool with_iface = shash_find(&ctx->options, "--with-iface") != NULL;
1579 struct vsctl_port *port;
1580 struct vsctl_info info;
1582 get_info(ctx, &info);
1584 port = find_port(&info, ctx->argv[ctx->argc - 1], must_exist);
1586 const char *target = ctx->argv[ctx->argc - 1];
1587 struct vsctl_iface *iface;
1589 port = find_port(&info, target, false);
1591 iface = find_iface(&info, target, false);
1596 if (must_exist && !port) {
1597 vsctl_fatal("no port or interface named %s", target);
1602 if (ctx->argc == 3) {
1603 struct vsctl_bridge *bridge;
1605 bridge = find_bridge(&info, ctx->argv[1], true);
1606 if (port->bridge != bridge) {
1607 if (port->bridge->parent == bridge) {
1608 vsctl_fatal("bridge %s does not have a port %s (although "
1609 "its parent bridge %s does)",
1610 ctx->argv[1], ctx->argv[2],
1611 bridge->parent->name);
1613 vsctl_fatal("bridge %s does not have a port %s",
1614 ctx->argv[1], ctx->argv[2]);
1619 del_port(&info, port);
1626 cmd_port_to_br(struct vsctl_context *ctx)
1628 struct vsctl_port *port;
1629 struct vsctl_info info;
1631 get_info(ctx, &info);
1632 port = find_port(&info, ctx->argv[1], true);
1633 ds_put_format(&ctx->output, "%s\n", port->bridge->name);
1638 cmd_br_to_vlan(struct vsctl_context *ctx)
1640 struct vsctl_bridge *bridge;
1641 struct vsctl_info info;
1643 get_info(ctx, &info);
1644 bridge = find_bridge(&info, ctx->argv[1], true);
1645 ds_put_format(&ctx->output, "%d\n", bridge->vlan);
1650 cmd_br_to_parent(struct vsctl_context *ctx)
1652 struct vsctl_bridge *bridge;
1653 struct vsctl_info info;
1655 get_info(ctx, &info);
1656 bridge = find_bridge(&info, ctx->argv[1], true);
1657 if (bridge->parent) {
1658 bridge = bridge->parent;
1660 ds_put_format(&ctx->output, "%s\n", bridge->name);
1665 cmd_list_ifaces(struct vsctl_context *ctx)
1667 struct vsctl_bridge *br;
1668 struct shash_node *node;
1669 struct vsctl_info info;
1672 get_info(ctx, &info);
1673 br = find_bridge(&info, ctx->argv[1], true);
1677 SHASH_FOR_EACH (node, &info.ifaces) {
1678 struct vsctl_iface *iface = node->data;
1680 if (strcmp(iface->iface_cfg->name, br->name)
1681 && br == iface->port->bridge) {
1682 svec_add(&ifaces, iface->iface_cfg->name);
1685 output_sorted(&ifaces, &ctx->output);
1686 svec_destroy(&ifaces);
1692 cmd_iface_to_br(struct vsctl_context *ctx)
1694 struct vsctl_iface *iface;
1695 struct vsctl_info info;
1697 get_info(ctx, &info);
1698 iface = find_iface(&info, ctx->argv[1], true);
1699 ds_put_format(&ctx->output, "%s\n", iface->port->bridge->name);
1704 verify_controllers(struct ovsrec_bridge *bridge)
1709 ovsrec_bridge_verify_controller(bridge);
1710 for (i = 0; i < bridge->n_controller; i++) {
1711 ovsrec_controller_verify_target(bridge->controller[i]);
1717 pre_controller(struct vsctl_context *ctx)
1721 ovsdb_idl_add_column(ctx->idl, &ovsrec_controller_col_target);
1725 cmd_get_controller(struct vsctl_context *ctx)
1727 struct vsctl_info info;
1728 struct vsctl_bridge *br;
1729 struct svec targets;
1732 get_info(ctx, &info);
1733 br = find_bridge(&info, ctx->argv[1], true);
1734 verify_controllers(br->br_cfg);
1736 /* Print the targets in sorted order for reproducibility. */
1737 svec_init(&targets);
1738 for (i = 0; i < br->n_ctrl; i++) {
1739 svec_add(&targets, br->ctrl[i]->target);
1742 svec_sort(&targets);
1743 for (i = 0; i < targets.n; i++) {
1744 ds_put_format(&ctx->output, "%s\n", targets.names[i]);
1746 svec_destroy(&targets);
1752 delete_controllers(struct ovsrec_controller **controllers,
1753 size_t n_controllers)
1757 for (i = 0; i < n_controllers; i++) {
1758 ovsrec_controller_delete(controllers[i]);
1763 cmd_del_controller(struct vsctl_context *ctx)
1765 struct vsctl_info info;
1766 struct vsctl_bridge *br;
1768 get_info(ctx, &info);
1769 br = find_real_bridge(&info, ctx->argv[1], true);
1770 verify_controllers(br->br_cfg);
1773 delete_controllers(br->ctrl, br->n_ctrl);
1774 ovsrec_bridge_set_controller(br->br_cfg, NULL, 0);
1780 static struct ovsrec_controller **
1781 insert_controllers(struct ovsdb_idl_txn *txn, char *targets[], size_t n)
1783 struct ovsrec_controller **controllers;
1786 controllers = xmalloc(n * sizeof *controllers);
1787 for (i = 0; i < n; i++) {
1788 controllers[i] = ovsrec_controller_insert(txn);
1789 ovsrec_controller_set_target(controllers[i], targets[i]);
1796 cmd_set_controller(struct vsctl_context *ctx)
1798 struct vsctl_info info;
1799 struct vsctl_bridge *br;
1800 struct ovsrec_controller **controllers;
1803 get_info(ctx, &info);
1804 br = find_real_bridge(&info, ctx->argv[1], true);
1805 verify_controllers(br->br_cfg);
1807 delete_controllers(br->ctrl, br->n_ctrl);
1810 controllers = insert_controllers(ctx->txn, &ctx->argv[2], n);
1811 ovsrec_bridge_set_controller(br->br_cfg, controllers, n);
1818 cmd_get_fail_mode(struct vsctl_context *ctx)
1820 struct vsctl_info info;
1821 struct vsctl_bridge *br;
1823 get_info(ctx, &info);
1824 br = find_bridge(&info, ctx->argv[1], true);
1827 ovsrec_bridge_verify_fail_mode(br->br_cfg);
1829 if (br->fail_mode && strlen(br->fail_mode)) {
1830 ds_put_format(&ctx->output, "%s\n", br->fail_mode);
1837 cmd_del_fail_mode(struct vsctl_context *ctx)
1839 struct vsctl_info info;
1840 struct vsctl_bridge *br;
1842 get_info(ctx, &info);
1843 br = find_real_bridge(&info, ctx->argv[1], true);
1845 ovsrec_bridge_set_fail_mode(br->br_cfg, NULL);
1851 cmd_set_fail_mode(struct vsctl_context *ctx)
1853 struct vsctl_info info;
1854 struct vsctl_bridge *br;
1855 const char *fail_mode = ctx->argv[2];
1857 get_info(ctx, &info);
1858 br = find_real_bridge(&info, ctx->argv[1], true);
1860 if (strcmp(fail_mode, "standalone") && strcmp(fail_mode, "secure")) {
1861 vsctl_fatal("fail-mode must be \"standalone\" or \"secure\"");
1864 ovsrec_bridge_set_fail_mode(br->br_cfg, fail_mode);
1870 verify_managers(const struct ovsrec_open_vswitch *ovs)
1874 ovsrec_open_vswitch_verify_managers(ovs);
1875 ovsrec_open_vswitch_verify_manager_options(ovs);
1877 for (i = 0; i < ovs->n_manager_options; ++i) {
1878 const struct ovsrec_manager *mgr = ovs->manager_options[i];
1880 ovsrec_manager_verify_target(mgr);
1885 pre_manager(struct vsctl_context *ctx)
1887 ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_managers);
1888 ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_manager_options);
1889 ovsdb_idl_add_column(ctx->idl, &ovsrec_manager_col_target);
1893 cmd_get_manager(struct vsctl_context *ctx)
1895 const struct ovsrec_open_vswitch *ovs = ctx->ovs;
1896 struct svec targets;
1899 verify_managers(ovs);
1901 /* Print the targets in sorted order for reproducibility. */
1902 svec_init(&targets);
1904 /* First, add all targets found in deprecated 'managers' column. */
1905 for (i = 0; i < ovs->n_managers; i++) {
1906 svec_add(&targets, ovs->managers[i]);
1909 /* Second, add all targets pointed to by 'manager_options' column. */
1910 for (i = 0; i < ovs->n_manager_options; i++) {
1911 svec_add(&targets, ovs->manager_options[i]->target);
1914 svec_sort_unique(&targets);
1915 for (i = 0; i < targets.n; i++) {
1916 ds_put_format(&ctx->output, "%s\n", targets.names[i]);
1918 svec_destroy(&targets);
1922 delete_managers(const struct vsctl_context *ctx)
1924 const struct ovsrec_open_vswitch *ovs = ctx->ovs;
1927 /* Delete manager targets in deprecated 'managers' column. */
1928 ovsrec_open_vswitch_set_managers(ovs, NULL, 0);
1930 /* Delete Manager rows pointed to by 'manager_options' column. */
1931 for (i = 0; i < ovs->n_manager_options; i++) {
1932 ovsrec_manager_delete(ovs->manager_options[i]);
1935 /* Delete 'Manager' row refs in 'manager_options' column. */
1936 ovsrec_open_vswitch_set_manager_options(ovs, NULL, 0);
1940 cmd_del_manager(struct vsctl_context *ctx)
1942 const struct ovsrec_open_vswitch *ovs = ctx->ovs;
1944 verify_managers(ovs);
1945 delete_managers(ctx);
1949 insert_managers(struct vsctl_context *ctx, char *targets[], size_t n)
1951 struct ovsrec_manager **managers;
1954 /* Store in deprecated 'manager' column. */
1955 ovsrec_open_vswitch_set_managers(ctx->ovs, targets, n);
1957 /* Insert each manager in a new row in Manager table. */
1958 managers = xmalloc(n * sizeof *managers);
1959 for (i = 0; i < n; i++) {
1960 managers[i] = ovsrec_manager_insert(ctx->txn);
1961 ovsrec_manager_set_target(managers[i], targets[i]);
1964 /* Store uuids of new Manager rows in 'manager_options' column. */
1965 ovsrec_open_vswitch_set_manager_options(ctx->ovs, managers, n);
1970 cmd_set_manager(struct vsctl_context *ctx)
1972 const size_t n = ctx->argc - 1;
1974 verify_managers(ctx->ovs);
1975 delete_managers(ctx);
1976 insert_managers(ctx, &ctx->argv[1], n);
1980 pre_cmd_get_ssl(struct vsctl_context *ctx)
1982 ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_ssl);
1984 ovsdb_idl_add_column(ctx->idl, &ovsrec_ssl_col_private_key);
1985 ovsdb_idl_add_column(ctx->idl, &ovsrec_ssl_col_certificate);
1986 ovsdb_idl_add_column(ctx->idl, &ovsrec_ssl_col_ca_cert);
1987 ovsdb_idl_add_column(ctx->idl, &ovsrec_ssl_col_bootstrap_ca_cert);
1991 cmd_get_ssl(struct vsctl_context *ctx)
1993 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1995 ovsrec_open_vswitch_verify_ssl(ctx->ovs);
1997 ovsrec_ssl_verify_private_key(ssl);
1998 ovsrec_ssl_verify_certificate(ssl);
1999 ovsrec_ssl_verify_ca_cert(ssl);
2000 ovsrec_ssl_verify_bootstrap_ca_cert(ssl);
2002 ds_put_format(&ctx->output, "Private key: %s\n", ssl->private_key);
2003 ds_put_format(&ctx->output, "Certificate: %s\n", ssl->certificate);
2004 ds_put_format(&ctx->output, "CA Certificate: %s\n", ssl->ca_cert);
2005 ds_put_format(&ctx->output, "Bootstrap: %s\n",
2006 ssl->bootstrap_ca_cert ? "true" : "false");
2011 pre_cmd_del_ssl(struct vsctl_context *ctx)
2013 ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_ssl);
2017 cmd_del_ssl(struct vsctl_context *ctx)
2019 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
2022 ovsrec_open_vswitch_verify_ssl(ctx->ovs);
2023 ovsrec_ssl_delete(ssl);
2024 ovsrec_open_vswitch_set_ssl(ctx->ovs, NULL);
2029 pre_cmd_set_ssl(struct vsctl_context *ctx)
2031 ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_ssl);
2035 cmd_set_ssl(struct vsctl_context *ctx)
2037 bool bootstrap = shash_find(&ctx->options, "--bootstrap");
2038 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
2040 ovsrec_open_vswitch_verify_ssl(ctx->ovs);
2042 ovsrec_ssl_delete(ssl);
2044 ssl = ovsrec_ssl_insert(ctx->txn);
2046 ovsrec_ssl_set_private_key(ssl, ctx->argv[1]);
2047 ovsrec_ssl_set_certificate(ssl, ctx->argv[2]);
2048 ovsrec_ssl_set_ca_cert(ssl, ctx->argv[3]);
2050 ovsrec_ssl_set_bootstrap_ca_cert(ssl, bootstrap);
2052 ovsrec_open_vswitch_set_ssl(ctx->ovs, ssl);
2055 /* Parameter commands. */
2057 struct vsctl_row_id {
2058 const struct ovsdb_idl_table_class *table;
2059 const struct ovsdb_idl_column *name_column;
2060 const struct ovsdb_idl_column *uuid_column;
2063 struct vsctl_table_class {
2064 struct ovsdb_idl_table_class *class;
2065 struct vsctl_row_id row_ids[2];
2068 static const struct vsctl_table_class tables[] = {
2069 {&ovsrec_table_bridge,
2070 {{&ovsrec_table_bridge, &ovsrec_bridge_col_name, NULL},
2071 {NULL, NULL, NULL}}},
2073 {&ovsrec_table_controller,
2074 {{&ovsrec_table_bridge,
2075 &ovsrec_bridge_col_name,
2076 &ovsrec_bridge_col_controller}}},
2078 {&ovsrec_table_interface,
2079 {{&ovsrec_table_interface, &ovsrec_interface_col_name, NULL},
2080 {NULL, NULL, NULL}}},
2082 {&ovsrec_table_mirror,
2083 {{&ovsrec_table_mirror, &ovsrec_mirror_col_name, NULL},
2084 {NULL, NULL, NULL}}},
2086 {&ovsrec_table_manager,
2087 {{&ovsrec_table_manager, &ovsrec_manager_col_target, NULL},
2088 {NULL, NULL, NULL}}},
2090 {&ovsrec_table_netflow,
2091 {{&ovsrec_table_bridge,
2092 &ovsrec_bridge_col_name,
2093 &ovsrec_bridge_col_netflow},
2094 {NULL, NULL, NULL}}},
2096 {&ovsrec_table_open_vswitch,
2097 {{&ovsrec_table_open_vswitch, NULL, NULL},
2098 {NULL, NULL, NULL}}},
2100 {&ovsrec_table_port,
2101 {{&ovsrec_table_port, &ovsrec_port_col_name, NULL},
2102 {NULL, NULL, NULL}}},
2105 {{&ovsrec_table_port, &ovsrec_port_col_name, &ovsrec_port_col_qos},
2106 {NULL, NULL, NULL}}},
2108 {&ovsrec_table_monitor,
2109 {{&ovsrec_table_interface,
2110 &ovsrec_interface_col_name,
2111 &ovsrec_interface_col_monitor},
2112 {NULL, NULL, NULL}}},
2114 {&ovsrec_table_maintenance_point,
2115 {{NULL, NULL, NULL},
2116 {NULL, NULL, NULL}}},
2118 {&ovsrec_table_queue,
2119 {{NULL, NULL, NULL},
2120 {NULL, NULL, NULL}}},
2123 {{&ovsrec_table_open_vswitch, NULL, &ovsrec_open_vswitch_col_ssl}}},
2125 {&ovsrec_table_sflow,
2126 {{&ovsrec_table_bridge,
2127 &ovsrec_bridge_col_name,
2128 &ovsrec_bridge_col_sflow},
2129 {NULL, NULL, NULL}}},
2131 {NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}
2135 die_if_error(char *error)
2138 vsctl_fatal("%s", error);
2143 to_lower_and_underscores(unsigned c)
2145 return c == '-' ? '_' : tolower(c);
2149 score_partial_match(const char *name, const char *s)
2153 if (!strcmp(name, s)) {
2156 for (score = 0; ; score++, name++, s++) {
2157 if (to_lower_and_underscores(*name) != to_lower_and_underscores(*s)) {
2159 } else if (*name == '\0') {
2160 return UINT_MAX - 1;
2163 return *s == '\0' ? score : 0;
2166 static const struct vsctl_table_class *
2167 get_table(const char *table_name)
2169 const struct vsctl_table_class *table;
2170 const struct vsctl_table_class *best_match = NULL;
2171 unsigned int best_score = 0;
2173 for (table = tables; table->class; table++) {
2174 unsigned int score = score_partial_match(table->class->name,
2176 if (score > best_score) {
2179 } else if (score == best_score) {
2185 } else if (best_score) {
2186 vsctl_fatal("multiple table names match \"%s\"", table_name);
2188 vsctl_fatal("unknown table \"%s\"", table_name);
2192 static const struct vsctl_table_class *
2193 pre_get_table(struct vsctl_context *ctx, const char *table_name)
2195 const struct vsctl_table_class *table_class;
2198 table_class = get_table(table_name);
2199 ovsdb_idl_add_table(ctx->idl, table_class->class);
2201 for (i = 0; i < ARRAY_SIZE(table_class->row_ids); i++) {
2202 const struct vsctl_row_id *id = &table_class->row_ids[i];
2204 ovsdb_idl_add_table(ctx->idl, id->table);
2206 if (id->name_column) {
2207 ovsdb_idl_add_column(ctx->idl, id->name_column);
2209 if (id->uuid_column) {
2210 ovsdb_idl_add_column(ctx->idl, id->uuid_column);
2217 static const struct ovsdb_idl_row *
2218 get_row_by_id(struct vsctl_context *ctx, const struct vsctl_table_class *table,
2219 const struct vsctl_row_id *id, const char *record_id)
2221 const struct ovsdb_idl_row *referrer, *final;
2227 if (!id->name_column) {
2228 if (strcmp(record_id, ".")) {
2231 referrer = ovsdb_idl_first_row(ctx->idl, id->table);
2232 if (!referrer || ovsdb_idl_next_row(referrer)) {
2236 const struct ovsdb_idl_row *row;
2239 for (row = ovsdb_idl_first_row(ctx->idl, id->table);
2241 row = ovsdb_idl_next_row(row))
2243 const struct ovsdb_datum *name;
2245 name = ovsdb_idl_get(row, id->name_column,
2246 OVSDB_TYPE_STRING, OVSDB_TYPE_VOID);
2247 if (name->n == 1 && !strcmp(name->keys[0].string, record_id)) {
2249 vsctl_fatal("multiple rows in %s match \"%s\"",
2250 table->class->name, record_id);
2261 if (id->uuid_column) {
2262 const struct ovsdb_datum *uuid;
2264 ovsdb_idl_txn_verify(referrer, id->uuid_column);
2265 uuid = ovsdb_idl_get(referrer, id->uuid_column,
2266 OVSDB_TYPE_UUID, OVSDB_TYPE_VOID);
2268 final = ovsdb_idl_get_row_for_uuid(ctx->idl, table->class,
2269 &uuid->keys[0].uuid);
2278 static const struct ovsdb_idl_row *
2279 get_row (struct vsctl_context *ctx,
2280 const struct vsctl_table_class *table, const char *record_id)
2282 const struct ovsdb_idl_row *row;
2285 if (uuid_from_string(&uuid, record_id)) {
2286 row = ovsdb_idl_get_row_for_uuid(ctx->idl, table->class, &uuid);
2290 for (i = 0; i < ARRAY_SIZE(table->row_ids); i++) {
2291 row = get_row_by_id(ctx, table, &table->row_ids[i], record_id);
2300 static const struct ovsdb_idl_row *
2301 must_get_row(struct vsctl_context *ctx,
2302 const struct vsctl_table_class *table, const char *record_id)
2304 const struct ovsdb_idl_row *row = get_row(ctx, table, record_id);
2306 vsctl_fatal("no row \"%s\" in table %s",
2307 record_id, table->class->name);
2313 get_column(const struct vsctl_table_class *table, const char *column_name,
2314 const struct ovsdb_idl_column **columnp)
2316 const struct ovsdb_idl_column *best_match = NULL;
2317 unsigned int best_score = 0;
2320 for (i = 0; i < table->class->n_columns; i++) {
2321 const struct ovsdb_idl_column *column = &table->class->columns[i];
2322 unsigned int score = score_partial_match(column->name, column_name);
2323 if (score > best_score) {
2324 best_match = column;
2326 } else if (score == best_score) {
2331 *columnp = best_match;
2334 } else if (best_score) {
2335 return xasprintf("%s contains more than one column whose name "
2336 "matches \"%s\"", table->class->name, column_name);
2338 return xasprintf("%s does not contain a column whose name matches "
2339 "\"%s\"", table->class->name, column_name);
2343 static struct uuid *
2344 create_symbol(struct ovsdb_symbol_table *symtab, const char *id, bool *newp)
2346 struct ovsdb_symbol *symbol;
2349 vsctl_fatal("row id \"%s\" does not begin with \"@\"", id);
2353 *newp = ovsdb_symbol_table_get(symtab, id) == NULL;
2356 symbol = ovsdb_symbol_table_insert(symtab, id);
2358 vsctl_fatal("row id \"%s\" may only be specified on one --id option",
2361 symbol->used = true;
2362 return &symbol->uuid;
2366 pre_get_column(struct vsctl_context *ctx,
2367 const struct vsctl_table_class *table, const char *column_name,
2368 const struct ovsdb_idl_column **columnp)
2370 die_if_error(get_column(table, column_name, columnp));
2371 ovsdb_idl_add_column(ctx->idl, *columnp);
2375 missing_operator_error(const char *arg, const char **allowed_operators,
2381 ds_put_format(&s, "%s: argument does not end in ", arg);
2382 ds_put_format(&s, "\"%s\"", allowed_operators[0]);
2383 if (n_allowed == 2) {
2384 ds_put_format(&s, " or \"%s\"", allowed_operators[1]);
2385 } else if (n_allowed > 2) {
2388 for (i = 1; i < n_allowed - 1; i++) {
2389 ds_put_format(&s, ", \"%s\"", allowed_operators[i]);
2391 ds_put_format(&s, ", or \"%s\"", allowed_operators[i]);
2393 ds_put_format(&s, " followed by a value.");
2395 return ds_steal_cstr(&s);
2398 /* Breaks 'arg' apart into a number of fields in the following order:
2400 * - If 'columnp' is nonnull, the name of a column in 'table'. The column
2401 * is stored into '*columnp'. The column name may be abbreviated.
2403 * - If 'keyp' is nonnull, optionally a key string. (If both 'columnp'
2404 * and 'keyp' are nonnull, then the column and key names are expected to
2405 * be separated by ':'). The key is stored as a malloc()'d string into
2406 * '*keyp', or NULL if no key is present in 'arg'.
2408 * - If 'valuep' is nonnull, an operator followed by a value string. The
2409 * allowed operators are the 'n_allowed' string in 'allowed_operators',
2410 * or just "=" if 'n_allowed' is 0. If 'operatorp' is nonnull, then the
2411 * operator is stored into '*operatorp' (one of the pointers from
2412 * 'allowed_operators' is stored; nothing is malloc()'d). The value is
2413 * stored as a malloc()'d string into '*valuep', or NULL if no value is
2416 * At least 'columnp' or 'keyp' must be nonnull.
2418 * On success, returns NULL. On failure, returned a malloc()'d string error
2419 * message and stores NULL into all of the nonnull output arguments. */
2420 static char * WARN_UNUSED_RESULT
2421 parse_column_key_value(const char *arg,
2422 const struct vsctl_table_class *table,
2423 const struct ovsdb_idl_column **columnp, char **keyp,
2424 const char **operatorp,
2425 const char **allowed_operators, size_t n_allowed,
2428 const char *p = arg;
2431 assert(columnp || keyp);
2432 assert(!(operatorp && !valuep));
2440 /* Parse column name. */
2444 error = ovsdb_token_parse(&p, &column_name);
2448 if (column_name[0] == '\0') {
2450 error = xasprintf("%s: missing column name", arg);
2453 error = get_column(table, column_name, columnp);
2460 /* Parse key string. */
2461 if (*p == ':' || !columnp) {
2465 error = xasprintf("%s: key not accepted here", arg);
2468 error = ovsdb_token_parse(&p, keyp);
2476 /* Parse value string. */
2482 if (!allowed_operators) {
2483 static const char *equals = "=";
2484 allowed_operators = =
2490 for (i = 0; i < n_allowed; i++) {
2491 const char *op = allowed_operators[i];
2492 size_t op_len = strlen(op);
2494 if (op_len > best_len && !strncmp(op, p, op_len) && p[op_len]) {
2500 error = missing_operator_error(arg, allowed_operators, n_allowed);
2507 *valuep = xstrdup(p + best_len);
2513 error = xasprintf("%s: trailing garbage \"%s\" in argument",
2539 pre_parse_column_key_value(struct vsctl_context *ctx,
2541 const struct vsctl_table_class *table)
2543 const struct ovsdb_idl_column *column;
2548 die_if_error(ovsdb_token_parse(&p, &column_name));
2549 if (column_name[0] == '\0') {
2550 vsctl_fatal("%s: missing column name", arg);
2553 pre_get_column(ctx, table, column_name, &column);
2558 pre_cmd_get(struct vsctl_context *ctx)
2560 const char *table_name = ctx->argv[1];
2561 const struct vsctl_table_class *table;
2564 table = pre_get_table(ctx, table_name);
2565 for (i = 3; i < ctx->argc; i++) {
2566 if (!strcasecmp(ctx->argv[i], "_uuid")
2567 || !strcasecmp(ctx->argv[i], "-uuid")) {
2571 pre_parse_column_key_value(ctx, ctx->argv[i], table);
2576 cmd_get(struct vsctl_context *ctx)
2578 const char *id = shash_find_data(&ctx->options, "--id");
2579 bool if_exists = shash_find(&ctx->options, "--if-exists");
2580 const char *table_name = ctx->argv[1];
2581 const char *record_id = ctx->argv[2];
2582 const struct vsctl_table_class *table;
2583 const struct ovsdb_idl_row *row;
2584 struct ds *out = &ctx->output;
2587 table = get_table(table_name);
2588 row = must_get_row(ctx, table, record_id);
2592 *create_symbol(ctx->symtab, id, &new) = row->uuid;
2594 vsctl_fatal("row id \"%s\" specified on \"get\" command was used "
2595 "before it was defined", id);
2598 for (i = 3; i < ctx->argc; i++) {
2599 const struct ovsdb_idl_column *column;
2600 const struct ovsdb_datum *datum;
2603 /* Special case for obtaining the UUID of a row. We can't just do this
2604 * through parse_column_key_value() below since it returns a "struct
2605 * ovsdb_idl_column" and the UUID column doesn't have one. */
2606 if (!strcasecmp(ctx->argv[i], "_uuid")
2607 || !strcasecmp(ctx->argv[i], "-uuid")) {
2608 ds_put_format(out, UUID_FMT"\n", UUID_ARGS(&row->uuid));
2612 die_if_error(parse_column_key_value(ctx->argv[i], table,
2613 &column, &key_string,
2614 NULL, NULL, 0, NULL));
2616 ovsdb_idl_txn_verify(row, column);
2617 datum = ovsdb_idl_read(row, column);
2619 union ovsdb_atom key;
2622 if (column->type.value.type == OVSDB_TYPE_VOID) {
2623 vsctl_fatal("cannot specify key to get for non-map column %s",
2627 die_if_error(ovsdb_atom_from_string(&key,
2629 key_string, ctx->symtab));
2631 idx = ovsdb_datum_find_key(datum, &key,
2632 column->type.key.type);
2633 if (idx == UINT_MAX) {
2635 vsctl_fatal("no key \"%s\" in %s record \"%s\" column %s",
2636 key_string, table->class->name, record_id,
2640 ovsdb_atom_to_string(&datum->values[idx],
2641 column->type.value.type, out);
2643 ovsdb_atom_destroy(&key, column->type.key.type);
2645 ovsdb_datum_to_string(datum, &column->type, out);
2647 ds_put_char(out, '\n');
2654 pre_cmd_list(struct vsctl_context *ctx)
2656 const char *table_name = ctx->argv[1];
2657 const struct vsctl_table_class *table;
2660 table = pre_get_table(ctx, table_name);
2661 for (i = 0; i < table->class->n_columns; i++) {
2662 ovsdb_idl_add_column(ctx->idl, &table->class->columns[i]);
2667 list_record(const struct vsctl_table_class *table,
2668 const struct ovsdb_idl_row *row, struct ds *out)
2672 ds_put_format(out, "%-20s: "UUID_FMT"\n", "_uuid",
2673 UUID_ARGS(&row->uuid));
2674 for (i = 0; i < table->class->n_columns; i++) {
2675 const struct ovsdb_idl_column *column = &table->class->columns[i];
2676 const struct ovsdb_datum *datum;
2678 datum = ovsdb_idl_read(row, column);
2680 ds_put_format(out, "%-20s: ", column->name);
2681 ovsdb_datum_to_string(datum, &column->type, out);
2682 ds_put_char(out, '\n');
2687 cmd_list(struct vsctl_context *ctx)
2689 const char *table_name = ctx->argv[1];
2690 const struct vsctl_table_class *table;
2691 struct ds *out = &ctx->output;
2694 table = get_table(table_name);
2695 if (ctx->argc > 2) {
2696 for (i = 2; i < ctx->argc; i++) {
2698 ds_put_char(out, '\n');
2700 list_record(table, must_get_row(ctx, table, ctx->argv[i]), out);
2703 const struct ovsdb_idl_row *row;
2706 for (row = ovsdb_idl_first_row(ctx->idl, table->class), first = true;
2708 row = ovsdb_idl_next_row(row), first = false) {
2710 ds_put_char(out, '\n');
2712 list_record(table, row, out);
2718 pre_cmd_set(struct vsctl_context *ctx)
2720 const char *table_name = ctx->argv[1];
2721 const struct vsctl_table_class *table;
2724 table = pre_get_table(ctx, table_name);
2725 for (i = 3; i < ctx->argc; i++) {
2726 pre_parse_column_key_value(ctx, ctx->argv[i], table);
2731 set_column(const struct vsctl_table_class *table,
2732 const struct ovsdb_idl_row *row, const char *arg,
2733 struct ovsdb_symbol_table *symtab)
2735 const struct ovsdb_idl_column *column;
2736 char *key_string, *value_string;
2739 error = parse_column_key_value(arg, table, &column, &key_string,
2740 NULL, NULL, 0, &value_string);
2741 die_if_error(error);
2742 if (!value_string) {
2743 vsctl_fatal("%s: missing value", arg);
2747 union ovsdb_atom key, value;
2748 struct ovsdb_datum datum;
2750 if (column->type.value.type == OVSDB_TYPE_VOID) {
2751 vsctl_fatal("cannot specify key to set for non-map column %s",
2755 die_if_error(ovsdb_atom_from_string(&key, &column->type.key,
2756 key_string, symtab));
2757 die_if_error(ovsdb_atom_from_string(&value, &column->type.value,
2758 value_string, symtab));
2760 ovsdb_datum_init_empty(&datum);
2761 ovsdb_datum_add_unsafe(&datum, &key, &value, &column->type);
2763 ovsdb_atom_destroy(&key, column->type.key.type);
2764 ovsdb_atom_destroy(&value, column->type.value.type);
2766 ovsdb_datum_union(&datum, ovsdb_idl_read(row, column),
2767 &column->type, false);
2768 ovsdb_idl_txn_write(row, column, &datum);
2770 struct ovsdb_datum datum;
2772 die_if_error(ovsdb_datum_from_string(&datum, &column->type,
2773 value_string, symtab));
2774 ovsdb_idl_txn_write(row, column, &datum);
2782 cmd_set(struct vsctl_context *ctx)
2784 const char *table_name = ctx->argv[1];
2785 const char *record_id = ctx->argv[2];
2786 const struct vsctl_table_class *table;
2787 const struct ovsdb_idl_row *row;
2790 table = get_table(table_name);
2791 row = must_get_row(ctx, table, record_id);
2792 for (i = 3; i < ctx->argc; i++) {
2793 set_column(table, row, ctx->argv[i], ctx->symtab);
2798 pre_cmd_add(struct vsctl_context *ctx)
2800 const char *table_name = ctx->argv[1];
2801 const char *column_name = ctx->argv[3];
2802 const struct vsctl_table_class *table;
2803 const struct ovsdb_idl_column *column;
2805 table = pre_get_table(ctx, table_name);
2806 pre_get_column(ctx, table, column_name, &column);
2810 cmd_add(struct vsctl_context *ctx)
2812 const char *table_name = ctx->argv[1];
2813 const char *record_id = ctx->argv[2];
2814 const char *column_name = ctx->argv[3];
2815 const struct vsctl_table_class *table;
2816 const struct ovsdb_idl_column *column;
2817 const struct ovsdb_idl_row *row;
2818 const struct ovsdb_type *type;
2819 struct ovsdb_datum old;
2822 table = get_table(table_name);
2823 row = must_get_row(ctx, table, record_id);
2824 die_if_error(get_column(table, column_name, &column));
2826 type = &column->type;
2827 ovsdb_datum_clone(&old, ovsdb_idl_read(row, column), &column->type);
2828 for (i = 4; i < ctx->argc; i++) {
2829 struct ovsdb_type add_type;
2830 struct ovsdb_datum add;
2834 add_type.n_max = UINT_MAX;
2835 die_if_error(ovsdb_datum_from_string(&add, &add_type, ctx->argv[i],
2837 ovsdb_datum_union(&old, &add, type, false);
2838 ovsdb_datum_destroy(&add, type);
2840 if (old.n > type->n_max) {
2841 vsctl_fatal("\"add\" operation would put %u %s in column %s of "
2842 "table %s but the maximum number is %u",
2844 type->value.type == OVSDB_TYPE_VOID ? "values" : "pairs",
2845 column->name, table->class->name, type->n_max);
2847 ovsdb_idl_txn_verify(row, column);
2848 ovsdb_idl_txn_write(row, column, &old);
2852 pre_cmd_remove(struct vsctl_context *ctx)
2854 const char *table_name = ctx->argv[1];
2855 const char *column_name = ctx->argv[3];
2856 const struct vsctl_table_class *table;
2857 const struct ovsdb_idl_column *column;
2859 table = pre_get_table(ctx, table_name);
2860 pre_get_column(ctx, table, column_name, &column);
2864 cmd_remove(struct vsctl_context *ctx)
2866 const char *table_name = ctx->argv[1];
2867 const char *record_id = ctx->argv[2];
2868 const char *column_name = ctx->argv[3];
2869 const struct vsctl_table_class *table;
2870 const struct ovsdb_idl_column *column;
2871 const struct ovsdb_idl_row *row;
2872 const struct ovsdb_type *type;
2873 struct ovsdb_datum old;
2876 table = get_table(table_name);
2877 row = must_get_row(ctx, table, record_id);
2878 die_if_error(get_column(table, column_name, &column));
2880 type = &column->type;
2881 ovsdb_datum_clone(&old, ovsdb_idl_read(row, column), &column->type);
2882 for (i = 4; i < ctx->argc; i++) {
2883 struct ovsdb_type rm_type;
2884 struct ovsdb_datum rm;
2889 rm_type.n_max = UINT_MAX;
2890 error = ovsdb_datum_from_string(&rm, &rm_type,
2891 ctx->argv[i], ctx->symtab);
2892 if (error && ovsdb_type_is_map(&rm_type)) {
2894 rm_type.value.type = OVSDB_TYPE_VOID;
2895 die_if_error(ovsdb_datum_from_string(&rm, &rm_type,
2896 ctx->argv[i], ctx->symtab));
2898 ovsdb_datum_subtract(&old, type, &rm, &rm_type);
2899 ovsdb_datum_destroy(&rm, &rm_type);
2901 if (old.n < type->n_min) {
2902 vsctl_fatal("\"remove\" operation would put %u %s in column %s of "
2903 "table %s but the minimum number is %u",
2905 type->value.type == OVSDB_TYPE_VOID ? "values" : "pairs",
2906 column->name, table->class->name, type->n_min);
2908 ovsdb_idl_txn_verify(row, column);
2909 ovsdb_idl_txn_write(row, column, &old);
2913 pre_cmd_clear(struct vsctl_context *ctx)
2915 const char *table_name = ctx->argv[1];
2916 const struct vsctl_table_class *table;
2919 table = pre_get_table(ctx, table_name);
2920 for (i = 3; i < ctx->argc; i++) {
2921 const struct ovsdb_idl_column *column;
2923 pre_get_column(ctx, table, ctx->argv[i], &column);
2928 cmd_clear(struct vsctl_context *ctx)
2930 const char *table_name = ctx->argv[1];
2931 const char *record_id = ctx->argv[2];
2932 const struct vsctl_table_class *table;
2933 const struct ovsdb_idl_row *row;
2936 table = get_table(table_name);
2937 row = must_get_row(ctx, table, record_id);
2938 for (i = 3; i < ctx->argc; i++) {
2939 const struct ovsdb_idl_column *column;
2940 const struct ovsdb_type *type;
2941 struct ovsdb_datum datum;
2943 die_if_error(get_column(table, ctx->argv[i], &column));
2945 type = &column->type;
2946 if (type->n_min > 0) {
2947 vsctl_fatal("\"clear\" operation cannot be applied to column %s "
2948 "of table %s, which is not allowed to be empty",
2949 column->name, table->class->name);
2952 ovsdb_datum_init_empty(&datum);
2953 ovsdb_idl_txn_write(row, column, &datum);
2958 cmd_create(struct vsctl_context *ctx)
2960 const char *id = shash_find_data(&ctx->options, "--id");
2961 const char *table_name = ctx->argv[1];
2962 const struct vsctl_table_class *table;
2963 const struct ovsdb_idl_row *row;
2964 const struct uuid *uuid;
2967 uuid = id ? create_symbol(ctx->symtab, id, NULL) : NULL;
2969 table = get_table(table_name);
2970 row = ovsdb_idl_txn_insert(ctx->txn, table->class, uuid);
2971 for (i = 2; i < ctx->argc; i++) {
2972 set_column(table, row, ctx->argv[i], ctx->symtab);
2974 ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(&row->uuid));
2977 /* This function may be used as the 'postprocess' function for commands that
2978 * insert new rows into the database. It expects that the command's 'run'
2979 * function prints the UUID reported by ovsdb_idl_txn_insert() as the command's
2980 * sole output. It replaces that output by the row's permanent UUID assigned
2981 * by the database server and appends a new-line.
2983 * Currently we use this only for "create", because the higher-level commands
2984 * are supposed to be independent of the actual structure of the vswitch
2987 post_create(struct vsctl_context *ctx)
2989 const struct uuid *real;
2992 uuid_from_string(&dummy, ds_cstr(&ctx->output));
2993 real = ovsdb_idl_txn_get_insert_uuid(ctx->txn, &dummy);
2995 ds_clear(&ctx->output);
2996 ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(real));
2998 ds_put_char(&ctx->output, '\n');
3002 pre_cmd_destroy(struct vsctl_context *ctx)
3004 const char *table_name = ctx->argv[1];
3006 pre_get_table(ctx, table_name);
3010 cmd_destroy(struct vsctl_context *ctx)
3012 bool must_exist = !shash_find(&ctx->options, "--if-exists");
3013 const char *table_name = ctx->argv[1];
3014 const struct vsctl_table_class *table;
3017 table = get_table(table_name);
3018 for (i = 2; i < ctx->argc; i++) {
3019 const struct ovsdb_idl_row *row;
3021 row = (must_exist ? must_get_row : get_row)(ctx, table, ctx->argv[i]);
3023 ovsdb_idl_txn_delete(row);
3029 is_condition_satified(const struct vsctl_table_class *table,
3030 const struct ovsdb_idl_row *row, const char *arg,
3031 struct ovsdb_symbol_table *symtab)
3033 static const char *operators[] = {
3034 "=", "!=", "<", ">", "<=", ">="
3037 const struct ovsdb_idl_column *column;
3038 const struct ovsdb_datum *have_datum;
3039 char *key_string, *value_string;
3040 const char *operator;
3045 error = parse_column_key_value(arg, table, &column, &key_string,
3046 &operator, operators, ARRAY_SIZE(operators),
3048 die_if_error(error);
3049 if (!value_string) {
3050 vsctl_fatal("%s: missing value", arg);
3053 have_datum = ovsdb_idl_read(row, column);
3055 union ovsdb_atom want_key, want_value;
3057 if (column->type.value.type == OVSDB_TYPE_VOID) {
3058 vsctl_fatal("cannot specify key to check for non-map column %s",
3062 die_if_error(ovsdb_atom_from_string(&want_key, &column->type.key,
3063 key_string, symtab));
3064 die_if_error(ovsdb_atom_from_string(&want_value, &column->type.value,
3065 value_string, symtab));
3067 idx = ovsdb_datum_find_key(have_datum,
3068 &want_key, column->type.key.type);
3069 if (idx != UINT_MAX) {
3070 cmp = ovsdb_atom_compare_3way(&have_datum->values[idx],
3072 column->type.value.type);
3075 ovsdb_atom_destroy(&want_key, column->type.key.type);
3076 ovsdb_atom_destroy(&want_value, column->type.value.type);
3078 struct ovsdb_datum want_datum;
3080 die_if_error(ovsdb_datum_from_string(&want_datum, &column->type,
3081 value_string, symtab));
3083 cmp = ovsdb_datum_compare_3way(have_datum, &want_datum,
3085 ovsdb_datum_destroy(&want_datum, &column->type);
3091 return (idx == UINT_MAX ? false
3092 : !strcmp(operator, "=") ? cmp == 0
3093 : !strcmp(operator, "!=") ? cmp != 0
3094 : !strcmp(operator, "<") ? cmp < 0
3095 : !strcmp(operator, ">") ? cmp > 0
3096 : !strcmp(operator, "<=") ? cmp <= 0
3097 : !strcmp(operator, ">=") ? cmp >= 0
3102 pre_cmd_wait_until(struct vsctl_context *ctx)
3104 const char *table_name = ctx->argv[1];
3105 const struct vsctl_table_class *table;
3108 table = pre_get_table(ctx, table_name);
3110 for (i = 3; i < ctx->argc; i++) {
3111 pre_parse_column_key_value(ctx, ctx->argv[i], table);
3116 cmd_wait_until(struct vsctl_context *ctx)
3118 const char *table_name = ctx->argv[1];
3119 const char *record_id = ctx->argv[2];
3120 const struct vsctl_table_class *table;
3121 const struct ovsdb_idl_row *row;
3124 table = get_table(table_name);
3126 row = get_row(ctx, table, record_id);
3128 ctx->try_again = true;
3132 for (i = 3; i < ctx->argc; i++) {
3133 if (!is_condition_satified(table, row, ctx->argv[i], ctx->symtab)) {
3134 ctx->try_again = true;
3140 static struct json *
3141 where_uuid_equals(const struct uuid *uuid)
3144 json_array_create_1(
3145 json_array_create_3(
3146 json_string_create("_uuid"),
3147 json_string_create("=="),
3148 json_array_create_2(
3149 json_string_create("uuid"),
3150 json_string_create_nocopy(
3151 xasprintf(UUID_FMT, UUID_ARGS(uuid))))));
3155 vsctl_context_init(struct vsctl_context *ctx, struct vsctl_command *command,
3156 struct ovsdb_idl *idl, struct ovsdb_idl_txn *txn,
3157 const struct ovsrec_open_vswitch *ovs,
3158 struct ovsdb_symbol_table *symtab)
3160 ctx->argc = command->argc;
3161 ctx->argv = command->argv;
3162 ctx->options = command->options;
3164 ds_swap(&ctx->output, &command->output);
3168 ctx->symtab = symtab;
3169 ctx->verified_ports = false;
3171 ctx->try_again = false;
3175 vsctl_context_done(struct vsctl_context *ctx, struct vsctl_command *command)
3177 ds_swap(&ctx->output, &command->output);
3181 run_prerequisites(struct vsctl_command *commands, size_t n_commands,
3182 struct ovsdb_idl *idl)
3184 struct vsctl_command *c;
3186 ovsdb_idl_add_table(idl, &ovsrec_table_open_vswitch);
3187 if (wait_for_reload) {
3188 ovsdb_idl_add_column(idl, &ovsrec_open_vswitch_col_cur_cfg);
3190 for (c = commands; c < &commands[n_commands]; c++) {
3191 if (c->syntax->prerequisites) {
3192 struct vsctl_context ctx;
3194 ds_init(&c->output);
3196 vsctl_context_init(&ctx, c, idl, NULL, NULL, NULL);
3197 (c->syntax->prerequisites)(&ctx);
3198 vsctl_context_done(&ctx, c);
3200 assert(!c->output.string);
3206 do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
3207 struct ovsdb_idl *idl)
3209 struct ovsdb_idl_txn *txn;
3210 const struct ovsrec_open_vswitch *ovs;
3211 enum ovsdb_idl_txn_status status;
3212 struct ovsdb_symbol_table *symtab;
3214 struct vsctl_command *c;
3215 int64_t next_cfg = 0;
3218 txn = the_idl_txn = ovsdb_idl_txn_create(idl);
3220 ovsdb_idl_txn_set_dry_run(txn);
3223 ovsdb_idl_txn_add_comment(txn, "ovs-vsctl: %s", args);
3225 ovs = ovsrec_open_vswitch_first(idl);
3227 /* XXX add verification that table is empty */
3228 ovs = ovsrec_open_vswitch_insert(txn);
3231 if (wait_for_reload) {
3232 struct json *where = where_uuid_equals(&ovs->header_.uuid);
3233 ovsdb_idl_txn_increment(txn, "Open_vSwitch", "next_cfg", where);
3234 json_destroy(where);
3237 symtab = ovsdb_symbol_table_create();
3238 for (c = commands; c < &commands[n_commands]; c++) {
3239 ds_init(&c->output);
3241 for (c = commands; c < &commands[n_commands]; c++) {
3242 struct vsctl_context ctx;
3244 vsctl_context_init(&ctx, c, idl, txn, ovs, symtab);
3245 (c->syntax->run)(&ctx);
3246 vsctl_context_done(&ctx, c);
3248 if (ctx.try_again) {
3253 status = ovsdb_idl_txn_commit_block(txn);
3254 if (wait_for_reload && status == TXN_SUCCESS) {
3255 next_cfg = ovsdb_idl_txn_get_increment_new_value(txn);
3257 if (status == TXN_UNCHANGED || status == TXN_SUCCESS) {
3258 for (c = commands; c < &commands[n_commands]; c++) {
3259 if (c->syntax->postprocess) {
3260 struct vsctl_context ctx;
3262 vsctl_context_init(&ctx, c, idl, txn, ovs, symtab);
3263 (c->syntax->postprocess)(&ctx);
3264 vsctl_context_done(&ctx, c);
3268 error = xstrdup(ovsdb_idl_txn_get_error(txn));
3269 ovsdb_idl_txn_destroy(txn);
3270 txn = the_idl_txn = NULL;
3272 unused = ovsdb_symbol_table_find_unused(symtab);
3274 vsctl_fatal("row id \"%s\" is referenced but never created (e.g. "
3275 "with \"-- --id=%s create ...\")", unused, unused);
3279 case TXN_INCOMPLETE:
3283 /* Should not happen--we never call ovsdb_idl_txn_abort(). */
3284 vsctl_fatal("transaction aborted");
3294 vsctl_fatal("transaction error: %s", error);
3301 ovsdb_symbol_table_destroy(symtab);
3303 for (c = commands; c < &commands[n_commands]; c++) {
3304 struct ds *ds = &c->output;
3310 for (j = 0; j < ds->length; j++) {
3311 int ch = ds->string[j];
3314 fputs("\\n", stdout);
3318 fputs("\\\\", stdout);
3327 fputs(ds_cstr(ds), stdout);
3329 ds_destroy(&c->output);
3331 smap_destroy(&c->options);
3335 if (wait_for_reload && status != TXN_UNCHANGED) {
3338 OVSREC_OPEN_VSWITCH_FOR_EACH (ovs, idl) {
3339 if (ovs->cur_cfg >= next_cfg) {
3343 ovsdb_idl_wait(idl);
3348 ovsdb_idl_destroy(idl);
3353 /* Our transaction needs to be rerun, or a prerequisite was not met. Free
3354 * resources and return so that the caller can try again. */
3356 ovsdb_idl_txn_abort(txn);
3357 ovsdb_idl_txn_destroy(txn);
3359 ovsdb_symbol_table_destroy(symtab);
3360 for (c = commands; c < &commands[n_commands]; c++) {
3361 ds_destroy(&c->output);
3366 static const struct vsctl_command_syntax all_commands[] = {
3367 /* Open vSwitch commands. */
3368 {"init", 0, 0, NULL, cmd_init, NULL, "", RW},
3370 /* Bridge commands. */
3371 {"add-br", 1, 3, pre_get_info, cmd_add_br, NULL, "--may-exist", RW},
3372 {"del-br", 1, 1, pre_get_info, cmd_del_br, NULL, "--if-exists", RW},
3373 {"list-br", 0, 0, pre_get_info, cmd_list_br, NULL, "", RO},
3374 {"br-exists", 1, 1, pre_get_info, cmd_br_exists, NULL, "", RO},
3375 {"br-to-vlan", 1, 1, pre_get_info, cmd_br_to_vlan, NULL, "", RO},
3376 {"br-to-parent", 1, 1, pre_get_info, cmd_br_to_parent, NULL, "", RO},
3377 {"br-set-external-id", 2, 3, pre_cmd_br_set_external_id,
3378 cmd_br_set_external_id, NULL, "", RW},
3379 {"br-get-external-id", 1, 2, pre_cmd_br_get_external_id,
3380 cmd_br_get_external_id, NULL, "", RO},
3382 /* Port commands. */
3383 {"list-ports", 1, 1, pre_get_info, cmd_list_ports, NULL, "", RO},
3384 {"add-port", 2, INT_MAX, pre_get_info, cmd_add_port, NULL, "--may-exist",
3386 {"add-bond", 4, INT_MAX, pre_get_info, cmd_add_bond, NULL,
3387 "--may-exist,--fake-iface", RW},
3388 {"del-port", 1, 2, pre_get_info, cmd_del_port, NULL,
3389 "--if-exists,--with-iface", RW},
3390 {"port-to-br", 1, 1, pre_get_info, cmd_port_to_br, NULL, "", RO},
3392 /* Interface commands. */
3393 {"list-ifaces", 1, 1, pre_get_info, cmd_list_ifaces, NULL, "", RO},
3394 {"iface-to-br", 1, 1, pre_get_info, cmd_iface_to_br, NULL, "", RO},
3396 /* Controller commands. */
3397 {"get-controller", 1, 1, pre_controller, cmd_get_controller, NULL, "", RO},
3398 {"del-controller", 1, 1, pre_controller, cmd_del_controller, NULL, "", RW},
3399 {"set-controller", 1, INT_MAX, pre_controller, cmd_set_controller, NULL,
3401 {"get-fail-mode", 1, 1, pre_get_info, cmd_get_fail_mode, NULL, "", RO},
3402 {"del-fail-mode", 1, 1, pre_get_info, cmd_del_fail_mode, NULL, "", RW},
3403 {"set-fail-mode", 2, 2, pre_get_info, cmd_set_fail_mode, NULL, "", RW},
3405 /* Manager commands. */
3406 {"get-manager", 0, 0, pre_manager, cmd_get_manager, NULL, "", RO},
3407 {"del-manager", 0, INT_MAX, pre_manager, cmd_del_manager, NULL, "", RW},
3408 {"set-manager", 1, INT_MAX, pre_manager, cmd_set_manager, NULL, "", RW},
3411 {"get-ssl", 0, 0, pre_cmd_get_ssl, cmd_get_ssl, NULL, "", RO},
3412 {"del-ssl", 0, 0, pre_cmd_del_ssl, cmd_del_ssl, NULL, "", RW},
3413 {"set-ssl", 3, 3, pre_cmd_set_ssl, cmd_set_ssl, NULL, "--bootstrap", RW},
3415 /* Switch commands. */
3416 {"emer-reset", 0, 0, pre_cmd_emer_reset, cmd_emer_reset, NULL, "", RW},
3418 /* Parameter commands. */
3419 {"get", 2, INT_MAX, pre_cmd_get, cmd_get, NULL, "--if-exists,--id=", RO},
3420 {"list", 1, INT_MAX, pre_cmd_list, cmd_list, NULL, "", RO},
3421 {"set", 3, INT_MAX, pre_cmd_set, cmd_set, NULL, "", RW},
3422 {"add", 4, INT_MAX, pre_cmd_add, cmd_add, NULL, "", RW},
3423 {"remove", 4, INT_MAX, pre_cmd_remove, cmd_remove, NULL, "", RW},
3424 {"clear", 3, INT_MAX, pre_cmd_clear, cmd_clear, NULL, "", RW},
3425 {"create", 2, INT_MAX, NULL, cmd_create, post_create, "--id=", RW},
3426 {"destroy", 1, INT_MAX, pre_cmd_destroy, cmd_destroy, NULL, "--if-exists",
3428 {"wait-until", 2, INT_MAX, pre_cmd_wait_until, cmd_wait_until, NULL, "",
3431 {NULL, 0, 0, NULL, NULL, NULL, NULL, RO},