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 #define THIS_MODULE VLM_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 typedef void vsctl_handler_func(struct vsctl_context *);
55 struct vsctl_command_syntax {
59 vsctl_handler_func *run;
60 vsctl_handler_func *postprocess;
64 struct vsctl_command {
65 /* Data that remains constant after initialization. */
66 const struct vsctl_command_syntax *syntax;
71 /* Data modified by commands. */
75 /* --db: The database server to contact. */
76 static const char *db;
78 /* --oneline: Write each command's output as a single line? */
81 /* --dry-run: Do not commit any changes. */
84 /* --no-wait: Wait for ovs-vswitchd to reload its configuration? */
85 static bool wait_for_reload = true;
87 /* --timeout: Time to wait for a connection to 'db'. */
88 static int timeout = 5;
90 /* All supported commands. */
91 static const struct vsctl_command_syntax all_commands[];
93 /* The IDL we're using and the current transaction, if any.
94 * This is for use by vsctl_exit() only, to allow it to clean up.
95 * Other code should use its context arguments. */
96 static struct ovsdb_idl *the_idl;
97 static struct ovsdb_idl_txn *the_idl_txn;
99 static void vsctl_exit(int status) NO_RETURN;
100 static void vsctl_fatal(const char *, ...) PRINTF_FORMAT(1, 2) NO_RETURN;
101 static char *default_db(void);
102 static void usage(void) NO_RETURN;
103 static void parse_options(int argc, char *argv[]);
105 static struct vsctl_command *parse_commands(int argc, char *argv[],
106 size_t *n_commandsp);
107 static void parse_command(int argc, char *argv[], struct vsctl_command *);
108 static void do_vsctl(const char *args,
109 struct vsctl_command *, size_t n_commands,
112 static const struct vsctl_table_class *get_table(const char *table_name);
113 static void set_column(const struct vsctl_table_class *,
114 const struct ovsdb_idl_row *, const char *arg);
118 main(int argc, char *argv[])
120 struct ovsdb_idl *idl;
122 struct vsctl_command *commands;
127 set_program_name(argv[0]);
128 signal(SIGPIPE, SIG_IGN);
131 vlog_set_levels(VLM_ANY_MODULE, VLF_CONSOLE, VLL_WARN);
132 vlog_set_levels(VLM_reconnect, VLF_ANY_FACILITY, VLL_WARN);
135 /* Log our arguments. This is often valuable for debugging systems. */
136 args = process_escape_args(argv);
137 VLOG_INFO("Called as %s", args);
139 /* Parse command line. */
140 parse_options(argc, argv);
141 commands = parse_commands(argc - optind, argv + optind, &n_commands);
147 /* Now execute the commands. */
148 idl = the_idl = ovsdb_idl_create(db, &ovsrec_idl_class);
149 seqno = ovsdb_idl_get_seqno(idl);
152 unsigned int new_seqno;
155 new_seqno = ovsdb_idl_get_seqno(idl);
156 if (new_seqno != seqno) {
158 vsctl_fatal("too many database inconsistency failures");
160 do_vsctl(args, commands, n_commands, idl);
170 parse_options(int argc, char *argv[])
173 OPT_DB = UCHAR_MAX + 1,
181 static struct option long_options[] = {
182 {"db", required_argument, 0, OPT_DB},
183 {"no-syslog", no_argument, 0, OPT_NO_SYSLOG},
184 {"no-wait", no_argument, 0, OPT_NO_WAIT},
185 {"dry-run", no_argument, 0, OPT_DRY_RUN},
186 {"oneline", no_argument, 0, OPT_ONELINE},
187 {"timeout", required_argument, 0, 't'},
188 {"help", no_argument, 0, 'h'},
189 {"version", no_argument, 0, 'V'},
192 STREAM_SSL_LONG_OPTIONS
193 {"peer-ca-cert", required_argument, 0, OPT_PEER_CA_CERT},
202 c = getopt_long(argc, argv, "+v::hVt:", long_options, NULL);
217 vlog_set_levels(VLM_vsctl, VLF_SYSLOG, VLL_WARN);
221 wait_for_reload = false;
232 OVS_PRINT_VERSION(0, 0);
236 timeout = strtoul(optarg, NULL, 10);
238 vsctl_fatal("value %s on -t or --timeout is invalid",
246 STREAM_SSL_OPTION_HANDLERS
248 case OPT_PEER_CA_CERT:
249 stream_ssl_set_peer_ca_cert_file(optarg);
266 static struct vsctl_command *
267 parse_commands(int argc, char *argv[], size_t *n_commandsp)
269 struct vsctl_command *commands;
270 size_t n_commands, allocated_commands;
274 n_commands = allocated_commands = 0;
276 for (start = i = 0; i <= argc; i++) {
277 if (i == argc || !strcmp(argv[i], "--")) {
279 if (n_commands >= allocated_commands) {
280 struct vsctl_command *c;
282 commands = x2nrealloc(commands, &allocated_commands,
284 for (c = commands; c < &commands[n_commands]; c++) {
285 shash_moved(&c->options);
288 parse_command(i - start, &argv[start],
289 &commands[n_commands++]);
295 vsctl_fatal("missing command name (use --help for help)");
297 *n_commandsp = n_commands;
302 parse_command(int argc, char *argv[], struct vsctl_command *command)
304 const struct vsctl_command_syntax *p;
307 shash_init(&command->options);
308 for (i = 0; i < argc; i++) {
309 if (argv[i][0] != '-') {
312 if (!shash_add_once(&command->options, argv[i], NULL)) {
313 vsctl_fatal("'%s' option specified multiple times", argv[i]);
317 vsctl_fatal("missing command name");
320 for (p = all_commands; p->name; p++) {
321 if (!strcmp(p->name, argv[i])) {
322 struct shash_node *node;
325 SHASH_FOR_EACH (node, &command->options) {
326 const char *s = strstr(p->options, node->name);
327 int end = s ? s[strlen(node->name)] : EOF;
328 if (end != ',' && end != ' ' && end != '\0') {
329 vsctl_fatal("'%s' command has no '%s' option",
330 argv[i], node->name);
334 n_arg = argc - i - 1;
335 if (n_arg < p->min_args) {
336 vsctl_fatal("'%s' command requires at least %d arguments",
337 p->name, p->min_args);
338 } else if (n_arg > p->max_args) {
341 for (j = i + 1; j < argc; j++) {
342 if (argv[j][0] == '-') {
343 vsctl_fatal("'%s' command takes at most %d arguments "
344 "(note that options must precede command "
345 "names and follow a \"--\" argument)",
346 p->name, p->max_args);
350 vsctl_fatal("'%s' command takes at most %d arguments",
351 p->name, p->max_args);
354 command->argc = n_arg + 1;
355 command->argv = &argv[i];
361 vsctl_fatal("unknown command '%s'; use --help for help", argv[i]);
365 vsctl_fatal(const char *format, ...)
370 va_start(args, format);
371 message = xvasprintf(format, args);
374 vlog_set_levels(VLM_vsctl, VLF_CONSOLE, VLL_EMER);
375 VLOG_ERR("%s", message);
376 ovs_error(0, "%s", message);
377 vsctl_exit(EXIT_FAILURE);
380 /* Frees the current transaction and the underlying IDL and then calls
383 * Freeing the transaction and the IDL is not strictly necessary, but it makes
384 * for a clean memory leak report from valgrind in the normal case. That makes
385 * it easier to notice real memory leaks. */
387 vsctl_exit(int status)
390 ovsdb_idl_txn_abort(the_idl_txn);
391 ovsdb_idl_txn_destroy(the_idl_txn);
393 ovsdb_idl_destroy(the_idl);
401 %s: ovs-vswitchd management utility\n\
402 usage: %s [OPTIONS] COMMAND [ARG...]\n\
405 add-br BRIDGE create a new bridge named BRIDGE\n\
406 add-br BRIDGE PARENT VLAN create new fake BRIDGE in PARENT on VLAN\n\
407 del-br BRIDGE delete BRIDGE and all of its ports\n\
408 list-br print the names of all the bridges\n\
409 br-exists BRIDGE test whether BRIDGE exists\n\
410 br-to-vlan BRIDGE print the VLAN which BRIDGE is on\n\
411 br-to-parent BRIDGE print the parent of BRIDGE\n\
412 br-set-external-id BRIDGE KEY VALUE set KEY on BRIDGE to VALUE\n\
413 br-set-external-id BRIDGE KEY unset KEY on BRIDGE\n\
414 br-get-external-id BRIDGE KEY print value of KEY on BRIDGE\n\
415 br-get-external-id BRIDGE list key-value pairs on BRIDGE\n\
418 list-ports BRIDGE print the names of all the ports on BRIDGE\n\
419 add-port BRIDGE PORT add network device PORT to BRIDGE\n\
420 add-bond BRIDGE PORT IFACE... add bonded port PORT in BRIDGE from IFACES\n\
421 del-port [BRIDGE] PORT delete PORT (which may be bonded) from BRIDGE\n\
422 port-to-br PORT print name of bridge that contains PORT\n\
423 A bond is considered to be a single port.\n\
425 Interface commands (a bond consists of multiple interfaces):\n\
426 list-ifaces BRIDGE print the names of all interfaces on BRIDGE\n\
427 iface-to-br IFACE print name of bridge that contains IFACE\n\
429 Controller commands:\n\
430 get-controller [BRIDGE] print the controller for BRIDGE\n\
431 del-controller [BRIDGE] delete the controller for BRIDGE\n\
432 set-controller [BRIDGE] TARGET set the controller for BRIDGE to TARGET\n\
433 get-fail-mode [BRIDGE] print the fail-mode for BRIDGE\n\
434 del-fail-mode [BRIDGE] delete the fail-mode for BRIDGE\n\
435 set-fail-mode [BRIDGE] MODE set the fail-mode for BRIDGE to MODE\n\
438 get-ssl print the SSL configuration\n\
439 del-ssl delete the SSL configuration\n\
440 set-ssl PRIV-KEY CERT CA-CERT set the SSL configuration\n\
443 emer-reset reset switch to known good state\n\
445 Database commands:\n\
446 list TBL [REC] list RECord (or all records) in TBL\n\
447 get TBL REC COL[:KEY] print values of COLumns in RECORD in TBL\n\
448 set TBL REC COL[:KEY]=VALUE set COLumn values in RECord in TBL\n\
449 add TBL REC COL [KEY=]VALUE add (KEY=)VALUE to COLumn in RECord in TBL\n\
450 remove TBL REC COL [KEY=]VALUE remove (KEY=)VALUE from COLumn\n\
451 clear TBL REC COL clear values from COLumn in RECord in TBL\n\
452 create TBL COL[:KEY]=VALUE create and initialize new record\n\
453 destroy TBL REC delete REC from TBL\n\
454 Potentially unsafe database commands require --force option.\n\
457 --db=DATABASE connect to DATABASE\n\
459 --oneline print exactly one line of output per command\n",
460 program_name, program_name, default_db());
464 -h, --help display this help message\n\
465 -V, --version display version information\n");
474 def = xasprintf("unix:%s/db.sock", ovs_rundir);
479 struct vsctl_context {
483 struct shash options;
485 /* Modifiable state. */
487 struct ovsdb_idl *idl;
488 struct ovsdb_idl_txn *txn;
489 const struct ovsrec_open_vswitch *ovs;
492 struct vsctl_bridge {
493 struct ovsrec_bridge *br_cfg;
495 struct ovsrec_controller **ctrl;
497 struct vsctl_bridge *parent;
502 struct ovsrec_port *port_cfg;
503 struct vsctl_bridge *bridge;
507 struct ovsrec_interface *iface_cfg;
508 struct vsctl_port *port;
512 struct shash bridges;
515 struct ovsrec_controller **ctrl;
520 vsctl_context_to_string(const struct vsctl_context *ctx)
522 const struct shash_node *node;
528 SHASH_FOR_EACH (node, &ctx->options) {
529 svec_add(&words, node->name);
531 for (i = 0; i < ctx->argc; i++) {
532 svec_add(&words, ctx->argv[i]);
534 svec_terminate(&words);
536 s = process_escape_args(words.names);
538 svec_destroy(&words);
543 static struct vsctl_bridge *
544 add_bridge(struct vsctl_info *b,
545 struct ovsrec_bridge *br_cfg, const char *name,
546 struct vsctl_bridge *parent, int vlan)
548 struct vsctl_bridge *br = xmalloc(sizeof *br);
550 br->name = xstrdup(name);
554 br->ctrl = parent->br_cfg->controller;
555 br->n_ctrl = parent->br_cfg->n_controller;
557 br->ctrl = br_cfg->controller;
558 br->n_ctrl = br_cfg->n_controller;
560 shash_add(&b->bridges, br->name, br);
565 port_is_fake_bridge(const struct ovsrec_port *port_cfg)
567 return (port_cfg->fake_bridge
569 && *port_cfg->tag >= 1 && *port_cfg->tag <= 4095);
572 static struct vsctl_bridge *
573 find_vlan_bridge(struct vsctl_info *info,
574 struct vsctl_bridge *parent, int vlan)
576 struct shash_node *node;
578 SHASH_FOR_EACH (node, &info->bridges) {
579 struct vsctl_bridge *br = node->data;
580 if (br->parent == parent && br->vlan == vlan) {
589 free_info(struct vsctl_info *info)
591 struct shash_node *node;
593 SHASH_FOR_EACH (node, &info->bridges) {
594 struct vsctl_bridge *bridge = node->data;
598 shash_destroy(&info->bridges);
600 SHASH_FOR_EACH (node, &info->ports) {
601 struct vsctl_port *port = node->data;
604 shash_destroy(&info->ports);
606 SHASH_FOR_EACH (node, &info->ifaces) {
607 struct vsctl_iface *iface = node->data;
610 shash_destroy(&info->ifaces);
614 get_info(const struct ovsrec_open_vswitch *ovs, struct vsctl_info *info)
616 struct shash bridges, ports;
619 shash_init(&info->bridges);
620 shash_init(&info->ports);
621 shash_init(&info->ifaces);
623 info->ctrl = ovs->controller;
624 info->n_ctrl = ovs->n_controller;
626 shash_init(&bridges);
628 for (i = 0; i < ovs->n_bridges; i++) {
629 struct ovsrec_bridge *br_cfg = ovs->bridges[i];
630 struct vsctl_bridge *br;
633 if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
634 VLOG_WARN("%s: database contains duplicate bridge name",
638 br = add_bridge(info, br_cfg, br_cfg->name, NULL, 0);
643 for (j = 0; j < br_cfg->n_ports; j++) {
644 struct ovsrec_port *port_cfg = br_cfg->ports[j];
646 if (!shash_add_once(&ports, port_cfg->name, NULL)) {
647 VLOG_WARN("%s: database contains duplicate port name",
652 if (port_is_fake_bridge(port_cfg)
653 && shash_add_once(&bridges, port_cfg->name, NULL)) {
654 add_bridge(info, NULL, port_cfg->name, br, *port_cfg->tag);
658 shash_destroy(&bridges);
659 shash_destroy(&ports);
661 shash_init(&bridges);
663 for (i = 0; i < ovs->n_bridges; i++) {
664 struct ovsrec_bridge *br_cfg = ovs->bridges[i];
665 struct vsctl_bridge *br;
668 if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
671 br = shash_find_data(&info->bridges, br_cfg->name);
672 for (j = 0; j < br_cfg->n_ports; j++) {
673 struct ovsrec_port *port_cfg = br_cfg->ports[j];
674 struct vsctl_port *port;
677 if (!shash_add_once(&ports, port_cfg->name, NULL)) {
681 if (port_is_fake_bridge(port_cfg)
682 && !shash_add_once(&bridges, port_cfg->name, NULL)) {
686 port = xmalloc(sizeof *port);
687 port->port_cfg = port_cfg;
689 && *port_cfg->tag >= 1 && *port_cfg->tag <= 4095) {
690 port->bridge = find_vlan_bridge(info, br, *port_cfg->tag);
697 shash_add(&info->ports, port_cfg->name, port);
699 for (k = 0; k < port_cfg->n_interfaces; k++) {
700 struct ovsrec_interface *iface_cfg = port_cfg->interfaces[k];
701 struct vsctl_iface *iface;
703 if (shash_find(&info->ifaces, iface_cfg->name)) {
704 VLOG_WARN("%s: database contains duplicate interface name",
709 iface = xmalloc(sizeof *iface);
710 iface->iface_cfg = iface_cfg;
712 shash_add(&info->ifaces, iface_cfg->name, iface);
716 shash_destroy(&bridges);
717 shash_destroy(&ports);
721 check_conflicts(struct vsctl_info *info, const char *name,
724 struct vsctl_iface *iface;
725 struct vsctl_port *port;
727 if (shash_find(&info->bridges, name)) {
728 vsctl_fatal("%s because a bridge named %s already exists",
732 port = shash_find_data(&info->ports, name);
734 vsctl_fatal("%s because a port named %s already exists on "
735 "bridge %s", msg, name, port->bridge->name);
738 iface = shash_find_data(&info->ifaces, name);
740 vsctl_fatal("%s because an interface named %s already exists "
741 "on bridge %s", msg, name, iface->port->bridge->name);
747 static struct vsctl_bridge *
748 find_bridge(struct vsctl_info *info, const char *name, bool must_exist)
750 struct vsctl_bridge *br = shash_find_data(&info->bridges, name);
751 if (must_exist && !br) {
752 vsctl_fatal("no bridge named %s", name);
757 static struct vsctl_bridge *
758 find_real_bridge(struct vsctl_info *info, const char *name, bool must_exist)
760 struct vsctl_bridge *br = find_bridge(info, name, must_exist);
761 if (br && br->parent) {
762 vsctl_fatal("%s is a fake bridge", name);
767 static struct vsctl_port *
768 find_port(struct vsctl_info *info, const char *name, bool must_exist)
770 struct vsctl_port *port = shash_find_data(&info->ports, name);
771 if (port && !strcmp(name, port->bridge->name)) {
774 if (must_exist && !port) {
775 vsctl_fatal("no port named %s", name);
780 static struct vsctl_iface *
781 find_iface(struct vsctl_info *info, const char *name, bool must_exist)
783 struct vsctl_iface *iface = shash_find_data(&info->ifaces, name);
784 if (iface && !strcmp(name, iface->port->bridge->name)) {
787 if (must_exist && !iface) {
788 vsctl_fatal("no interface named %s", name);
794 bridge_insert_port(struct ovsrec_bridge *br, struct ovsrec_port *port)
796 struct ovsrec_port **ports;
799 ports = xmalloc(sizeof *br->ports * (br->n_ports + 1));
800 for (i = 0; i < br->n_ports; i++) {
801 ports[i] = br->ports[i];
803 ports[br->n_ports] = port;
804 ovsrec_bridge_set_ports(br, ports, br->n_ports + 1);
809 bridge_delete_port(struct ovsrec_bridge *br, struct ovsrec_port *port)
811 struct ovsrec_port **ports;
814 ports = xmalloc(sizeof *br->ports * br->n_ports);
815 for (i = n = 0; i < br->n_ports; i++) {
816 if (br->ports[i] != port) {
817 ports[n++] = br->ports[i];
820 ovsrec_bridge_set_ports(br, ports, n);
825 ovs_insert_bridge(const struct ovsrec_open_vswitch *ovs,
826 struct ovsrec_bridge *bridge)
828 struct ovsrec_bridge **bridges;
831 bridges = xmalloc(sizeof *ovs->bridges * (ovs->n_bridges + 1));
832 for (i = 0; i < ovs->n_bridges; i++) {
833 bridges[i] = ovs->bridges[i];
835 bridges[ovs->n_bridges] = bridge;
836 ovsrec_open_vswitch_set_bridges(ovs, bridges, ovs->n_bridges + 1);
841 ovs_delete_bridge(const struct ovsrec_open_vswitch *ovs,
842 struct ovsrec_bridge *bridge)
844 struct ovsrec_bridge **bridges;
847 bridges = xmalloc(sizeof *ovs->bridges * ovs->n_bridges);
848 for (i = n = 0; i < ovs->n_bridges; i++) {
849 if (ovs->bridges[i] != bridge) {
850 bridges[n++] = ovs->bridges[i];
853 ovsrec_open_vswitch_set_bridges(ovs, bridges, n);
858 cmd_init(struct vsctl_context *ctx OVS_UNUSED)
863 cmd_emer_reset(struct vsctl_context *ctx)
865 const struct ovsdb_idl *idl = ctx->idl;
866 const struct ovsrec_bridge *br;
867 const struct ovsrec_port *port;
868 const struct ovsrec_interface *iface;
869 const struct ovsrec_mirror *mirror, *next_mirror;
870 const struct ovsrec_controller *ctrl, *next_ctrl;
871 const struct ovsrec_netflow *nf, *next_nf;
872 const struct ovsrec_ssl *ssl, *next_ssl;
873 const struct ovsrec_sflow *sflow, *next_sflow;
876 /* Reset the Open_vSwitch table. */
877 ovsrec_open_vswitch_set_managers(ctx->ovs, NULL, 0);
878 ovsrec_open_vswitch_set_controller(ctx->ovs, NULL, 0);
879 ovsrec_open_vswitch_set_ssl(ctx->ovs, NULL);
881 OVSREC_BRIDGE_FOR_EACH (br, idl) {
883 char *hw_key = "hwaddr";
886 ovsrec_bridge_set_controller(br, NULL, 0);
887 ovsrec_bridge_set_mirrors(br, NULL, 0);
888 ovsrec_bridge_set_netflow(br, NULL);
889 ovsrec_bridge_set_sflow(br, NULL);
890 ovsrec_bridge_set_flood_vlans(br, NULL, 0);
892 /* We only want to save the "hwaddr" key from other_config. */
893 for (i=0; i < br->n_other_config; i++) {
894 if (!strcmp(br->key_other_config[i], hw_key)) {
895 hw_val = br->value_other_config[i];
900 char *val = xstrdup(hw_val);
901 ovsrec_bridge_set_other_config(br, &hw_key, &val, 1);
904 ovsrec_bridge_set_other_config(br, NULL, NULL, 0);
908 OVSREC_PORT_FOR_EACH (port, idl) {
909 ovsrec_port_set_other_config(port, NULL, NULL, 0);
912 OVSREC_INTERFACE_FOR_EACH (iface, idl) {
913 /* xxx What do we do about gre/patch devices created by mgr? */
915 ovsrec_interface_set_ingress_policing_rate(iface, 0);
916 ovsrec_interface_set_ingress_policing_burst(iface, 0);
919 OVSREC_MIRROR_FOR_EACH_SAFE (mirror, next_mirror, idl) {
920 ovsrec_mirror_delete(mirror);
923 OVSREC_CONTROLLER_FOR_EACH_SAFE (ctrl, next_ctrl, idl) {
924 ovsrec_controller_delete(ctrl);
927 OVSREC_NETFLOW_FOR_EACH_SAFE (nf, next_nf, idl) {
928 ovsrec_netflow_delete(nf);
931 OVSREC_SSL_FOR_EACH_SAFE (ssl, next_ssl, idl) {
932 ovsrec_ssl_delete(ssl);
935 OVSREC_SFLOW_FOR_EACH_SAFE (sflow, next_sflow, idl) {
936 ovsrec_sflow_delete(sflow);
941 cmd_add_br(struct vsctl_context *ctx)
943 bool may_exist = shash_find(&ctx->options, "--may-exist") != 0;
944 const char *br_name, *parent_name;
945 struct vsctl_info info;
948 br_name = ctx->argv[1];
949 if (ctx->argc == 2) {
952 } else if (ctx->argc == 4) {
953 parent_name = ctx->argv[2];
954 vlan = atoi(ctx->argv[3]);
955 if (vlan < 1 || vlan > 4095) {
956 vsctl_fatal("%s: vlan must be between 1 and 4095", ctx->argv[0]);
959 vsctl_fatal("'%s' command takes exactly 1 or 3 arguments",
963 get_info(ctx->ovs, &info);
965 struct vsctl_bridge *br;
967 br = find_bridge(&info, br_name, false);
971 vsctl_fatal("\"--may-exist add-br %s\" but %s is "
972 "a VLAN bridge for VLAN %d",
973 br_name, br_name, br->vlan);
977 vsctl_fatal("\"--may-exist add-br %s %s %d\" but %s "
978 "is not a VLAN bridge",
979 br_name, parent_name, vlan, br_name);
980 } else if (strcmp(br->parent->name, parent_name)) {
981 vsctl_fatal("\"--may-exist add-br %s %s %d\" but %s "
982 "has the wrong parent %s",
983 br_name, parent_name, vlan,
984 br_name, br->parent->name);
985 } else if (br->vlan != vlan) {
986 vsctl_fatal("\"--may-exist add-br %s %s %d\" but %s "
987 "is a VLAN bridge for the wrong VLAN %d",
988 br_name, parent_name, vlan, br_name, br->vlan);
994 check_conflicts(&info, br_name,
995 xasprintf("cannot create a bridge named %s", br_name));
998 struct ovsrec_port *port;
999 struct ovsrec_interface *iface;
1000 struct ovsrec_bridge *br;
1002 iface = ovsrec_interface_insert(ctx->txn);
1003 ovsrec_interface_set_name(iface, br_name);
1005 port = ovsrec_port_insert(ctx->txn);
1006 ovsrec_port_set_name(port, br_name);
1007 ovsrec_port_set_interfaces(port, &iface, 1);
1009 br = ovsrec_bridge_insert(ctx->txn);
1010 ovsrec_bridge_set_name(br, br_name);
1011 ovsrec_bridge_set_ports(br, &port, 1);
1013 ovs_insert_bridge(ctx->ovs, br);
1015 struct vsctl_bridge *parent;
1016 struct ovsrec_port *port;
1017 struct ovsrec_interface *iface;
1018 struct ovsrec_bridge *br;
1021 parent = find_bridge(&info, parent_name, false);
1022 if (parent && parent->vlan) {
1023 vsctl_fatal("cannot create bridge with fake bridge as parent");
1026 vsctl_fatal("parent bridge %s does not exist", parent_name);
1028 br = parent->br_cfg;
1030 iface = ovsrec_interface_insert(ctx->txn);
1031 ovsrec_interface_set_name(iface, br_name);
1032 ovsrec_interface_set_type(iface, "internal");
1034 port = ovsrec_port_insert(ctx->txn);
1035 ovsrec_port_set_name(port, br_name);
1036 ovsrec_port_set_interfaces(port, &iface, 1);
1037 ovsrec_port_set_fake_bridge(port, true);
1038 ovsrec_port_set_tag(port, &tag, 1);
1040 bridge_insert_port(br, port);
1047 del_port(struct vsctl_info *info, struct vsctl_port *port)
1049 struct shash_node *node;
1051 SHASH_FOR_EACH (node, &info->ifaces) {
1052 struct vsctl_iface *iface = node->data;
1053 if (iface->port == port) {
1054 ovsrec_interface_delete(iface->iface_cfg);
1057 ovsrec_port_delete(port->port_cfg);
1059 bridge_delete_port((port->bridge->parent
1060 ? port->bridge->parent->br_cfg
1061 : port->bridge->br_cfg), port->port_cfg);
1065 cmd_del_br(struct vsctl_context *ctx)
1067 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1068 struct vsctl_bridge *bridge;
1069 struct vsctl_info info;
1071 get_info(ctx->ovs, &info);
1072 bridge = find_bridge(&info, ctx->argv[1], must_exist);
1074 struct shash_node *node;
1076 SHASH_FOR_EACH (node, &info.ports) {
1077 struct vsctl_port *port = node->data;
1078 if (port->bridge == bridge || port->bridge->parent == bridge
1079 || !strcmp(port->port_cfg->name, bridge->name)) {
1080 del_port(&info, port);
1083 if (bridge->br_cfg) {
1084 ovsrec_bridge_delete(bridge->br_cfg);
1085 ovs_delete_bridge(ctx->ovs, bridge->br_cfg);
1092 output_sorted(struct svec *svec, struct ds *output)
1098 SVEC_FOR_EACH (i, name, svec) {
1099 ds_put_format(output, "%s\n", name);
1104 cmd_list_br(struct vsctl_context *ctx)
1106 struct shash_node *node;
1107 struct vsctl_info info;
1108 struct svec bridges;
1110 get_info(ctx->ovs, &info);
1112 svec_init(&bridges);
1113 SHASH_FOR_EACH (node, &info.bridges) {
1114 struct vsctl_bridge *br = node->data;
1115 svec_add(&bridges, br->name);
1117 output_sorted(&bridges, &ctx->output);
1118 svec_destroy(&bridges);
1124 cmd_br_exists(struct vsctl_context *ctx)
1126 struct vsctl_info info;
1128 get_info(ctx->ovs, &info);
1129 if (!find_bridge(&info, ctx->argv[1], false)) {
1135 /* Returns true if 'b_prefix' (of length 'b_prefix_len') concatenated with 'b'
1136 * equals 'a', false otherwise. */
1138 key_matches(const char *a,
1139 const char *b_prefix, size_t b_prefix_len, const char *b)
1141 return !strncmp(a, b_prefix, b_prefix_len) && !strcmp(a + b_prefix_len, b);
1145 set_external_id(char **old_keys, char **old_values, size_t old_n,
1146 char *key, char *value,
1147 char ***new_keysp, char ***new_valuesp, size_t *new_np)
1154 new_keys = xmalloc(sizeof *new_keys * (old_n + 1));
1155 new_values = xmalloc(sizeof *new_values * (old_n + 1));
1157 for (i = 0; i < old_n; i++) {
1158 if (strcmp(key, old_keys[i])) {
1159 new_keys[new_n] = old_keys[i];
1160 new_values[new_n] = old_values[i];
1165 new_keys[new_n] = key;
1166 new_values[new_n] = value;
1169 *new_keysp = new_keys;
1170 *new_valuesp = new_values;
1175 cmd_br_set_external_id(struct vsctl_context *ctx)
1177 struct vsctl_info info;
1178 struct vsctl_bridge *bridge;
1179 char **keys, **values;
1182 get_info(ctx->ovs, &info);
1183 bridge = find_bridge(&info, ctx->argv[1], true);
1184 if (bridge->br_cfg) {
1185 set_external_id(bridge->br_cfg->key_external_ids,
1186 bridge->br_cfg->value_external_ids,
1187 bridge->br_cfg->n_external_ids,
1188 ctx->argv[2], ctx->argc >= 4 ? ctx->argv[3] : NULL,
1189 &keys, &values, &n);
1190 ovsrec_bridge_set_external_ids(bridge->br_cfg, keys, values, n);
1192 char *key = xasprintf("fake-bridge-%s", ctx->argv[2]);
1193 struct vsctl_port *port = shash_find_data(&info.ports, ctx->argv[1]);
1194 set_external_id(port->port_cfg->key_external_ids,
1195 port->port_cfg->value_external_ids,
1196 port->port_cfg->n_external_ids,
1197 key, ctx->argc >= 4 ? ctx->argv[3] : NULL,
1198 &keys, &values, &n);
1199 ovsrec_port_set_external_ids(port->port_cfg, keys, values, n);
1209 get_external_id(char **keys, char **values, size_t n,
1210 const char *prefix, const char *key,
1213 size_t prefix_len = strlen(prefix);
1218 for (i = 0; i < n; i++) {
1219 if (!key && !strncmp(keys[i], prefix, prefix_len)) {
1220 svec_add_nocopy(&svec, xasprintf("%s=%s",
1221 keys[i] + prefix_len, values[i]));
1222 } else if (key_matches(keys[i], prefix, prefix_len, key)) {
1223 svec_add(&svec, values[i]);
1227 output_sorted(&svec, output);
1228 svec_destroy(&svec);
1232 cmd_br_get_external_id(struct vsctl_context *ctx)
1234 struct vsctl_info info;
1235 struct vsctl_bridge *bridge;
1237 get_info(ctx->ovs, &info);
1238 bridge = find_bridge(&info, ctx->argv[1], true);
1239 if (bridge->br_cfg) {
1240 get_external_id(bridge->br_cfg->key_external_ids,
1241 bridge->br_cfg->value_external_ids,
1242 bridge->br_cfg->n_external_ids,
1243 "", ctx->argc >= 3 ? ctx->argv[2] : NULL,
1246 struct vsctl_port *port = shash_find_data(&info.ports, ctx->argv[1]);
1247 get_external_id(port->port_cfg->key_external_ids,
1248 port->port_cfg->value_external_ids,
1249 port->port_cfg->n_external_ids,
1250 "fake-bridge-", ctx->argc >= 3 ? ctx->argv[2] : NULL, &ctx->output);
1257 cmd_list_ports(struct vsctl_context *ctx)
1259 struct vsctl_bridge *br;
1260 struct shash_node *node;
1261 struct vsctl_info info;
1264 get_info(ctx->ovs, &info);
1265 br = find_bridge(&info, ctx->argv[1], true);
1268 SHASH_FOR_EACH (node, &info.ports) {
1269 struct vsctl_port *port = node->data;
1271 if (strcmp(port->port_cfg->name, br->name) && br == port->bridge) {
1272 svec_add(&ports, port->port_cfg->name);
1275 output_sorted(&ports, &ctx->output);
1276 svec_destroy(&ports);
1282 add_port(struct vsctl_context *ctx,
1283 const char *br_name, const char *port_name,
1284 bool may_exist, bool fake_iface,
1285 char *iface_names[], int n_ifaces,
1286 char *settings[], int n_settings)
1288 struct vsctl_info info;
1289 struct vsctl_bridge *bridge;
1290 struct ovsrec_interface **ifaces;
1291 struct ovsrec_port *port;
1294 get_info(ctx->ovs, &info);
1296 struct vsctl_port *port;
1298 port = find_port(&info, port_name, false);
1300 struct svec want_names, have_names;
1303 svec_init(&want_names);
1304 for (i = 0; i < n_ifaces; i++) {
1305 svec_add(&want_names, iface_names[i]);
1307 svec_sort(&want_names);
1309 svec_init(&have_names);
1310 for (i = 0; i < port->port_cfg->n_interfaces; i++) {
1311 svec_add(&have_names, port->port_cfg->interfaces[i]->name);
1313 svec_sort(&have_names);
1315 if (strcmp(port->bridge->name, br_name)) {
1316 char *command = vsctl_context_to_string(ctx);
1317 vsctl_fatal("\"%s\" but %s is actually attached to bridge %s",
1318 command, port_name, port->bridge->name);
1321 if (!svec_equal(&want_names, &have_names)) {
1322 char *have_names_string = svec_join(&have_names, ", ", "");
1323 char *command = vsctl_context_to_string(ctx);
1325 vsctl_fatal("\"%s\" but %s actually has interface(s) %s",
1326 command, port_name, have_names_string);
1329 svec_destroy(&want_names);
1330 svec_destroy(&have_names);
1335 check_conflicts(&info, port_name,
1336 xasprintf("cannot create a port named %s", port_name));
1337 for (i = 0; i < n_ifaces; i++) {
1338 check_conflicts(&info, iface_names[i],
1339 xasprintf("cannot create an interface named %s",
1342 bridge = find_bridge(&info, br_name, true);
1344 ifaces = xmalloc(n_ifaces * sizeof *ifaces);
1345 for (i = 0; i < n_ifaces; i++) {
1346 ifaces[i] = ovsrec_interface_insert(ctx->txn);
1347 ovsrec_interface_set_name(ifaces[i], iface_names[i]);
1350 port = ovsrec_port_insert(ctx->txn);
1351 ovsrec_port_set_name(port, port_name);
1352 ovsrec_port_set_interfaces(port, ifaces, n_ifaces);
1353 ovsrec_port_set_bond_fake_iface(port, fake_iface);
1357 int64_t tag = bridge->vlan;
1358 ovsrec_port_set_tag(port, &tag, 1);
1361 for (i = 0; i < n_settings; i++) {
1362 set_column(get_table("Port"), &port->header_, settings[i]);
1365 bridge_insert_port((bridge->parent ? bridge->parent->br_cfg
1366 : bridge->br_cfg), port);
1372 cmd_add_port(struct vsctl_context *ctx)
1374 bool may_exist = shash_find(&ctx->options, "--may-exist") != 0;
1376 add_port(ctx, ctx->argv[1], ctx->argv[2], may_exist, false,
1377 &ctx->argv[2], 1, &ctx->argv[3], ctx->argc - 3);
1381 cmd_add_bond(struct vsctl_context *ctx)
1383 bool may_exist = shash_find(&ctx->options, "--may-exist") != 0;
1384 bool fake_iface = shash_find(&ctx->options, "--fake-iface");
1388 n_ifaces = ctx->argc - 3;
1389 for (i = 3; i < ctx->argc; i++) {
1390 if (strchr(ctx->argv[i], '=')) {
1396 vsctl_fatal("add-bond requires at least 2 interfaces, but only "
1397 "%d were specified", n_ifaces);
1400 add_port(ctx, ctx->argv[1], ctx->argv[2], may_exist, fake_iface,
1401 &ctx->argv[3], n_ifaces,
1402 &ctx->argv[n_ifaces + 3], ctx->argc - 3 - n_ifaces);
1406 cmd_del_port(struct vsctl_context *ctx)
1408 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1409 bool with_iface = shash_find(&ctx->options, "--with-iface") != NULL;
1410 struct vsctl_port *port;
1411 struct vsctl_info info;
1413 get_info(ctx->ovs, &info);
1415 port = find_port(&info, ctx->argv[ctx->argc - 1], must_exist);
1417 const char *target = ctx->argv[ctx->argc - 1];
1418 struct vsctl_iface *iface;
1420 port = find_port(&info, target, false);
1422 iface = find_iface(&info, target, false);
1427 if (must_exist && !port) {
1428 vsctl_fatal("no port or interface named %s", target);
1433 if (ctx->argc == 3) {
1434 struct vsctl_bridge *bridge;
1436 bridge = find_bridge(&info, ctx->argv[1], true);
1437 if (port->bridge != bridge) {
1438 if (port->bridge->parent == bridge) {
1439 vsctl_fatal("bridge %s does not have a port %s (although "
1440 "its parent bridge %s does)",
1441 ctx->argv[1], ctx->argv[2],
1442 bridge->parent->name);
1444 vsctl_fatal("bridge %s does not have a port %s",
1445 ctx->argv[1], ctx->argv[2]);
1450 del_port(&info, port);
1457 cmd_port_to_br(struct vsctl_context *ctx)
1459 struct vsctl_port *port;
1460 struct vsctl_info info;
1462 get_info(ctx->ovs, &info);
1463 port = find_port(&info, ctx->argv[1], true);
1464 ds_put_format(&ctx->output, "%s\n", port->bridge->name);
1469 cmd_br_to_vlan(struct vsctl_context *ctx)
1471 struct vsctl_bridge *bridge;
1472 struct vsctl_info info;
1474 get_info(ctx->ovs, &info);
1475 bridge = find_bridge(&info, ctx->argv[1], true);
1476 ds_put_format(&ctx->output, "%d\n", bridge->vlan);
1481 cmd_br_to_parent(struct vsctl_context *ctx)
1483 struct vsctl_bridge *bridge;
1484 struct vsctl_info info;
1486 get_info(ctx->ovs, &info);
1487 bridge = find_bridge(&info, ctx->argv[1], true);
1488 if (bridge->parent) {
1489 bridge = bridge->parent;
1491 ds_put_format(&ctx->output, "%s\n", bridge->name);
1496 cmd_list_ifaces(struct vsctl_context *ctx)
1498 struct vsctl_bridge *br;
1499 struct shash_node *node;
1500 struct vsctl_info info;
1503 get_info(ctx->ovs, &info);
1504 br = find_bridge(&info, ctx->argv[1], true);
1507 SHASH_FOR_EACH (node, &info.ifaces) {
1508 struct vsctl_iface *iface = node->data;
1510 if (strcmp(iface->iface_cfg->name, br->name)
1511 && br == iface->port->bridge) {
1512 svec_add(&ifaces, iface->iface_cfg->name);
1515 output_sorted(&ifaces, &ctx->output);
1516 svec_destroy(&ifaces);
1522 cmd_iface_to_br(struct vsctl_context *ctx)
1524 struct vsctl_iface *iface;
1525 struct vsctl_info info;
1527 get_info(ctx->ovs, &info);
1528 iface = find_iface(&info, ctx->argv[1], true);
1529 ds_put_format(&ctx->output, "%s\n", iface->port->bridge->name);
1533 /* Print targets of the 'n_controllers' in 'controllers' on the output for
1536 print_controllers(struct vsctl_context *ctx,
1537 struct ovsrec_controller **controllers,
1538 size_t n_controllers)
1540 /* Print the targets in sorted order for reproducibility. */
1541 struct svec targets;
1544 svec_init(&targets);
1545 for (i = 0; i < n_controllers; i++) {
1546 svec_add(&targets, controllers[i]->target);
1549 svec_sort(&targets);
1550 for (i = 0; i < targets.n; i++) {
1551 ds_put_format(&ctx->output, "%s\n", targets.names[i]);
1553 svec_destroy(&targets);
1557 cmd_get_controller(struct vsctl_context *ctx)
1559 struct vsctl_info info;
1561 get_info(ctx->ovs, &info);
1563 if (ctx->argc == 1 || !strcmp(ctx->argv[1], "default")) {
1564 print_controllers(ctx, info.ctrl, info.n_ctrl);
1566 struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true);
1568 print_controllers(ctx, br->ctrl, br->n_ctrl);
1570 print_controllers(ctx, info.ctrl, info.n_ctrl);
1578 delete_controllers(struct ovsrec_controller **controllers,
1579 size_t n_controllers)
1583 for (i = 0; i < n_controllers; i++) {
1584 ovsrec_controller_delete(controllers[i]);
1589 cmd_del_controller(struct vsctl_context *ctx)
1591 struct vsctl_info info;
1593 get_info(ctx->ovs, &info);
1595 if (ctx->argc == 1 || !strcmp(ctx->argv[1], "default")) {
1597 delete_controllers(info.ctrl, info.n_ctrl);
1598 ovsrec_open_vswitch_set_controller(ctx->ovs, NULL, 0);
1601 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1603 delete_controllers(br->ctrl, br->n_ctrl);
1604 ovsrec_bridge_set_controller(br->br_cfg, NULL, 0);
1611 static struct ovsrec_controller **
1612 insert_controllers(struct ovsdb_idl_txn *txn, char *targets[], size_t n)
1614 struct ovsrec_controller **controllers;
1617 controllers = xmalloc(n * sizeof *controllers);
1618 for (i = 0; i < n; i++) {
1619 controllers[i] = ovsrec_controller_insert(txn);
1620 ovsrec_controller_set_target(controllers[i], targets[i]);
1627 set_default_controllers(struct vsctl_context *ctx, char *targets[], size_t n)
1629 struct ovsrec_controller **controllers;
1631 delete_controllers(ctx->ovs->controller, ctx->ovs->n_controller);
1633 controllers = insert_controllers(ctx->txn, targets, n);
1634 ovsrec_open_vswitch_set_controller(ctx->ovs, controllers, n);
1639 cmd_set_controller(struct vsctl_context *ctx)
1641 struct vsctl_info info;
1643 get_info(ctx->ovs, &info);
1645 if (ctx->argc == 2) {
1646 /* Set one controller in the "Open_vSwitch" table. */
1647 set_default_controllers(ctx, &ctx->argv[1], 1);
1648 } else if (!strcmp(ctx->argv[1], "default")) {
1649 /* Set one or more controllers in the "Open_vSwitch" table. */
1650 set_default_controllers(ctx, &ctx->argv[2], ctx->argc - 2);
1652 /* Set one or more controllers for a particular bridge. */
1653 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1654 struct ovsrec_controller **controllers;
1657 delete_controllers(br->ctrl, br->n_ctrl);
1660 controllers = insert_controllers(ctx->txn, &ctx->argv[2], n);
1661 ovsrec_bridge_set_controller(br->br_cfg, controllers, n);
1669 get_fail_mode(struct ovsrec_controller **controllers, size_t n_controllers)
1671 const char *fail_mode;
1675 for (i = 0; i < n_controllers; i++) {
1676 const char *s = controllers[i]->fail_mode;
1678 if (!strcmp(s, "secure")) {
1690 cmd_get_fail_mode(struct vsctl_context *ctx)
1692 struct vsctl_info info;
1693 const char *fail_mode = NULL;
1695 get_info(ctx->ovs, &info);
1697 if (ctx->argc == 1 || !strcmp(ctx->argv[1], "default")) {
1698 /* Return the fail-mode from the "Open_vSwitch" table */
1699 fail_mode = get_fail_mode(info.ctrl, info.n_ctrl);
1701 /* Return the fail-mode for a particular bridge. */
1702 struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true);
1704 /* If no controller is defined for the requested bridge, fallback to
1705 * the "Open_vSwitch" table's controller. */
1706 fail_mode = (br->n_ctrl
1707 ? get_fail_mode(br->ctrl, br->n_ctrl)
1708 : get_fail_mode(info.ctrl, info.n_ctrl));
1711 if (fail_mode && strlen(fail_mode)) {
1712 ds_put_format(&ctx->output, "%s\n", fail_mode);
1719 set_fail_mode(struct ovsrec_controller **controllers, size_t n_controllers,
1720 const char *fail_mode)
1724 for (i = 0; i < n_controllers; i++) {
1725 ovsrec_controller_set_fail_mode(controllers[i], fail_mode);
1730 cmd_del_fail_mode(struct vsctl_context *ctx)
1732 struct vsctl_info info;
1734 get_info(ctx->ovs, &info);
1736 if (ctx->argc == 1 || !strcmp(ctx->argv[1], "default")) {
1737 set_fail_mode(info.ctrl, info.n_ctrl, NULL);
1739 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1741 set_fail_mode(br->ctrl, br->n_ctrl, NULL);
1748 cmd_set_fail_mode(struct vsctl_context *ctx)
1750 struct vsctl_info info;
1752 const char *fail_mode;
1754 get_info(ctx->ovs, &info);
1756 if (ctx->argc == 2) {
1758 fail_mode = ctx->argv[1];
1760 bridge = ctx->argv[1];
1761 fail_mode = ctx->argv[2];
1764 if (strcmp(fail_mode, "standalone") && strcmp(fail_mode, "secure")) {
1765 vsctl_fatal("fail-mode must be \"standalone\" or \"secure\"");
1768 if (!strcmp(bridge, "default")) {
1769 /* Set the fail-mode in the "Open_vSwitch" table. */
1771 vsctl_fatal("no controller declared");
1773 set_fail_mode(info.ctrl, info.n_ctrl, fail_mode);
1775 struct vsctl_bridge *br = find_real_bridge(&info, bridge, true);
1778 vsctl_fatal("no controller declared for %s", br->name);
1780 set_fail_mode(br->ctrl, br->n_ctrl, fail_mode);
1787 cmd_get_ssl(struct vsctl_context *ctx)
1789 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1792 ds_put_format(&ctx->output, "Private key: %s\n", ssl->private_key);
1793 ds_put_format(&ctx->output, "Certificate: %s\n", ssl->certificate);
1794 ds_put_format(&ctx->output, "CA Certificate: %s\n", ssl->ca_cert);
1795 ds_put_format(&ctx->output, "Bootstrap: %s\n",
1796 ssl->bootstrap_ca_cert ? "true" : "false");
1801 cmd_del_ssl(struct vsctl_context *ctx)
1803 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1806 ovsrec_ssl_delete(ssl);
1807 ovsrec_open_vswitch_set_ssl(ctx->ovs, NULL);
1812 cmd_set_ssl(struct vsctl_context *ctx)
1814 bool bootstrap = shash_find(&ctx->options, "--bootstrap");
1815 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1818 ovsrec_ssl_delete(ssl);
1820 ssl = ovsrec_ssl_insert(ctx->txn);
1822 ovsrec_ssl_set_private_key(ssl, ctx->argv[1]);
1823 ovsrec_ssl_set_certificate(ssl, ctx->argv[2]);
1824 ovsrec_ssl_set_ca_cert(ssl, ctx->argv[3]);
1826 ovsrec_ssl_set_bootstrap_ca_cert(ssl, bootstrap);
1828 ovsrec_open_vswitch_set_ssl(ctx->ovs, ssl);
1831 /* Parameter commands. */
1833 struct vsctl_row_id {
1834 const struct ovsdb_idl_table_class *table;
1835 const struct ovsdb_idl_column *name_column;
1836 const struct ovsdb_idl_column *uuid_column;
1839 struct vsctl_table_class {
1840 struct ovsdb_idl_table_class *class;
1841 struct vsctl_row_id row_ids[2];
1844 static const struct vsctl_table_class tables[] = {
1845 {&ovsrec_table_bridge,
1846 {{&ovsrec_table_bridge, &ovsrec_bridge_col_name, NULL},
1847 {NULL, NULL, NULL}}},
1849 {&ovsrec_table_controller,
1850 {{&ovsrec_table_bridge,
1851 &ovsrec_bridge_col_name,
1852 &ovsrec_bridge_col_controller},
1853 {&ovsrec_table_open_vswitch,
1855 &ovsrec_open_vswitch_col_controller}}},
1857 {&ovsrec_table_interface,
1858 {{&ovsrec_table_interface, &ovsrec_interface_col_name, NULL},
1859 {NULL, NULL, NULL}}},
1861 {&ovsrec_table_mirror,
1862 {{&ovsrec_table_mirror, &ovsrec_mirror_col_name, NULL},
1863 {NULL, NULL, NULL}}},
1865 {&ovsrec_table_netflow,
1866 {{&ovsrec_table_bridge,
1867 &ovsrec_bridge_col_name,
1868 &ovsrec_bridge_col_netflow},
1869 {NULL, NULL, NULL}}},
1871 {&ovsrec_table_open_vswitch,
1872 {{&ovsrec_table_open_vswitch, NULL, NULL},
1873 {NULL, NULL, NULL}}},
1875 {&ovsrec_table_port,
1876 {{&ovsrec_table_port, &ovsrec_port_col_name, NULL},
1877 {NULL, NULL, NULL}}},
1880 {{&ovsrec_table_open_vswitch, NULL, &ovsrec_open_vswitch_col_ssl}}},
1882 {&ovsrec_table_sflow,
1883 {{&ovsrec_table_bridge,
1884 &ovsrec_bridge_col_name,
1885 &ovsrec_bridge_col_sflow},
1886 {NULL, NULL, NULL}}},
1888 {NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}
1892 die_if_error(char *error)
1895 vsctl_fatal("%s", error);
1900 to_lower_and_underscores(unsigned c)
1902 return c == '-' ? '_' : tolower(c);
1906 score_partial_match(const char *name, const char *s)
1910 if (!strcmp(name, s)) {
1913 for (score = 0; ; score++, name++, s++) {
1914 if (to_lower_and_underscores(*name) != to_lower_and_underscores(*s)) {
1916 } else if (*name == '\0') {
1917 return UINT_MAX - 1;
1920 return *s == '\0' ? score : 0;
1923 static const struct vsctl_table_class *
1924 get_table(const char *table_name)
1926 const struct vsctl_table_class *table;
1927 const struct vsctl_table_class *best_match = NULL;
1928 unsigned int best_score = 0;
1930 for (table = tables; table->class; table++) {
1931 unsigned int score = score_partial_match(table->class->name,
1933 if (score > best_score) {
1936 } else if (score == best_score) {
1942 } else if (best_score) {
1943 vsctl_fatal("multiple table names match \"%s\"", table_name);
1945 vsctl_fatal("unknown table \"%s\"", table_name);
1949 static const struct ovsdb_idl_row *
1950 get_row_by_id(struct vsctl_context *ctx, const struct vsctl_table_class *table,
1951 const struct vsctl_row_id *id, const char *record_id)
1953 const struct ovsdb_idl_row *referrer, *final;
1959 if (!id->name_column) {
1960 if (strcmp(record_id, ".")) {
1963 referrer = ovsdb_idl_first_row(ctx->idl, id->table);
1964 if (!referrer || ovsdb_idl_next_row(referrer)) {
1968 const struct ovsdb_idl_row *row;
1969 unsigned int best_score = 0;
1971 /* It might make sense to relax this assertion. */
1972 assert(id->name_column->type.key.type == OVSDB_TYPE_STRING);
1975 for (row = ovsdb_idl_first_row(ctx->idl, id->table);
1976 row != NULL && best_score != UINT_MAX;
1977 row = ovsdb_idl_next_row(row))
1979 struct ovsdb_datum name;
1981 ovsdb_idl_txn_read(row, id->name_column, &name);
1983 unsigned int score = score_partial_match(name.keys[0].string,
1985 if (score > best_score) {
1988 } else if (score == best_score) {
1992 ovsdb_datum_destroy(&name, &id->name_column->type);
1994 if (best_score && !referrer) {
1995 vsctl_fatal("multiple rows in %s match \"%s\"",
1996 table->class->name, record_id);
2004 if (id->uuid_column) {
2005 struct ovsdb_datum uuid;
2007 assert(id->uuid_column->type.key.type == OVSDB_TYPE_UUID);
2008 assert(id->uuid_column->type.value.type == OVSDB_TYPE_VOID);
2010 ovsdb_idl_txn_read(referrer, id->uuid_column, &uuid);
2012 final = ovsdb_idl_get_row_for_uuid(ctx->idl, table->class,
2013 &uuid.keys[0].uuid);
2015 ovsdb_datum_destroy(&uuid, &id->uuid_column->type);
2023 static const struct ovsdb_idl_row *
2024 get_row(struct vsctl_context *ctx,
2025 const struct vsctl_table_class *table, const char *record_id)
2027 const struct ovsdb_idl_row *row;
2030 if (uuid_from_string(&uuid, record_id)) {
2031 row = ovsdb_idl_get_row_for_uuid(ctx->idl, table->class, &uuid);
2035 for (i = 0; i < ARRAY_SIZE(table->row_ids); i++) {
2036 row = get_row_by_id(ctx, table, &table->row_ids[i], record_id);
2045 static const struct ovsdb_idl_row *
2046 must_get_row(struct vsctl_context *ctx,
2047 const struct vsctl_table_class *table, const char *record_id)
2049 const struct ovsdb_idl_row *row = get_row(ctx, table, record_id);
2051 vsctl_fatal("no row \"%s\" in table %s",
2052 record_id, table->class->name);
2058 get_column(const struct vsctl_table_class *table, const char *column_name,
2059 const struct ovsdb_idl_column **columnp)
2061 const struct ovsdb_idl_column *best_match = NULL;
2062 unsigned int best_score = 0;
2065 for (i = 0; i < table->class->n_columns; i++) {
2066 const struct ovsdb_idl_column *column = &table->class->columns[i];
2067 unsigned int score = score_partial_match(column->name, column_name);
2068 if (score > best_score) {
2069 best_match = column;
2071 } else if (score == best_score) {
2076 *columnp = best_match;
2079 } else if (best_score) {
2080 return xasprintf("%s contains more than one column whose name "
2081 "matches \"%s\"", table->class->name, column_name);
2083 return xasprintf("%s does not contain a column whose name matches "
2084 "\"%s\"", table->class->name, column_name);
2088 static char * WARN_UNUSED_RESULT
2089 parse_column_key_value(const char *arg, const struct vsctl_table_class *table,
2090 const struct ovsdb_idl_column **columnp,
2091 char **keyp, char **valuep)
2093 const char *p = arg;
2096 assert(columnp || keyp);
2104 /* Parse column name. */
2108 error = ovsdb_token_parse(&p, &column_name);
2112 if (column_name[0] == '\0') {
2114 error = xasprintf("%s: missing column name", arg);
2117 error = get_column(table, column_name, columnp);
2124 /* Parse key string. */
2125 if (*p == ':' || !columnp) {
2129 error = xasprintf("%s: key not accepted here", arg);
2132 error = ovsdb_token_parse(&p, keyp);
2140 /* Parse value string. */
2143 error = xasprintf("%s: value not accepted here", arg);
2146 *valuep = xstrdup(p + 1);
2152 error = xasprintf("%s: trailing garbage \"%s\" in argument",
2175 cmd_get(struct vsctl_context *ctx)
2177 bool if_exists = shash_find(&ctx->options, "--if-exists");
2178 const char *table_name = ctx->argv[1];
2179 const char *record_id = ctx->argv[2];
2180 const struct vsctl_table_class *table;
2181 const struct ovsdb_idl_row *row;
2182 struct ds *out = &ctx->output;
2185 table = get_table(table_name);
2186 row = must_get_row(ctx, table, record_id);
2187 for (i = 3; i < ctx->argc; i++) {
2188 const struct ovsdb_idl_column *column;
2189 struct ovsdb_datum datum;
2192 die_if_error(parse_column_key_value(ctx->argv[i], table,
2193 &column, &key_string, NULL));
2195 ovsdb_idl_txn_read(row, column, &datum);
2197 union ovsdb_atom key;
2200 if (column->type.value.type == OVSDB_TYPE_VOID) {
2201 vsctl_fatal("cannot specify key to get for non-map column %s",
2205 die_if_error(ovsdb_atom_from_string(&key,
2209 idx = ovsdb_datum_find_key(&datum, &key,
2210 column->type.key.type);
2211 if (idx == UINT_MAX) {
2213 vsctl_fatal("no key \"%s\" in %s record \"%s\" column %s",
2214 key_string, table->class->name, record_id,
2218 ovsdb_atom_to_string(&datum.values[idx],
2219 column->type.value.type, out);
2221 ovsdb_atom_destroy(&key, column->type.key.type);
2223 ovsdb_datum_to_string(&datum, &column->type, out);
2225 ds_put_char(out, '\n');
2226 ovsdb_datum_destroy(&datum, &column->type);
2233 list_record(const struct vsctl_table_class *table,
2234 const struct ovsdb_idl_row *row, struct ds *out)
2238 ds_put_format(out, "%-20s: "UUID_FMT"\n", "_uuid",
2239 UUID_ARGS(&row->uuid));
2240 for (i = 0; i < table->class->n_columns; i++) {
2241 const struct ovsdb_idl_column *column = &table->class->columns[i];
2242 struct ovsdb_datum datum;
2244 ovsdb_idl_txn_read(row, column, &datum);
2246 ds_put_format(out, "%-20s: ", column->name);
2247 ovsdb_datum_to_string(&datum, &column->type, out);
2248 ds_put_char(out, '\n');
2250 ovsdb_datum_destroy(&datum, &column->type);
2255 cmd_list(struct vsctl_context *ctx)
2257 const char *table_name = ctx->argv[1];
2258 const struct vsctl_table_class *table;
2259 struct ds *out = &ctx->output;
2262 table = get_table(table_name);
2263 if (ctx->argc > 2) {
2264 for (i = 2; i < ctx->argc; i++) {
2266 ds_put_char(out, '\n');
2268 list_record(table, must_get_row(ctx, table, ctx->argv[i]), out);
2271 const struct ovsdb_idl_row *row;
2274 for (row = ovsdb_idl_first_row(ctx->idl, table->class), first = true;
2276 row = ovsdb_idl_next_row(row), first = false) {
2278 ds_put_char(out, '\n');
2280 list_record(table, row, out);
2286 set_column(const struct vsctl_table_class *table,
2287 const struct ovsdb_idl_row *row, const char *arg)
2289 const struct ovsdb_idl_column *column;
2290 char *key_string, *value_string;
2293 error = parse_column_key_value(arg, table, &column, &key_string,
2295 die_if_error(error);
2296 if (!value_string) {
2297 vsctl_fatal("%s: missing value", arg);
2301 union ovsdb_atom key, value;
2302 struct ovsdb_datum old, new;
2304 if (column->type.value.type == OVSDB_TYPE_VOID) {
2305 vsctl_fatal("cannot specify key to set for non-map column %s",
2309 die_if_error(ovsdb_atom_from_string(&key, &column->type.key,
2311 die_if_error(ovsdb_atom_from_string(&value, &column->type.value,
2314 ovsdb_datum_init_empty(&new);
2315 ovsdb_datum_add_unsafe(&new, &key, &value, &column->type);
2317 ovsdb_atom_destroy(&key, column->type.key.type);
2318 ovsdb_atom_destroy(&value, column->type.value.type);
2320 ovsdb_idl_txn_read(row, column, &old);
2321 ovsdb_datum_union(&old, &new, &column->type, true);
2322 ovsdb_idl_txn_write(row, column, &old);
2324 ovsdb_datum_destroy(&new, &column->type);
2326 struct ovsdb_datum datum;
2328 die_if_error(ovsdb_datum_from_string(&datum, &column->type,
2330 ovsdb_idl_txn_write(row, column, &datum);
2338 cmd_set(struct vsctl_context *ctx)
2340 const char *table_name = ctx->argv[1];
2341 const char *record_id = ctx->argv[2];
2342 const struct vsctl_table_class *table;
2343 const struct ovsdb_idl_row *row;
2346 table = get_table(table_name);
2347 row = must_get_row(ctx, table, record_id);
2348 for (i = 3; i < ctx->argc; i++) {
2349 set_column(table, row, ctx->argv[i]);
2354 cmd_add(struct vsctl_context *ctx)
2356 const char *table_name = ctx->argv[1];
2357 const char *record_id = ctx->argv[2];
2358 const char *column_name = ctx->argv[3];
2359 const struct vsctl_table_class *table;
2360 const struct ovsdb_idl_column *column;
2361 const struct ovsdb_idl_row *row;
2362 const struct ovsdb_type *type;
2363 struct ovsdb_datum old;
2366 table = get_table(table_name);
2367 row = must_get_row(ctx, table, record_id);
2368 die_if_error(get_column(table, column_name, &column));
2370 type = &column->type;
2371 ovsdb_idl_txn_read(row, column, &old);
2372 for (i = 4; i < ctx->argc; i++) {
2373 struct ovsdb_type add_type;
2374 struct ovsdb_datum add;
2378 add_type.n_max = UINT_MAX;
2379 die_if_error(ovsdb_datum_from_string(&add, &add_type, ctx->argv[i]));
2380 ovsdb_datum_union(&old, &add, type, false);
2381 ovsdb_datum_destroy(&add, type);
2383 if (old.n > type->n_max) {
2384 vsctl_fatal("\"add\" operation would put %u %s in column %s of "
2385 "table %s but the maximum number is %u",
2387 type->value.type == OVSDB_TYPE_VOID ? "values" : "pairs",
2388 column->name, table->class->name, type->n_max);
2390 ovsdb_idl_txn_write(row, column, &old);
2394 cmd_remove(struct vsctl_context *ctx)
2396 const char *table_name = ctx->argv[1];
2397 const char *record_id = ctx->argv[2];
2398 const char *column_name = ctx->argv[3];
2399 const struct vsctl_table_class *table;
2400 const struct ovsdb_idl_column *column;
2401 const struct ovsdb_idl_row *row;
2402 const struct ovsdb_type *type;
2403 struct ovsdb_datum old;
2406 table = get_table(table_name);
2407 row = must_get_row(ctx, table, record_id);
2408 die_if_error(get_column(table, column_name, &column));
2410 type = &column->type;
2411 ovsdb_idl_txn_read(row, column, &old);
2412 for (i = 4; i < ctx->argc; i++) {
2413 struct ovsdb_type rm_type;
2414 struct ovsdb_datum rm;
2419 rm_type.n_max = UINT_MAX;
2420 error = ovsdb_datum_from_string(&rm, &rm_type, ctx->argv[i]);
2421 if (error && ovsdb_type_is_map(&rm_type)) {
2423 rm_type.value.type = OVSDB_TYPE_VOID;
2424 die_if_error(ovsdb_datum_from_string(&rm, &rm_type, ctx->argv[i]));
2426 ovsdb_datum_subtract(&old, type, &rm, &rm_type);
2427 ovsdb_datum_destroy(&rm, &rm_type);
2429 if (old.n < type->n_min) {
2430 vsctl_fatal("\"remove\" operation would put %u %s in column %s of "
2431 "table %s but the minimun number is %u",
2433 type->value.type == OVSDB_TYPE_VOID ? "values" : "pairs",
2434 column->name, table->class->name, type->n_min);
2436 ovsdb_idl_txn_write(row, column, &old);
2440 cmd_clear(struct vsctl_context *ctx)
2442 const char *table_name = ctx->argv[1];
2443 const char *record_id = ctx->argv[2];
2444 const struct vsctl_table_class *table;
2445 const struct ovsdb_idl_row *row;
2448 table = get_table(table_name);
2449 row = must_get_row(ctx, table, record_id);
2450 for (i = 3; i < ctx->argc; i++) {
2451 const struct ovsdb_idl_column *column;
2452 const struct ovsdb_type *type;
2453 struct ovsdb_datum datum;
2455 die_if_error(get_column(table, ctx->argv[i], &column));
2457 type = &column->type;
2458 if (type->n_min > 0) {
2459 vsctl_fatal("\"clear\" operation cannot be applied to column %s "
2460 "of table %s, which is not allowed to be empty",
2461 column->name, table->class->name);
2464 ovsdb_datum_init_empty(&datum);
2465 ovsdb_idl_txn_write(row, column, &datum);
2470 cmd_create(struct vsctl_context *ctx)
2472 const char *table_name = ctx->argv[1];
2473 const struct vsctl_table_class *table;
2474 const struct ovsdb_idl_row *row;
2477 table = get_table(table_name);
2478 row = ovsdb_idl_txn_insert(ctx->txn, table->class);
2479 for (i = 2; i < ctx->argc; i++) {
2480 set_column(table, row, ctx->argv[i]);
2482 ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(&row->uuid));
2485 /* This function may be used as the 'postprocess' function for commands that
2486 * insert new rows into the database. It expects that the command's 'run'
2487 * function prints the UUID reported by ovsdb_idl_txn_insert() as the command's
2488 * sole output. It replaces that output by the row's permanent UUID assigned
2489 * by the database server and appends a new-line.
2491 * Currently we use this only for "create", because the higher-level commands
2492 * are supposed to be independent of the actual structure of the vswitch
2495 post_create(struct vsctl_context *ctx)
2497 const struct uuid *real;
2500 uuid_from_string(&dummy, ds_cstr(&ctx->output));
2501 real = ovsdb_idl_txn_get_insert_uuid(ctx->txn, &dummy);
2503 ds_clear(&ctx->output);
2504 ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(real));
2506 ds_put_char(&ctx->output, '\n');
2510 cmd_destroy(struct vsctl_context *ctx)
2512 bool must_exist = !shash_find(&ctx->options, "--if-exists");
2513 const char *table_name = ctx->argv[1];
2514 const struct vsctl_table_class *table;
2517 table = get_table(table_name);
2518 for (i = 2; i < ctx->argc; i++) {
2519 const struct ovsdb_idl_row *row;
2521 row = (must_exist ? must_get_row : get_row)(ctx, table, ctx->argv[i]);
2523 ovsdb_idl_txn_delete(row);
2528 static struct json *
2529 where_uuid_equals(const struct uuid *uuid)
2532 json_array_create_1(
2533 json_array_create_3(
2534 json_string_create("_uuid"),
2535 json_string_create("=="),
2536 json_array_create_2(
2537 json_string_create("uuid"),
2538 json_string_create_nocopy(
2539 xasprintf(UUID_FMT, UUID_ARGS(uuid))))));
2543 vsctl_context_init(struct vsctl_context *ctx, struct vsctl_command *command,
2544 struct ovsdb_idl *idl, struct ovsdb_idl_txn *txn,
2545 const struct ovsrec_open_vswitch *ovs)
2547 ctx->argc = command->argc;
2548 ctx->argv = command->argv;
2549 ctx->options = command->options;
2551 ds_swap(&ctx->output, &command->output);
2559 vsctl_context_done(struct vsctl_context *ctx, struct vsctl_command *command)
2561 ds_swap(&ctx->output, &command->output);
2565 do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
2566 struct ovsdb_idl *idl)
2568 struct ovsdb_idl_txn *txn;
2569 const struct ovsrec_open_vswitch *ovs;
2570 enum ovsdb_idl_txn_status status;
2571 struct vsctl_command *c;
2572 int64_t next_cfg = 0;
2575 txn = the_idl_txn = ovsdb_idl_txn_create(idl);
2577 ovsdb_idl_txn_set_dry_run(txn);
2580 ovsdb_idl_txn_add_comment(txn, "ovs-vsctl: %s", args);
2582 ovs = ovsrec_open_vswitch_first(idl);
2584 /* XXX add verification that table is empty */
2585 ovs = ovsrec_open_vswitch_insert(txn);
2588 if (wait_for_reload) {
2589 struct json *where = where_uuid_equals(&ovs->header_.uuid);
2590 ovsdb_idl_txn_increment(txn, "Open_vSwitch", "next_cfg", where);
2591 json_destroy(where);
2594 for (c = commands; c < &commands[n_commands]; c++) {
2595 struct vsctl_context ctx;
2597 ds_init(&c->output);
2598 vsctl_context_init(&ctx, c, idl, txn, ovs);
2599 (c->syntax->run)(&ctx);
2600 vsctl_context_done(&ctx, c);
2603 status = ovsdb_idl_txn_commit_block(txn);
2604 if (wait_for_reload && status == TXN_SUCCESS) {
2605 next_cfg = ovsdb_idl_txn_get_increment_new_value(txn);
2607 for (c = commands; c < &commands[n_commands]; c++) {
2608 if (c->syntax->postprocess) {
2609 struct vsctl_context ctx;
2611 vsctl_context_init(&ctx, c, idl, txn, ovs);
2612 (c->syntax->postprocess)(&ctx);
2613 vsctl_context_done(&ctx, c);
2616 error = xstrdup(ovsdb_idl_txn_get_error(txn));
2617 ovsdb_idl_txn_destroy(txn);
2621 case TXN_INCOMPLETE:
2625 /* Should not happen--we never call ovsdb_idl_txn_abort(). */
2626 vsctl_fatal("transaction aborted");
2633 for (c = commands; c < &commands[n_commands]; c++) {
2634 ds_destroy(&c->output);
2640 vsctl_fatal("transaction error: %s", error);
2647 for (c = commands; c < &commands[n_commands]; c++) {
2648 struct ds *ds = &c->output;
2653 for (j = 0; j < ds->length; j++) {
2654 int c = ds->string[j];
2657 fputs("\\n", stdout);
2661 fputs("\\\\", stdout);
2670 fputs(ds_cstr(ds), stdout);
2672 ds_destroy(&c->output);
2673 shash_destroy(&c->options);
2677 if (wait_for_reload && status != TXN_UNCHANGED) {
2679 const struct ovsrec_open_vswitch *ovs;
2682 OVSREC_OPEN_VSWITCH_FOR_EACH (ovs, idl) {
2683 if (ovs->cur_cfg >= next_cfg) {
2687 ovsdb_idl_wait(idl);
2692 ovsdb_idl_destroy(idl);
2697 static const struct vsctl_command_syntax all_commands[] = {
2698 /* Open vSwitch commands. */
2699 {"init", 0, 0, cmd_init, NULL, ""},
2701 /* Bridge commands. */
2702 {"add-br", 1, 3, cmd_add_br, NULL, "--may-exist"},
2703 {"del-br", 1, 1, cmd_del_br, NULL, "--if-exists"},
2704 {"list-br", 0, 0, cmd_list_br, NULL, ""},
2705 {"br-exists", 1, 1, cmd_br_exists, NULL, ""},
2706 {"br-to-vlan", 1, 1, cmd_br_to_vlan, NULL, ""},
2707 {"br-to-parent", 1, 1, cmd_br_to_parent, NULL, ""},
2708 {"br-set-external-id", 2, 3, cmd_br_set_external_id, NULL, ""},
2709 {"br-get-external-id", 1, 2, cmd_br_get_external_id, NULL, ""},
2711 /* Port commands. */
2712 {"list-ports", 1, 1, cmd_list_ports, NULL, ""},
2713 {"add-port", 2, INT_MAX, cmd_add_port, NULL, "--may-exist"},
2714 {"add-bond", 4, INT_MAX, cmd_add_bond, NULL, "--may-exist,--fake-iface"},
2715 {"del-port", 1, 2, cmd_del_port, NULL, "--if-exists,--with-iface"},
2716 {"port-to-br", 1, 1, cmd_port_to_br, NULL, ""},
2718 /* Interface commands. */
2719 {"list-ifaces", 1, 1, cmd_list_ifaces, NULL, ""},
2720 {"iface-to-br", 1, 1, cmd_iface_to_br, NULL, ""},
2722 /* Controller commands. */
2723 {"get-controller", 0, 1, cmd_get_controller, NULL, ""},
2724 {"del-controller", 0, 1, cmd_del_controller, NULL, ""},
2725 {"set-controller", 1, INT_MAX, cmd_set_controller, NULL, ""},
2726 {"get-fail-mode", 0, 1, cmd_get_fail_mode, NULL, ""},
2727 {"del-fail-mode", 0, 1, cmd_del_fail_mode, NULL, ""},
2728 {"set-fail-mode", 1, 2, cmd_set_fail_mode, NULL, ""},
2731 {"get-ssl", 0, 0, cmd_get_ssl, NULL, ""},
2732 {"del-ssl", 0, 0, cmd_del_ssl, NULL, ""},
2733 {"set-ssl", 3, 3, cmd_set_ssl, NULL, "--bootstrap"},
2735 /* Switch commands. */
2736 {"emer-reset", 0, 0, cmd_emer_reset, NULL, ""},
2738 /* Parameter commands. */
2739 {"get", 3, INT_MAX, cmd_get, NULL, "--if-exists"},
2740 {"list", 1, INT_MAX, cmd_list, NULL, ""},
2741 {"set", 3, INT_MAX, cmd_set, NULL, ""},
2742 {"add", 4, INT_MAX, cmd_add, NULL, ""},
2743 {"remove", 4, INT_MAX, cmd_remove, NULL, ""},
2744 {"clear", 3, INT_MAX, cmd_clear, NULL, ""},
2745 {"create", 2, INT_MAX, cmd_create, post_create, ""},
2746 {"destroy", 1, INT_MAX, cmd_destroy, NULL, "--if-exists"},
2748 {NULL, 0, 0, NULL, NULL, NULL},