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.
31 #include "command-line.h"
34 #include "dynamic-string.h"
36 #include "ovsdb-data.h"
37 #include "ovsdb-idl.h"
38 #include "poll-loop.h"
41 #include "vswitchd/vswitch-idl.h"
46 #define THIS_MODULE VLM_vsctl
50 typedef void vsctl_handler_func(struct vsctl_context *);
52 struct vsctl_command_syntax {
56 vsctl_handler_func *run;
57 vsctl_handler_func *postprocess;
61 struct vsctl_command {
62 /* Data that remains constant after initialization. */
63 const struct vsctl_command_syntax *syntax;
68 /* Data modified by commands. */
72 /* --db: The database server to contact. */
73 static const char *db;
75 /* --oneline: Write each command's output as a single line? */
78 /* --dry-run: Do not commit any changes. */
81 /* --no-wait: Wait for ovs-vswitchd to reload its configuration? */
82 static bool wait_for_reload = true;
84 /* --timeout: Time to wait for a connection to 'db'. */
85 static int timeout = 5;
87 /* All supported commands. */
88 static const struct vsctl_command_syntax all_commands[];
90 static void vsctl_fatal(const char *, ...) PRINTF_FORMAT(1, 2) NO_RETURN;
91 static char *default_db(void);
92 static void usage(void) NO_RETURN;
93 static void parse_options(int argc, char *argv[]);
95 static struct vsctl_command *parse_commands(int argc, char *argv[],
97 static void parse_command(int argc, char *argv[], struct vsctl_command *);
98 static void do_vsctl(const char *args,
99 struct vsctl_command *, size_t n_commands,
103 main(int argc, char *argv[])
105 struct ovsdb_idl *idl;
107 struct vsctl_command *commands;
112 set_program_name(argv[0]);
113 signal(SIGPIPE, SIG_IGN);
116 vlog_set_levels(VLM_ANY_MODULE, VLF_CONSOLE, VLL_WARN);
117 vlog_set_levels(VLM_reconnect, VLF_ANY_FACILITY, VLL_WARN);
119 /* Log our arguments. This is often valuable for debugging systems. */
120 args = process_escape_args(argv);
121 VLOG_INFO("Called as %s", args);
123 /* Parse command line. */
124 parse_options(argc, argv);
125 commands = parse_commands(argc - optind, argv + optind, &n_commands);
131 /* Do basic command syntax checking. */
133 /* Now execute the commands. */
134 idl = ovsdb_idl_create(db, &ovsrec_idl_class);
135 seqno = ovsdb_idl_get_seqno(idl);
138 unsigned int new_seqno;
141 new_seqno = ovsdb_idl_get_seqno(idl);
142 if (new_seqno != seqno) {
144 vsctl_fatal("too many database inconsistency failures");
146 do_vsctl(args, commands, n_commands, idl);
156 parse_options(int argc, char *argv[])
159 OPT_DB = UCHAR_MAX + 1,
166 static struct option long_options[] = {
167 {"db", required_argument, 0, OPT_DB},
168 {"no-syslog", no_argument, 0, OPT_NO_SYSLOG},
169 {"no-wait", no_argument, 0, OPT_NO_WAIT},
170 {"dry-run", no_argument, 0, OPT_DRY_RUN},
171 {"oneline", no_argument, 0, OPT_ONELINE},
172 {"timeout", required_argument, 0, 't'},
173 {"help", no_argument, 0, 'h'},
174 {"version", no_argument, 0, 'V'},
183 c = getopt_long(argc, argv, "+v::hVt:", long_options, NULL);
198 vlog_set_levels(VLM_vsctl, VLF_SYSLOG, VLL_WARN);
202 wait_for_reload = false;
213 OVS_PRINT_VERSION(0, 0);
217 timeout = strtoul(optarg, NULL, 10);
219 ovs_fatal(0, "value %s on -t or --timeout is invalid",
239 static struct vsctl_command *
240 parse_commands(int argc, char *argv[], size_t *n_commandsp)
242 struct vsctl_command *commands;
243 size_t n_commands, allocated_commands;
247 n_commands = allocated_commands = 0;
249 for (start = i = 0; i <= argc; i++) {
250 if (i == argc || !strcmp(argv[i], "--")) {
252 if (n_commands >= allocated_commands) {
253 struct vsctl_command *c;
255 commands = x2nrealloc(commands, &allocated_commands,
257 for (c = commands; c < &commands[n_commands]; c++) {
258 shash_moved(&c->options);
261 parse_command(i - start, &argv[start],
262 &commands[n_commands++]);
268 vsctl_fatal("missing command name (use --help for help)");
270 *n_commandsp = n_commands;
275 parse_command(int argc, char *argv[], struct vsctl_command *command)
277 const struct vsctl_command_syntax *p;
280 shash_init(&command->options);
281 for (i = 0; i < argc; i++) {
282 if (argv[i][0] != '-') {
285 if (!shash_add_once(&command->options, argv[i], NULL)) {
286 vsctl_fatal("'%s' option specified multiple times", argv[i]);
290 vsctl_fatal("missing command name");
293 for (p = all_commands; p->name; p++) {
294 if (!strcmp(p->name, argv[i])) {
295 struct shash_node *node;
298 SHASH_FOR_EACH (node, &command->options) {
299 const char *s = strstr(p->options, node->name);
300 int end = s ? s[strlen(node->name)] : EOF;
301 if (end != ',' && end != ' ' && end != '\0') {
302 vsctl_fatal("'%s' command has no '%s' option",
303 argv[i], node->name);
307 n_arg = argc - i - 1;
308 if (n_arg < p->min_args) {
309 vsctl_fatal("'%s' command requires at least %d arguments",
310 p->name, p->min_args);
311 } else if (n_arg > p->max_args) {
312 vsctl_fatal("'%s' command takes at most %d arguments",
313 p->name, p->max_args);
316 command->argc = n_arg + 1;
317 command->argv = &argv[i];
323 vsctl_fatal("unknown command '%s'; use --help for help", argv[i]);
327 vsctl_fatal(const char *format, ...)
332 va_start(args, format);
333 message = xvasprintf(format, args);
336 vlog_set_levels(VLM_vsctl, VLF_CONSOLE, VLL_EMER);
337 VLOG_ERR("%s", message);
338 ovs_fatal(0, "%s", message);
345 %s: ovs-vswitchd management utility\n\
346 usage: %s [OPTIONS] COMMAND [ARG...]\n\
349 add-br BRIDGE create a new bridge named BRIDGE\n\
350 add-br BRIDGE PARENT VLAN create new fake BRIDGE in PARENT on VLAN\n\
351 del-br BRIDGE delete BRIDGE and all of its ports\n\
352 list-br print the names of all the bridges\n\
353 br-exists BRIDGE test whether BRIDGE exists\n\
354 br-to-vlan BRIDGE print the VLAN which BRIDGE is on\n\
355 br-to-parent BRIDGE print the parent of BRIDGE\n\
356 br-set-external-id BRIDGE KEY VALUE set KEY on BRIDGE to VALUE\n\
357 br-set-external-id BRIDGE KEY unset KEY on BRIDGE\n\
358 br-get-external-id BRIDGE KEY print value of KEY on BRIDGE\n\
359 br-get-external-id BRIDGE list key-value pairs on BRIDGE\n\
362 list-ports BRIDGE print the names of all the ports on BRIDGE\n\
363 add-port BRIDGE PORT add network device PORT to BRIDGE\n\
364 add-bond BRIDGE PORT IFACE... add bonded port PORT in BRIDGE from IFACES\n\
365 del-port [BRIDGE] PORT delete PORT (which may be bonded) from BRIDGE\n\
366 port-to-br PORT print name of bridge that contains PORT\n\
367 A bond is considered to be a single port.\n\
369 Interface commands (a bond consists of multiple interfaces):\n\
370 list-ifaces BRIDGE print the names of all interfaces on BRIDGE\n\
371 iface-to-br IFACE print name of bridge that contains IFACE\n\
373 Controller commands:\n\
374 get-controller [BRIDGE] print the controller for BRIDGE\n\
375 del-controller [BRIDGE] delete the controller for BRIDGE\n\
376 set-controller [BRIDGE] TARGET set the controller for BRIDGE to TARGET\n\
377 get-fail-mode [BRIDGE] print the fail-mode for BRIDGE\n\
378 del-fail-mode [BRIDGE] delete the fail-mode for BRIDGE\n\
379 set-fail-mode [BRIDGE] MODE set the fail-mode for BRIDGE to MODE\n\
382 get-ssl print the SSL configuration\n\
383 del-ssl delete the SSL configuration\n\
384 set-ssl PRIV-KEY CERT CA-CERT set the SSL configuration\n\
386 Database commands:\n\
387 list TBL [REC] list RECord (or all records) in TBL\n\
388 get TBL REC COL[:KEY] print values of COLumns in RECORD in TBL\n\
389 set TBL REC COL[:KEY]=VALUE set COLumn values in RECord in TBL\n\
390 add TBL REC COL [KEY=]VALUE add (KEY=)VALUE to COLumn in RECord in TBL\n\
391 remove TBL REC COL [KEY=]VALUE remove (KEY=)VALUE from COLumn\n\
392 clear TBL REC COL clear values from COLumn in RECord in TBL\n\
393 create TBL COL[:KEY]=VALUE create and initialize new record\n\
394 destroy TBL REC delete REC from TBL\n\
395 Potentially unsafe database commands require --force option.\n\
398 --db=DATABASE connect to DATABASE\n\
400 --oneline print exactly one line of output per command\n",
401 program_name, program_name, default_db());
405 -h, --help display this help message\n\
406 -V, --version display version information\n");
415 def = xasprintf("unix:%s/ovsdb-server", ovs_rundir);
420 struct vsctl_context {
424 struct shash options;
426 /* Modifiable state. */
428 struct ovsdb_idl *idl;
429 struct ovsdb_idl_txn *txn;
430 const struct ovsrec_open_vswitch *ovs;
433 struct vsctl_bridge {
434 struct ovsrec_bridge *br_cfg;
436 struct ovsrec_controller *ctrl;
437 struct vsctl_bridge *parent;
442 struct ovsrec_port *port_cfg;
443 struct vsctl_bridge *bridge;
447 struct ovsrec_interface *iface_cfg;
448 struct vsctl_port *port;
452 struct shash bridges;
455 struct ovsrec_controller *ctrl;
458 static struct vsctl_bridge *
459 add_bridge(struct vsctl_info *b,
460 struct ovsrec_bridge *br_cfg, const char *name,
461 struct vsctl_bridge *parent, int vlan)
463 struct vsctl_bridge *br = xmalloc(sizeof *br);
465 br->name = xstrdup(name);
468 br->ctrl = parent ? parent->br_cfg->controller : br_cfg->controller;
469 shash_add(&b->bridges, br->name, br);
474 port_is_fake_bridge(const struct ovsrec_port *port_cfg)
476 return (port_cfg->fake_bridge
478 && *port_cfg->tag >= 1 && *port_cfg->tag <= 4095);
481 static struct vsctl_bridge *
482 find_vlan_bridge(struct vsctl_info *info,
483 struct vsctl_bridge *parent, int vlan)
485 struct shash_node *node;
487 SHASH_FOR_EACH (node, &info->bridges) {
488 struct vsctl_bridge *br = node->data;
489 if (br->parent == parent && br->vlan == vlan) {
498 free_info(struct vsctl_info *info)
500 struct shash_node *node;
502 SHASH_FOR_EACH (node, &info->bridges) {
503 struct vsctl_bridge *bridge = node->data;
507 shash_destroy(&info->bridges);
509 SHASH_FOR_EACH (node, &info->ports) {
510 struct vsctl_port *port = node->data;
513 shash_destroy(&info->ports);
515 SHASH_FOR_EACH (node, &info->ifaces) {
516 struct vsctl_iface *iface = node->data;
519 shash_destroy(&info->ifaces);
523 get_info(const struct ovsrec_open_vswitch *ovs, struct vsctl_info *info)
525 struct shash bridges, ports;
528 shash_init(&info->bridges);
529 shash_init(&info->ports);
530 shash_init(&info->ifaces);
532 info->ctrl = ovs->controller;
534 shash_init(&bridges);
536 for (i = 0; i < ovs->n_bridges; i++) {
537 struct ovsrec_bridge *br_cfg = ovs->bridges[i];
538 struct vsctl_bridge *br;
541 if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
542 VLOG_WARN("%s: database contains duplicate bridge name",
546 br = add_bridge(info, br_cfg, br_cfg->name, NULL, 0);
551 for (j = 0; j < br_cfg->n_ports; j++) {
552 struct ovsrec_port *port_cfg = br_cfg->ports[j];
554 if (!shash_add_once(&ports, port_cfg->name, NULL)) {
555 VLOG_WARN("%s: database contains duplicate port name",
560 if (port_is_fake_bridge(port_cfg)
561 && shash_add_once(&bridges, port_cfg->name, NULL)) {
562 add_bridge(info, NULL, port_cfg->name, br, *port_cfg->tag);
566 shash_destroy(&bridges);
567 shash_destroy(&ports);
569 shash_init(&bridges);
571 for (i = 0; i < ovs->n_bridges; i++) {
572 struct ovsrec_bridge *br_cfg = ovs->bridges[i];
573 struct vsctl_bridge *br;
576 if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
579 br = shash_find_data(&info->bridges, br_cfg->name);
580 for (j = 0; j < br_cfg->n_ports; j++) {
581 struct ovsrec_port *port_cfg = br_cfg->ports[j];
582 struct vsctl_port *port;
585 if (!shash_add_once(&ports, port_cfg->name, NULL)) {
589 if (port_is_fake_bridge(port_cfg)
590 && !shash_add_once(&bridges, port_cfg->name, NULL)) {
594 port = xmalloc(sizeof *port);
595 port->port_cfg = port_cfg;
597 && *port_cfg->tag >= 1 && *port_cfg->tag <= 4095) {
598 port->bridge = find_vlan_bridge(info, br, *port_cfg->tag);
605 shash_add(&info->ports, port_cfg->name, port);
607 for (k = 0; k < port_cfg->n_interfaces; k++) {
608 struct ovsrec_interface *iface_cfg = port_cfg->interfaces[k];
609 struct vsctl_iface *iface;
611 if (shash_find(&info->ifaces, iface_cfg->name)) {
612 VLOG_WARN("%s: database contains duplicate interface name",
617 iface = xmalloc(sizeof *iface);
618 iface->iface_cfg = iface_cfg;
620 shash_add(&info->ifaces, iface_cfg->name, iface);
624 shash_destroy(&bridges);
625 shash_destroy(&ports);
629 check_conflicts(struct vsctl_info *info, const char *name,
632 struct vsctl_iface *iface;
633 struct vsctl_port *port;
635 if (shash_find(&info->bridges, name)) {
636 vsctl_fatal("%s because a bridge named %s already exists",
640 port = shash_find_data(&info->ports, name);
642 vsctl_fatal("%s because a port named %s already exists on "
643 "bridge %s", msg, name, port->bridge->name);
646 iface = shash_find_data(&info->ifaces, name);
648 vsctl_fatal("%s because an interface named %s already exists "
649 "on bridge %s", msg, name, iface->port->bridge->name);
655 static struct vsctl_bridge *
656 find_bridge(struct vsctl_info *info, const char *name, bool must_exist)
658 struct vsctl_bridge *br = shash_find_data(&info->bridges, name);
659 if (must_exist && !br) {
660 vsctl_fatal("no bridge named %s", name);
665 static struct vsctl_bridge *
666 find_real_bridge(struct vsctl_info *info, const char *name, bool must_exist)
668 struct vsctl_bridge *br = find_bridge(info, name, must_exist);
669 if (br && br->parent) {
670 vsctl_fatal("%s is a fake bridge", name);
675 static struct vsctl_port *
676 find_port(struct vsctl_info *info, const char *name, bool must_exist)
678 struct vsctl_port *port = shash_find_data(&info->ports, name);
679 if (port && !strcmp(name, port->bridge->name)) {
682 if (must_exist && !port) {
683 vsctl_fatal("no port named %s", name);
688 static struct vsctl_iface *
689 find_iface(struct vsctl_info *info, const char *name, bool must_exist)
691 struct vsctl_iface *iface = shash_find_data(&info->ifaces, name);
692 if (iface && !strcmp(name, iface->port->bridge->name)) {
695 if (must_exist && !iface) {
696 vsctl_fatal("no interface named %s", name);
702 bridge_insert_port(struct ovsrec_bridge *br, struct ovsrec_port *port)
704 struct ovsrec_port **ports;
707 ports = xmalloc(sizeof *br->ports * (br->n_ports + 1));
708 for (i = 0; i < br->n_ports; i++) {
709 ports[i] = br->ports[i];
711 ports[br->n_ports] = port;
712 ovsrec_bridge_set_ports(br, ports, br->n_ports + 1);
717 bridge_delete_port(struct ovsrec_bridge *br, struct ovsrec_port *port)
719 struct ovsrec_port **ports;
722 ports = xmalloc(sizeof *br->ports * br->n_ports);
723 for (i = n = 0; i < br->n_ports; i++) {
724 if (br->ports[i] != port) {
725 ports[n++] = br->ports[i];
728 ovsrec_bridge_set_ports(br, ports, n);
733 ovs_insert_bridge(const struct ovsrec_open_vswitch *ovs,
734 struct ovsrec_bridge *bridge)
736 struct ovsrec_bridge **bridges;
739 bridges = xmalloc(sizeof *ovs->bridges * (ovs->n_bridges + 1));
740 for (i = 0; i < ovs->n_bridges; i++) {
741 bridges[i] = ovs->bridges[i];
743 bridges[ovs->n_bridges] = bridge;
744 ovsrec_open_vswitch_set_bridges(ovs, bridges, ovs->n_bridges + 1);
749 ovs_delete_bridge(const struct ovsrec_open_vswitch *ovs,
750 struct ovsrec_bridge *bridge)
752 struct ovsrec_bridge **bridges;
755 bridges = xmalloc(sizeof *ovs->bridges * ovs->n_bridges);
756 for (i = n = 0; i < ovs->n_bridges; i++) {
757 if (ovs->bridges[i] != bridge) {
758 bridges[n++] = ovs->bridges[i];
761 ovsrec_open_vswitch_set_bridges(ovs, bridges, n);
766 cmd_init(struct vsctl_context *ctx UNUSED)
771 cmd_add_br(struct vsctl_context *ctx)
773 const char *br_name = ctx->argv[1];
774 struct vsctl_info info;
776 get_info(ctx->ovs, &info);
777 check_conflicts(&info, br_name,
778 xasprintf("cannot create a bridge named %s", br_name));
780 if (ctx->argc == 2) {
781 struct ovsrec_bridge *br;
782 struct ovsrec_port *port;
783 struct ovsrec_interface *iface;
785 iface = ovsrec_interface_insert(ctx->txn);
786 ovsrec_interface_set_name(iface, br_name);
788 port = ovsrec_port_insert(ctx->txn);
789 ovsrec_port_set_name(port, br_name);
790 ovsrec_port_set_interfaces(port, &iface, 1);
792 br = ovsrec_bridge_insert(ctx->txn);
793 ovsrec_bridge_set_name(br, br_name);
794 ovsrec_bridge_set_ports(br, &port, 1);
796 ovs_insert_bridge(ctx->ovs, br);
797 } else if (ctx->argc == 3) {
798 vsctl_fatal("'%s' command takes exactly 1 or 3 arguments",
800 } else if (ctx->argc == 4) {
801 const char *parent_name = ctx->argv[2];
802 int vlan = atoi(ctx->argv[3]);
803 struct ovsrec_bridge *br;
804 struct vsctl_bridge *parent;
805 struct ovsrec_port *port;
806 struct ovsrec_interface *iface;
809 if (vlan < 1 || vlan > 4095) {
810 vsctl_fatal("%s: vlan must be between 1 and 4095", ctx->argv[0]);
813 parent = find_bridge(&info, parent_name, false);
814 if (parent && parent->vlan) {
815 vsctl_fatal("cannot create bridge with fake bridge as parent");
818 vsctl_fatal("parent bridge %s does not exist", parent_name);
822 iface = ovsrec_interface_insert(ctx->txn);
823 ovsrec_interface_set_name(iface, br_name);
824 ovsrec_interface_set_type(iface, "internal");
826 port = ovsrec_port_insert(ctx->txn);
827 ovsrec_port_set_name(port, br_name);
828 ovsrec_port_set_interfaces(port, &iface, 1);
829 ovsrec_port_set_fake_bridge(port, true);
830 ovsrec_port_set_tag(port, &tag, 1);
832 bridge_insert_port(br, port);
841 del_port(struct vsctl_info *info, struct vsctl_port *port)
843 struct shash_node *node;
845 SHASH_FOR_EACH (node, &info->ifaces) {
846 struct vsctl_iface *iface = node->data;
847 if (iface->port == port) {
848 ovsrec_interface_delete(iface->iface_cfg);
851 ovsrec_port_delete(port->port_cfg);
853 bridge_delete_port((port->bridge->parent
854 ? port->bridge->parent->br_cfg
855 : port->bridge->br_cfg), port->port_cfg);
859 cmd_del_br(struct vsctl_context *ctx)
861 bool must_exist = !shash_find(&ctx->options, "--if-exists");
862 struct vsctl_bridge *bridge;
863 struct vsctl_info info;
865 get_info(ctx->ovs, &info);
866 bridge = find_bridge(&info, ctx->argv[1], must_exist);
868 struct shash_node *node;
870 SHASH_FOR_EACH (node, &info.ports) {
871 struct vsctl_port *port = node->data;
872 if (port->bridge == bridge
873 || !strcmp(port->port_cfg->name, bridge->name)) {
874 del_port(&info, port);
877 if (bridge->br_cfg) {
878 ovsrec_bridge_delete(bridge->br_cfg);
879 ovs_delete_bridge(ctx->ovs, bridge->br_cfg);
886 output_sorted(struct svec *svec, struct ds *output)
892 SVEC_FOR_EACH (i, name, svec) {
893 ds_put_format(output, "%s\n", name);
898 cmd_list_br(struct vsctl_context *ctx)
900 struct shash_node *node;
901 struct vsctl_info info;
904 get_info(ctx->ovs, &info);
907 SHASH_FOR_EACH (node, &info.bridges) {
908 struct vsctl_bridge *br = node->data;
909 svec_add(&bridges, br->name);
911 output_sorted(&bridges, &ctx->output);
912 svec_destroy(&bridges);
918 cmd_br_exists(struct vsctl_context *ctx)
920 struct vsctl_info info;
922 get_info(ctx->ovs, &info);
923 if (!find_bridge(&info, ctx->argv[1], false)) {
929 /* Returns true if 'b_prefix' (of length 'b_prefix_len') concatenated with 'b'
930 * equals 'a', false otherwise. */
932 key_matches(const char *a,
933 const char *b_prefix, size_t b_prefix_len, const char *b)
935 return !strncmp(a, b_prefix, b_prefix_len) && !strcmp(a + b_prefix_len, b);
939 set_external_id(char **old_keys, char **old_values, size_t old_n,
940 char *key, char *value,
941 char ***new_keysp, char ***new_valuesp, size_t *new_np)
948 new_keys = xmalloc(sizeof *new_keys * (old_n + 1));
949 new_values = xmalloc(sizeof *new_values * (old_n + 1));
951 for (i = 0; i < old_n; i++) {
952 if (strcmp(key, old_keys[i])) {
953 new_keys[new_n] = old_keys[i];
954 new_values[new_n] = old_values[i];
959 new_keys[new_n] = key;
960 new_values[new_n] = value;
963 *new_keysp = new_keys;
964 *new_valuesp = new_values;
969 cmd_br_set_external_id(struct vsctl_context *ctx)
971 struct vsctl_info info;
972 struct vsctl_bridge *bridge;
973 char **keys, **values;
976 get_info(ctx->ovs, &info);
977 bridge = find_bridge(&info, ctx->argv[1], true);
978 if (bridge->br_cfg) {
979 set_external_id(bridge->br_cfg->key_external_ids,
980 bridge->br_cfg->value_external_ids,
981 bridge->br_cfg->n_external_ids,
982 ctx->argv[2], ctx->argc >= 4 ? ctx->argv[3] : NULL,
984 ovsrec_bridge_set_external_ids(bridge->br_cfg, keys, values, n);
986 char *key = xasprintf("fake-bridge-%s", ctx->argv[2]);
987 struct vsctl_port *port = shash_find_data(&info.ports, ctx->argv[1]);
988 set_external_id(port->port_cfg->key_external_ids,
989 port->port_cfg->value_external_ids,
990 port->port_cfg->n_external_ids,
991 key, ctx->argc >= 4 ? ctx->argv[3] : NULL,
993 ovsrec_port_set_external_ids(port->port_cfg, keys, values, n);
1003 get_external_id(char **keys, char **values, size_t n,
1004 const char *prefix, const char *key,
1007 size_t prefix_len = strlen(prefix);
1012 for (i = 0; i < n; i++) {
1013 if (!key && !strncmp(keys[i], prefix, prefix_len)) {
1014 svec_add_nocopy(&svec, xasprintf("%s=%s",
1015 keys[i] + prefix_len, values[i]));
1016 } else if (key_matches(keys[i], prefix, prefix_len, key)) {
1017 svec_add(&svec, values[i]);
1021 output_sorted(&svec, output);
1022 svec_destroy(&svec);
1026 cmd_br_get_external_id(struct vsctl_context *ctx)
1028 struct vsctl_info info;
1029 struct vsctl_bridge *bridge;
1031 get_info(ctx->ovs, &info);
1032 bridge = find_bridge(&info, ctx->argv[1], true);
1033 if (bridge->br_cfg) {
1034 get_external_id(bridge->br_cfg->key_external_ids,
1035 bridge->br_cfg->value_external_ids,
1036 bridge->br_cfg->n_external_ids,
1037 "", ctx->argc >= 3 ? ctx->argv[2] : NULL,
1040 struct vsctl_port *port = shash_find_data(&info.ports, ctx->argv[1]);
1041 get_external_id(port->port_cfg->key_external_ids,
1042 port->port_cfg->value_external_ids,
1043 port->port_cfg->n_external_ids,
1044 "fake-bridge-", ctx->argc >= 3 ? ctx->argv[2] : NULL, &ctx->output);
1051 cmd_list_ports(struct vsctl_context *ctx)
1053 struct vsctl_bridge *br;
1054 struct shash_node *node;
1055 struct vsctl_info info;
1058 get_info(ctx->ovs, &info);
1059 br = find_bridge(&info, ctx->argv[1], true);
1062 SHASH_FOR_EACH (node, &info.ports) {
1063 struct vsctl_port *port = node->data;
1065 if (strcmp(port->port_cfg->name, br->name) && br == port->bridge) {
1066 svec_add(&ports, port->port_cfg->name);
1069 output_sorted(&ports, &ctx->output);
1070 svec_destroy(&ports);
1076 add_port(struct vsctl_context *ctx,
1077 const char *br_name, const char *port_name, bool fake_iface,
1078 char *iface_names[], int n_ifaces)
1080 struct vsctl_info info;
1081 struct vsctl_bridge *bridge;
1082 struct ovsrec_interface **ifaces;
1083 struct ovsrec_port *port;
1086 get_info(ctx->ovs, &info);
1087 check_conflicts(&info, port_name,
1088 xasprintf("cannot create a port named %s", port_name));
1089 /* XXX need to check for conflicts on interfaces too */
1090 bridge = find_bridge(&info, br_name, true);
1092 ifaces = xmalloc(n_ifaces * sizeof *ifaces);
1093 for (i = 0; i < n_ifaces; i++) {
1094 ifaces[i] = ovsrec_interface_insert(ctx->txn);
1095 ovsrec_interface_set_name(ifaces[i], iface_names[i]);
1098 port = ovsrec_port_insert(ctx->txn);
1099 ovsrec_port_set_name(port, port_name);
1100 ovsrec_port_set_interfaces(port, ifaces, n_ifaces);
1101 ovsrec_port_set_bond_fake_iface(port, fake_iface);
1105 int64_t tag = bridge->vlan;
1106 ovsrec_port_set_tag(port, &tag, 1);
1109 bridge_insert_port((bridge->parent ? bridge->parent->br_cfg
1110 : bridge->br_cfg), port);
1116 cmd_add_port(struct vsctl_context *ctx)
1118 add_port(ctx, ctx->argv[1], ctx->argv[2], false, &ctx->argv[2], 1);
1122 cmd_add_bond(struct vsctl_context *ctx)
1124 bool fake_iface = shash_find(&ctx->options, "--fake-iface");
1126 add_port(ctx, ctx->argv[1], ctx->argv[2], fake_iface,
1127 &ctx->argv[3], ctx->argc - 3);
1131 cmd_del_port(struct vsctl_context *ctx)
1133 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1134 struct vsctl_info info;
1136 get_info(ctx->ovs, &info);
1137 if (ctx->argc == 2) {
1138 struct vsctl_port *port = find_port(&info, ctx->argv[1], must_exist);
1140 del_port(&info, port);
1142 } else if (ctx->argc == 3) {
1143 struct vsctl_bridge *bridge = find_bridge(&info, ctx->argv[1], true);
1144 struct vsctl_port *port = find_port(&info, ctx->argv[2], must_exist);
1147 if (port->bridge == bridge) {
1148 del_port(&info, port);
1149 } else if (port->bridge->parent == bridge) {
1150 vsctl_fatal("bridge %s does not have a port %s (although its "
1151 "parent bridge %s does)",
1152 ctx->argv[1], ctx->argv[2], bridge->parent->name);
1154 vsctl_fatal("bridge %s does not have a port %s",
1155 ctx->argv[1], ctx->argv[2]);
1163 cmd_port_to_br(struct vsctl_context *ctx)
1165 struct vsctl_port *port;
1166 struct vsctl_info info;
1168 get_info(ctx->ovs, &info);
1169 port = find_port(&info, ctx->argv[1], true);
1170 ds_put_format(&ctx->output, "%s\n", port->bridge->name);
1175 cmd_br_to_vlan(struct vsctl_context *ctx)
1177 struct vsctl_bridge *bridge;
1178 struct vsctl_info info;
1180 get_info(ctx->ovs, &info);
1181 bridge = find_bridge(&info, ctx->argv[1], true);
1182 ds_put_format(&ctx->output, "%d\n", bridge->vlan);
1187 cmd_br_to_parent(struct vsctl_context *ctx)
1189 struct vsctl_bridge *bridge;
1190 struct vsctl_info info;
1192 get_info(ctx->ovs, &info);
1193 bridge = find_bridge(&info, ctx->argv[1], true);
1194 if (bridge->parent) {
1195 bridge = bridge->parent;
1197 ds_put_format(&ctx->output, "%s\n", bridge->name);
1202 cmd_list_ifaces(struct vsctl_context *ctx)
1204 struct vsctl_bridge *br;
1205 struct shash_node *node;
1206 struct vsctl_info info;
1209 get_info(ctx->ovs, &info);
1210 br = find_bridge(&info, ctx->argv[1], true);
1213 SHASH_FOR_EACH (node, &info.ifaces) {
1214 struct vsctl_iface *iface = node->data;
1216 if (strcmp(iface->iface_cfg->name, br->name)
1217 && br == iface->port->bridge) {
1218 svec_add(&ifaces, iface->iface_cfg->name);
1221 output_sorted(&ifaces, &ctx->output);
1222 svec_destroy(&ifaces);
1228 cmd_iface_to_br(struct vsctl_context *ctx)
1230 struct vsctl_iface *iface;
1231 struct vsctl_info info;
1233 get_info(ctx->ovs, &info);
1234 iface = find_iface(&info, ctx->argv[1], true);
1235 ds_put_format(&ctx->output, "%s\n", iface->port->bridge->name);
1240 cmd_get_controller(struct vsctl_context *ctx)
1242 struct vsctl_info info;
1244 get_info(ctx->ovs, &info);
1246 if (ctx->argc == 1) {
1247 /* Return the controller from the "Open_vSwitch" table */
1249 ds_put_format(&ctx->output, "%s\n", info.ctrl->target);
1252 /* Return the controller for a particular bridge. */
1253 struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true);
1255 /* If no controller is explicitly defined for the requested
1256 * bridge, fallback to the "Open_vSwitch" table's controller. */
1258 ds_put_format(&ctx->output, "%s\n", br->ctrl->target);
1259 } else if (info.ctrl) {
1260 ds_put_format(&ctx->output, "%s\n", info.ctrl->target);
1268 cmd_del_controller(struct vsctl_context *ctx)
1270 struct vsctl_info info;
1272 get_info(ctx->ovs, &info);
1274 if (ctx->argc == 1) {
1276 ovsrec_controller_delete(info.ctrl);
1277 ovsrec_open_vswitch_set_controller(ctx->ovs, NULL);
1280 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1283 ovsrec_controller_delete(br->ctrl);
1284 ovsrec_bridge_set_controller(br->br_cfg, NULL);
1292 cmd_set_controller(struct vsctl_context *ctx)
1294 struct vsctl_info info;
1295 struct ovsrec_controller *ctrl;
1297 get_info(ctx->ovs, &info);
1299 if (ctx->argc == 2) {
1300 /* Set the controller in the "Open_vSwitch" table. */
1302 ovsrec_controller_delete(info.ctrl);
1304 ctrl = ovsrec_controller_insert(ctx->txn);
1305 ovsrec_controller_set_target(ctrl, ctx->argv[1]);
1306 ovsrec_open_vswitch_set_controller(ctx->ovs, ctrl);
1308 /* Set the controller for a particular bridge. */
1309 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1312 ovsrec_controller_delete(br->ctrl);
1314 ctrl = ovsrec_controller_insert(ctx->txn);
1315 ovsrec_controller_set_target(ctrl, ctx->argv[2]);
1316 ovsrec_bridge_set_controller(br->br_cfg, ctrl);
1323 cmd_get_fail_mode(struct vsctl_context *ctx)
1325 struct vsctl_info info;
1326 const char *fail_mode = NULL;
1328 get_info(ctx->ovs, &info);
1330 if (ctx->argc == 1) {
1331 /* Return the fail-mode from the "Open_vSwitch" table */
1332 if (info.ctrl && info.ctrl->fail_mode) {
1333 fail_mode = info.ctrl->fail_mode;
1336 /* Return the fail-mode for a particular bridge. */
1337 struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true);
1339 /* If no controller or fail-mode is explicitly defined for the
1340 * requested bridge, fallback to the "Open_vSwitch" table's
1342 if (br->ctrl && br->ctrl->fail_mode) {
1343 fail_mode = br->ctrl->fail_mode;
1344 } else if (info.ctrl && info.ctrl->fail_mode) {
1345 fail_mode = info.ctrl->fail_mode;
1349 if (fail_mode && strlen(fail_mode)) {
1350 ds_put_format(&ctx->output, "%s\n", fail_mode);
1357 cmd_del_fail_mode(struct vsctl_context *ctx)
1359 struct vsctl_info info;
1361 get_info(ctx->ovs, &info);
1363 if (ctx->argc == 1) {
1364 if (info.ctrl && info.ctrl->fail_mode) {
1365 ovsrec_controller_set_fail_mode(info.ctrl, NULL);
1368 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1370 if (br->ctrl && br->ctrl->fail_mode) {
1371 ovsrec_controller_set_fail_mode(br->ctrl, NULL);
1379 cmd_set_fail_mode(struct vsctl_context *ctx)
1381 struct vsctl_info info;
1382 const char *fail_mode;
1384 get_info(ctx->ovs, &info);
1386 fail_mode = (ctx->argc == 2) ? ctx->argv[1] : ctx->argv[2];
1388 if (strcmp(fail_mode, "standalone") && strcmp(fail_mode, "secure")) {
1389 vsctl_fatal("fail-mode must be \"standalone\" or \"secure\"");
1392 if (ctx->argc == 2) {
1393 /* Set the fail-mode in the "Open_vSwitch" table. */
1395 vsctl_fatal("no controller declared");
1397 ovsrec_controller_set_fail_mode(info.ctrl, fail_mode);
1399 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1402 vsctl_fatal("no controller declared for %s", br->name);
1404 ovsrec_controller_set_fail_mode(br->ctrl, fail_mode);
1411 cmd_get_ssl(struct vsctl_context *ctx)
1413 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1416 ds_put_format(&ctx->output, "Private key: %s\n", ssl->private_key);
1417 ds_put_format(&ctx->output, "Certificate: %s\n", ssl->certificate);
1418 ds_put_format(&ctx->output, "CA Certificate: %s\n", ssl->ca_cert);
1419 ds_put_format(&ctx->output, "Bootstrap: %s\n",
1420 ssl->bootstrap_ca_cert ? "true" : "false");
1425 cmd_del_ssl(struct vsctl_context *ctx)
1427 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1430 ovsrec_ssl_delete(ssl);
1431 ovsrec_open_vswitch_set_ssl(ctx->ovs, NULL);
1436 cmd_set_ssl(struct vsctl_context *ctx)
1438 bool bootstrap = shash_find(&ctx->options, "--bootstrap");
1439 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1442 ovsrec_ssl_delete(ssl);
1444 ssl = ovsrec_ssl_insert(ctx->txn);
1446 ovsrec_ssl_set_private_key(ssl, ctx->argv[1]);
1447 ovsrec_ssl_set_certificate(ssl, ctx->argv[2]);
1448 ovsrec_ssl_set_ca_cert(ssl, ctx->argv[3]);
1450 ovsrec_ssl_set_bootstrap_ca_cert(ssl, bootstrap);
1452 ovsrec_open_vswitch_set_ssl(ctx->ovs, ssl);
1455 /* Parameter commands. */
1457 /* POSIX extended regular expression for an 8-bit unsigned decimal integer. */
1458 #define OCTET_RE "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
1460 /* POSIX extended regular expression for an IP address. */
1461 #define IP_RE "("OCTET_RE"\\."OCTET_RE"\\."OCTET_RE"\\."OCTET_RE")"
1463 /* POSIX extended regular expression for a netmask. */
1464 #define NETMASK_RE \
1465 "255.255.255."NETMASK_END_RE"|" \
1466 "255.255."NETMASK_END_RE".0|" \
1467 "255."NETMASK_END_RE".0.0|" \
1468 NETMASK_END_RE".0.0.0"
1469 #define NETMASK_END_RE "(255|254|252|248|240|224|192|128|0)"
1471 /* POSIX extended regular expression for an Ethernet address. */
1472 #define XX_RE "[0-9a-fA-F][0-9a-fA-F]"
1473 #define MAC_RE XX_RE":"XX_RE":"XX_RE":"XX_RE":"XX_RE":"XX_RE
1475 /* POSIX extended regular expression for a TCP or UDP port number. */
1479 "[1-9][0-9][0-9]|" \
1480 "[1-9][0-9][0-9][0-9]|" \
1481 "[1-5][0-9][0-9][0-9][0-9]|" \
1482 "6[1-4][0-9][0-9][0-9]|" \
1483 "65[1-4][0-9][0-9]|" \
1488 VSCF_READONLY = 1 << 0,
1489 VSCF_HIDDEN = 1 << 1
1492 struct vsctl_column {
1493 struct ovsdb_idl_column *idl;
1495 const char *constraint;
1498 static const struct vsctl_column bridge_columns[] = {
1499 {&ovsrec_bridge_col_controller, VSCF_READONLY, NULL},
1500 {&ovsrec_bridge_col_datapath_id, VSCF_READONLY, NULL},
1501 {&ovsrec_bridge_col_datapath_type, VSCF_READONLY, NULL},
1502 {&ovsrec_bridge_col_external_ids, 0, NULL},
1503 {&ovsrec_bridge_col_flood_vlans, 0, "[1,4095]"},
1504 {&ovsrec_bridge_col_mirrors, VSCF_READONLY, NULL},
1505 {&ovsrec_bridge_col_name, VSCF_READONLY, NULL},
1506 {&ovsrec_bridge_col_netflow, VSCF_READONLY, NULL},
1507 {&ovsrec_bridge_col_other_config, 0, NULL},
1508 {&ovsrec_bridge_col_ports, VSCF_READONLY, NULL},
1512 static const struct vsctl_column controller_columns[] = {
1513 {&ovsrec_controller_col_connection_mode, 0, "in-band|out-of-band"},
1514 {&ovsrec_controller_col_controller_burst_limit, 0, "[25,]"},
1515 {&ovsrec_controller_col_controller_rate_limit, 0, "[100,]"},
1516 {&ovsrec_controller_col_discover_accept_regex, 0, NULL},
1517 {&ovsrec_controller_col_discover_update_resolv_conf, 0, NULL},
1518 {&ovsrec_controller_col_fail_mode, 0, "standalone|secure"},
1519 {&ovsrec_controller_col_inactivity_probe, 0, "[5000,]"},
1520 {&ovsrec_controller_col_local_gateway, 0, IP_RE},
1521 {&ovsrec_controller_col_local_ip, 0, IP_RE},
1522 {&ovsrec_controller_col_local_netmask, 0, NETMASK_RE},
1523 {&ovsrec_controller_col_max_backoff, 0, "[1000,]"},
1524 {&ovsrec_controller_col_target, 0, NULL},
1528 static const struct vsctl_column interface_columns[] = {
1529 {&ovsrec_interface_col_external_ids, 0, NULL},
1530 {&ovsrec_interface_col_ingress_policing_burst, 0, "[10,]"},
1531 {&ovsrec_interface_col_ingress_policing_rate, 0, "[100,]"},
1532 {&ovsrec_interface_col_mac, 0, MAC_RE},
1533 {&ovsrec_interface_col_name, VSCF_READONLY, NULL},
1534 {&ovsrec_interface_col_ofport, VSCF_READONLY, NULL},
1535 {&ovsrec_interface_col_options, 0, NULL},
1536 {&ovsrec_interface_col_type, VSCF_READONLY, NULL},
1540 static const struct vsctl_column mirror_columns[] = {
1541 {&ovsrec_mirror_col_name, VSCF_READONLY, NULL},
1542 {&ovsrec_mirror_col_output_port, 0, "Port"},
1543 {&ovsrec_mirror_col_output_vlan, 0, "[1,4095]"},
1544 {&ovsrec_mirror_col_select_dst_port, 0, "Port"},
1545 {&ovsrec_mirror_col_select_src_port, 0, "Port"},
1546 {&ovsrec_mirror_col_select_vlan, 0, "[1,4095]"},
1550 static const struct vsctl_column netflow_columns[] = {
1551 {&ovsrec_netflow_col_active_timeout, 0, "[-1,]"},
1552 {&ovsrec_netflow_col_add_id_to_interface, 0, NULL},
1553 {&ovsrec_netflow_col_engine_id, 0, "[0,255]"},
1554 {&ovsrec_netflow_col_engine_type, 0, "[0,255]"},
1555 {&ovsrec_netflow_col_targets, 0, IP_RE":"PORT_RE},
1559 static const struct vsctl_column open_vswitch_columns[] = {
1560 {&ovsrec_open_vswitch_col_bridges, VSCF_READONLY, NULL},
1561 {&ovsrec_open_vswitch_col_controller, VSCF_READONLY, NULL},
1562 {&ovsrec_open_vswitch_col_cur_cfg, VSCF_HIDDEN, NULL},
1563 {&ovsrec_open_vswitch_col_management_id, 0, "[0-9a-fA-F]{12}"},
1564 {&ovsrec_open_vswitch_col_managers, 0, "p?(ssl|tcp|unix):.*"},
1565 {&ovsrec_open_vswitch_col_next_cfg, VSCF_HIDDEN, NULL},
1566 {&ovsrec_open_vswitch_col_ssl, VSCF_READONLY, NULL},
1570 static const struct vsctl_column port_columns[] = {
1571 {&ovsrec_port_col_bond_downdelay, 0, "[0,]"},
1572 {&ovsrec_port_col_bond_fake_iface, VSCF_READONLY, NULL},
1573 {&ovsrec_port_col_bond_updelay, 0, "[0,]"},
1574 {&ovsrec_port_col_external_ids, 0, NULL},
1575 {&ovsrec_port_col_fake_bridge, VSCF_READONLY, NULL},
1576 {&ovsrec_port_col_interfaces, VSCF_READONLY, NULL},
1577 {&ovsrec_port_col_mac, 0, MAC_RE},
1578 {&ovsrec_port_col_name, VSCF_READONLY, NULL},
1579 {&ovsrec_port_col_other_config, 0, NULL},
1580 {&ovsrec_port_col_tag, 0, "[0,4095]"},
1581 {&ovsrec_port_col_trunks, 0, "[0,4095]"},
1585 static const struct vsctl_column ssl_columns[] = {
1586 {&ovsrec_ssl_col_bootstrap_ca_cert, 0, NULL},
1587 {&ovsrec_ssl_col_ca_cert, 0, NULL},
1588 {&ovsrec_ssl_col_certificate, 0, NULL},
1589 {&ovsrec_ssl_col_private_key, 0, NULL},
1593 struct vsctl_row_id {
1594 const struct ovsdb_idl_table_class *table;
1595 const struct ovsdb_idl_column *name_column;
1596 const struct ovsdb_idl_column *uuid_column;
1599 struct vsctl_table_class {
1600 struct ovsdb_idl_table_class *class;
1601 const struct vsctl_column *columns;
1602 struct vsctl_row_id row_ids[2];
1605 static const struct vsctl_table_class tables[] = {
1606 {&ovsrec_table_bridge, bridge_columns,
1607 {{&ovsrec_table_bridge, &ovsrec_bridge_col_name, NULL},
1608 {NULL, NULL, NULL}}},
1610 {&ovsrec_table_controller, controller_columns,
1611 {{&ovsrec_table_bridge,
1612 &ovsrec_bridge_col_name,
1613 &ovsrec_bridge_col_controller},
1614 {&ovsrec_table_open_vswitch,
1616 &ovsrec_open_vswitch_col_controller}}},
1618 {&ovsrec_table_interface, interface_columns,
1619 {{&ovsrec_table_interface, &ovsrec_interface_col_name, NULL},
1620 {NULL, NULL, NULL}}},
1622 {&ovsrec_table_mirror, mirror_columns,
1623 {{&ovsrec_table_mirror, &ovsrec_mirror_col_name, NULL},
1624 {NULL, NULL, NULL}}},
1626 {&ovsrec_table_netflow, netflow_columns,
1627 {{&ovsrec_table_bridge,
1628 &ovsrec_bridge_col_name,
1629 &ovsrec_bridge_col_netflow},
1630 {NULL, NULL, NULL}}},
1632 {&ovsrec_table_open_vswitch, open_vswitch_columns,
1633 {{&ovsrec_table_open_vswitch, NULL, NULL},
1634 {NULL, NULL, NULL}}},
1636 {&ovsrec_table_port, port_columns,
1637 {{&ovsrec_table_port, &ovsrec_port_col_name, NULL},
1638 {NULL, NULL, NULL}}},
1640 {&ovsrec_table_ssl, ssl_columns,
1641 {{&ovsrec_table_open_vswitch, NULL, &ovsrec_open_vswitch_col_ssl}}},
1643 {NULL, NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}
1647 die_if_error(char *error)
1650 ovs_fatal(0, "%s", error);
1655 to_lower_and_underscores(unsigned c)
1657 return c == '-' ? '_' : tolower(c);
1661 score_partial_match(const char *name, const char *s)
1665 if (!strcmp(name, s)) {
1668 for (score = 0; ; score++, name++, s++) {
1669 if (to_lower_and_underscores(*name) != to_lower_and_underscores(*s)) {
1671 } else if (*name == '\0') {
1672 return UINT_MAX - 1;
1675 return *s == '\0' ? score : 0;
1678 static const struct vsctl_table_class *
1679 get_table(const char *table_name)
1681 const struct vsctl_table_class *table;
1682 const struct vsctl_table_class *best_match = NULL;
1683 unsigned int best_score = 0;
1685 for (table = tables; table->class; table++) {
1686 unsigned int score = score_partial_match(table->class->name,
1688 if (score > best_score) {
1691 } else if (score == best_score) {
1697 } else if (best_score) {
1698 ovs_fatal(0, "multiple table names match \"%s\"", table_name);
1700 ovs_fatal(0, "unknown table \"%s\"", table_name);
1704 static const struct ovsdb_idl_row *
1705 get_row_by_id(struct vsctl_context *ctx, const struct vsctl_table_class *table,
1706 const struct vsctl_row_id *id, const char *record_id)
1708 const struct ovsdb_idl_row *referrer, *final;
1714 if (!id->name_column) {
1715 if (strcmp(record_id, ".")) {
1718 referrer = ovsdb_idl_first_row(ctx->idl, id->table);
1719 if (!referrer || ovsdb_idl_next_row(referrer)) {
1723 const struct ovsdb_idl_row *row;
1724 unsigned int best_score = 0;
1726 /* It might make sense to relax this assertion. */
1727 assert(id->name_column->type.key_type == OVSDB_TYPE_STRING);
1730 for (row = ovsdb_idl_first_row(ctx->idl, id->table);
1731 row != NULL && best_score != UINT_MAX;
1732 row = ovsdb_idl_next_row(row))
1734 struct ovsdb_datum name;
1736 ovsdb_idl_txn_read(row, id->name_column, &name);
1738 unsigned int score = score_partial_match(name.keys[0].string,
1740 if (score > best_score) {
1743 } else if (score == best_score) {
1747 ovsdb_datum_destroy(&name, &id->name_column->type);
1749 if (best_score && !referrer) {
1750 ovs_fatal(0, "multiple rows in %s match \"%s\"",
1751 table->class->name, record_id);
1759 if (id->uuid_column) {
1760 struct ovsdb_datum uuid;
1762 assert(id->uuid_column->type.key_type == OVSDB_TYPE_UUID);
1763 assert(id->uuid_column->type.value_type == OVSDB_TYPE_VOID);
1765 ovsdb_idl_txn_read(referrer, id->uuid_column, &uuid);
1767 final = ovsdb_idl_get_row_for_uuid(ctx->idl, table->class,
1768 &uuid.keys[0].uuid);
1770 ovsdb_datum_destroy(&uuid, &id->uuid_column->type);
1778 static const struct ovsdb_idl_row *
1779 get_row(struct vsctl_context *ctx,
1780 const struct vsctl_table_class *table, const char *record_id)
1782 const struct ovsdb_idl_row *row;
1785 if (uuid_from_string(&uuid, record_id)) {
1786 row = ovsdb_idl_get_row_for_uuid(ctx->idl, table->class, &uuid);
1790 for (i = 0; i < ARRAY_SIZE(table->row_ids); i++) {
1791 row = get_row_by_id(ctx, table, &table->row_ids[i], record_id);
1800 static const struct ovsdb_idl_row *
1801 must_get_row(struct vsctl_context *ctx,
1802 const struct vsctl_table_class *table, const char *record_id)
1804 const struct ovsdb_idl_row *row = get_row(ctx, table, record_id);
1806 ovs_fatal(0, "no row \"%s\" in table %s",
1807 record_id, table->class->name);
1813 get_column(const struct vsctl_table_class *table, const char *column_name,
1814 const struct vsctl_column **columnp)
1816 const struct vsctl_column *column;
1817 const struct vsctl_column *best_match = NULL;
1818 unsigned int best_score = 0;
1820 for (column = table->columns; column->idl; column++) {
1821 if (!(column->flags & VSCF_HIDDEN)) {
1822 unsigned int score = score_partial_match(column->idl->name,
1824 if (score > best_score) {
1825 best_match = column;
1827 } else if (score == best_score) {
1833 *columnp = best_match;
1836 } else if (best_score) {
1837 return xasprintf("%s contains more than one column whose name "
1838 "matches \"%s\"", table->class->name, column_name);
1840 return xasprintf("%s does not contain a column whose name matches "
1841 "\"%s\"", table->class->name, column_name);
1845 static char * WARN_UNUSED_RESULT
1846 parse_column_key_value(const char *arg, const struct vsctl_table_class *table,
1847 const struct vsctl_column **columnp,
1848 char **keyp, char **valuep)
1850 const char *p = arg;
1853 assert(columnp || keyp);
1861 /* Parse column name. */
1865 error = ovsdb_token_parse(&p, &column_name);
1869 if (column_name[0] == '\0') {
1871 error = xasprintf("%s: missing column name", arg);
1874 error = get_column(table, column_name, columnp);
1881 /* Parse key string. */
1882 if (*p == ':' || !columnp) {
1886 error = xasprintf("%s: key not accepted here", arg);
1889 error = ovsdb_token_parse(&p, keyp);
1897 /* Parse value string. */
1900 error = xasprintf("%s: value not accepted here", arg);
1903 *valuep = xstrdup(p + 1);
1909 error = xasprintf("%s: trailing garbage \"%s\" in argument",
1932 cmd_get(struct vsctl_context *ctx)
1934 bool if_exists = shash_find(&ctx->options, "--if-exists");
1935 const char *table_name = ctx->argv[1];
1936 const char *record_id = ctx->argv[2];
1937 const struct vsctl_table_class *table;
1938 const struct ovsdb_idl_row *row;
1939 struct ds *out = &ctx->output;
1942 table = get_table(table_name);
1943 row = must_get_row(ctx, table, record_id);
1944 for (i = 3; i < ctx->argc; i++) {
1945 const struct vsctl_column *column;
1946 struct ovsdb_datum datum;
1949 die_if_error(parse_column_key_value(ctx->argv[i], table,
1950 &column, &key_string, NULL));
1952 ovsdb_idl_txn_read(row, column->idl, &datum);
1954 union ovsdb_atom key;
1957 if (column->idl->type.value_type == OVSDB_TYPE_VOID) {
1958 ovs_fatal(0, "cannot specify key to get for non-map column %s",
1962 die_if_error(ovsdb_atom_from_string(&key,
1963 column->idl->type.key_type,
1966 idx = ovsdb_datum_find_key(&datum, &key,
1967 column->idl->type.key_type);
1968 if (idx == UINT_MAX) {
1970 ovs_fatal(0, "no key \"%s\" in %s record \"%s\" column %s",
1971 key_string, table->class->name, record_id,
1975 ovsdb_atom_to_string(&datum.values[idx],
1976 column->idl->type.value_type, out);
1978 ovsdb_atom_destroy(&key, column->idl->type.key_type);
1980 ovsdb_datum_to_string(&datum, &column->idl->type, out);
1982 ds_put_char(out, '\n');
1983 ovsdb_datum_destroy(&datum, &column->idl->type);
1990 list_record(const struct vsctl_table_class *table,
1991 const struct ovsdb_idl_row *row, struct ds *out)
1993 const struct vsctl_column *column;
1995 ds_put_format(out, "%-20s (RO): "UUID_FMT"\n", "_uuid",
1996 UUID_ARGS(&row->uuid));
1997 for (column = table->columns; column->idl; column++) {
1998 struct ovsdb_datum datum;
2000 if (column->flags & VSCF_HIDDEN) {
2004 ovsdb_idl_txn_read(row, column->idl, &datum);
2006 ds_put_format(out, "%-20s (%s): ", column->idl->name,
2007 column->flags & VSCF_READONLY ? "RO" : "RW");
2008 ovsdb_datum_to_string(&datum, &column->idl->type, out);
2009 ds_put_char(out, '\n');
2011 ovsdb_datum_destroy(&datum, &column->idl->type);
2016 cmd_list(struct vsctl_context *ctx)
2018 const char *table_name = ctx->argv[1];
2019 const struct vsctl_table_class *table;
2020 struct ds *out = &ctx->output;
2023 table = get_table(table_name);
2024 if (ctx->argc > 2) {
2025 for (i = 2; i < ctx->argc; i++) {
2027 ds_put_char(out, '\n');
2029 list_record(table, must_get_row(ctx, table, ctx->argv[i]), out);
2032 const struct ovsdb_idl_row *row;
2035 for (row = ovsdb_idl_first_row(ctx->idl, table->class), first = true;
2037 row = ovsdb_idl_next_row(row), first = false) {
2039 ds_put_char(out, '\n');
2041 list_record(table, row, out);
2047 check_string_constraint(const struct ovsdb_datum *datum,
2048 const char *constraint)
2055 regex = xasprintf("^%s$", constraint);
2056 retval = regcomp(&re, regex, REG_NOSUB | REG_EXTENDED);
2058 size_t length = regerror(retval, &re, NULL, 0);
2059 char *buffer = xmalloc(length);
2060 regerror(retval, &re, buffer, length);
2061 ovs_fatal(0, "internal error compiling regular expression %s: %s",
2065 for (i = 0; i < datum->n; i++) {
2066 const char *key = datum->keys[i].string;
2067 if (regexec(&re, key, 0, NULL, 0)) {
2068 ovs_fatal(0, "%s is not valid (it does not match %s)", key, regex);
2076 check_integer_constraint(const struct ovsdb_datum *datum,
2077 const char *constraint)
2083 sscanf(constraint, "[%"SCNd64",%"SCNd64"]%n", &min, &max, &n);
2085 sscanf(constraint, "[%"SCNd64",]%n", &min, &n);
2087 sscanf(constraint, "[,%"SCNd64"]%n", &max, &n);
2089 VLOG_DBG("internal error: bad integer contraint \"%s\"",
2100 for (i = 0; i < datum->n; i++) {
2101 int64_t value = datum->keys[i].integer;
2102 if (value < min || value > max) {
2103 if (max == INT64_MAX) {
2104 ovs_fatal(0, "%"PRId64" is less than the minimum "
2105 "allowed value %"PRId64, value, min);
2106 } else if (min == INT64_MIN) {
2107 ovs_fatal(0, "%"PRId64" is greater than the maximum "
2108 "allowed value %"PRId64, value, max);
2110 ovs_fatal(0, "%"PRId64" is outside the valid range %"PRId64" "
2111 "to %"PRId64" (inclusive)", value, min, max);
2118 check_constraint(const struct ovsdb_datum *datum,
2119 const struct ovsdb_type *type, const char *constraint)
2121 if (constraint && datum->n) {
2122 if (type->key_type == OVSDB_TYPE_STRING) {
2123 check_string_constraint(datum, constraint);
2124 } else if (type->key_type == OVSDB_TYPE_INTEGER) {
2125 check_integer_constraint(datum, constraint);
2131 set_column(const struct vsctl_table_class *table,
2132 const struct ovsdb_idl_row *row,
2133 const char *arg, bool force)
2135 const struct vsctl_column *column;
2136 char *key_string, *value_string;
2139 error = parse_column_key_value(arg, table, &column, &key_string,
2141 die_if_error(error);
2142 if (column->flags & VSCF_READONLY && !force) {
2143 ovs_fatal(0, "%s: cannot modify read-only column %s in table %s",
2144 arg, column->idl->name, table->class->name);
2146 if (!value_string) {
2147 ovs_fatal(0, "%s: missing value", arg);
2151 union ovsdb_atom key, value;
2152 struct ovsdb_datum old, new;
2154 if (column->idl->type.value_type == OVSDB_TYPE_VOID) {
2155 ovs_fatal(0, "cannot specify key to set for non-map column %s",
2159 die_if_error(ovsdb_atom_from_string(&key,
2160 column->idl->type.key_type,
2162 die_if_error(ovsdb_atom_from_string(&value,
2163 column->idl->type.value_type,
2166 ovsdb_datum_init_empty(&new);
2167 ovsdb_datum_add_unsafe(&new, &key, &value, &column->idl->type);
2169 ovsdb_idl_txn_read(row, column->idl, &old);
2170 ovsdb_datum_union(&old, &new, &column->idl->type, true);
2171 ovsdb_idl_txn_write(row, column->idl, &old);
2173 ovsdb_datum_destroy(&new, &column->idl->type);
2175 struct ovsdb_datum datum;
2177 die_if_error(ovsdb_datum_from_string(&datum, &column->idl->type,
2180 check_constraint(&datum, &column->idl->type,
2181 column->constraint);
2183 ovsdb_idl_txn_write(row, column->idl, &datum);
2190 cmd_set(struct vsctl_context *ctx)
2192 bool force = shash_find(&ctx->options, "--force");
2193 const char *table_name = ctx->argv[1];
2194 const char *record_id = ctx->argv[2];
2195 const struct vsctl_table_class *table;
2196 const struct ovsdb_idl_row *row;
2199 table = get_table(table_name);
2200 row = must_get_row(ctx, table, record_id);
2201 for (i = 3; i < ctx->argc; i++) {
2202 set_column(table, row, ctx->argv[i], force);
2207 cmd_add(struct vsctl_context *ctx)
2209 bool force = shash_find(&ctx->options, "--force");
2210 const char *table_name = ctx->argv[1];
2211 const char *record_id = ctx->argv[2];
2212 const char *column_name = ctx->argv[3];
2213 const struct vsctl_table_class *table;
2214 const struct vsctl_column *column;
2215 const struct ovsdb_idl_row *row;
2216 const struct ovsdb_type *type;
2217 struct ovsdb_datum old;
2220 table = get_table(table_name);
2221 row = must_get_row(ctx, table, record_id);
2222 die_if_error(get_column(table, column_name, &column));
2223 if (column->flags & VSCF_READONLY && !force) {
2224 ovs_fatal(0, "cannot modify read-only column %s in table %s",
2225 column->idl->name, table->class->name);
2228 type = &column->idl->type;
2229 ovsdb_idl_txn_read(row, column->idl, &old);
2230 for (i = 4; i < ctx->argc; i++) {
2231 struct ovsdb_type add_type;
2232 struct ovsdb_datum add;
2236 add_type.n_max = UINT_MAX;
2237 die_if_error(ovsdb_datum_from_string(&add, &add_type, ctx->argv[i]));
2238 ovsdb_datum_union(&old, &add, type, false);
2239 ovsdb_datum_destroy(&add, type);
2241 if (old.n > type->n_max) {
2242 ovs_fatal(0, "\"add\" operation would put %u %s in column %s of "
2243 "table %s but the maximum number is %u",
2245 type->value_type == OVSDB_TYPE_VOID ? "values" : "pairs",
2246 column->idl->name, table->class->name, type->n_max);
2248 ovsdb_idl_txn_write(row, column->idl, &old);
2252 cmd_remove(struct vsctl_context *ctx)
2254 bool force = shash_find(&ctx->options, "--force");
2255 const char *table_name = ctx->argv[1];
2256 const char *record_id = ctx->argv[2];
2257 const char *column_name = ctx->argv[3];
2258 const struct vsctl_table_class *table;
2259 const struct vsctl_column *column;
2260 const struct ovsdb_idl_row *row;
2261 const struct ovsdb_type *type;
2262 struct ovsdb_datum old;
2265 table = get_table(table_name);
2266 row = must_get_row(ctx, table, record_id);
2267 die_if_error(get_column(table, column_name, &column));
2268 if (column->flags & VSCF_READONLY && !force) {
2269 ovs_fatal(0, "cannot modify read-only column %s in table %s",
2270 column->idl->name, table->class->name);
2273 type = &column->idl->type;
2274 ovsdb_idl_txn_read(row, column->idl, &old);
2275 for (i = 4; i < ctx->argc; i++) {
2276 struct ovsdb_type rm_type;
2277 struct ovsdb_datum rm;
2282 rm_type.n_max = UINT_MAX;
2283 error = ovsdb_datum_from_string(&rm, &rm_type, ctx->argv[i]);
2284 if (error && ovsdb_type_is_map(&rm_type)) {
2286 rm_type.value_type = OVSDB_TYPE_VOID;
2287 die_if_error(ovsdb_datum_from_string(&rm, &rm_type, ctx->argv[i]));
2289 ovsdb_datum_subtract(&old, type, &rm, &rm_type);
2290 ovsdb_datum_destroy(&rm, &rm_type);
2292 if (old.n < type->n_min) {
2293 ovs_fatal(0, "\"remove\" operation would put %u %s in column %s of "
2294 "table %s but the minimun number is %u",
2296 type->value_type == OVSDB_TYPE_VOID ? "values" : "pairs",
2297 column->idl->name, table->class->name, type->n_min);
2299 ovsdb_idl_txn_write(row, column->idl, &old);
2303 cmd_clear(struct vsctl_context *ctx)
2305 bool force = shash_find(&ctx->options, "--force");
2306 const char *table_name = ctx->argv[1];
2307 const char *record_id = ctx->argv[2];
2308 const struct vsctl_table_class *table;
2309 const struct ovsdb_idl_row *row;
2312 table = get_table(table_name);
2313 row = must_get_row(ctx, table, record_id);
2314 for (i = 3; i < ctx->argc; i++) {
2315 const struct vsctl_column *column;
2316 const struct ovsdb_type *type;
2317 struct ovsdb_datum datum;
2319 die_if_error(get_column(table, ctx->argv[i], &column));
2321 type = &column->idl->type;
2322 if (column->flags & VSCF_READONLY && !force) {
2323 ovs_fatal(0, "cannot modify read-only column %s in table %s",
2324 column->idl->name, table->class->name);
2325 } else if (type->n_min > 0) {
2326 ovs_fatal(0, "\"clear\" operation cannot be applied to column %s "
2327 "of table %s, which is not allowed to be empty",
2328 column->idl->name, table->class->name);
2331 ovsdb_datum_init_empty(&datum);
2332 ovsdb_idl_txn_write(row, column->idl, &datum);
2337 cmd_create(struct vsctl_context *ctx)
2339 bool force = shash_find(&ctx->options, "--force");
2340 const char *table_name = ctx->argv[1];
2341 const struct vsctl_table_class *table;
2342 const struct ovsdb_idl_row *row;
2346 ovs_fatal(0, "\"create\" requires --force");
2349 table = get_table(table_name);
2350 row = ovsdb_idl_txn_insert(ctx->txn, table->class);
2351 for (i = 2; i < ctx->argc; i++) {
2352 set_column(table, row, ctx->argv[i], force);
2354 ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(&row->uuid));
2357 /* This function may be used as the 'postprocess' function for commands that
2358 * insert new rows into the database. It expects that the command's 'run'
2359 * function prints the UUID reported by ovsdb_idl_txn_insert() as the command's
2360 * sole output. It replaces that output by the row's permanent UUID assigned
2361 * by the database server and appends a new-line.
2363 * Currently we use this only for "create", because the higher-level commands
2364 * are supposed to be independent of the actual structure of the vswitch
2367 post_create(struct vsctl_context *ctx)
2369 const struct uuid *real;
2372 uuid_from_string(&dummy, ds_cstr(&ctx->output));
2373 real = ovsdb_idl_txn_get_insert_uuid(ctx->txn, &dummy);
2375 ds_clear(&ctx->output);
2376 ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(real));
2378 ds_put_char(&ctx->output, '\n');
2382 cmd_destroy(struct vsctl_context *ctx)
2384 bool force = shash_find(&ctx->options, "--force");
2385 bool must_exist = !shash_find(&ctx->options, "--if-exists");
2386 const char *table_name = ctx->argv[1];
2387 const struct vsctl_table_class *table;
2391 ovs_fatal(0, "\"destroy\" requires --force");
2394 table = get_table(table_name);
2395 for (i = 2; i < ctx->argc; i++) {
2396 const struct ovsdb_idl_row *row;
2398 row = (must_exist ? must_get_row : get_row)(ctx, table, ctx->argv[i]);
2400 ovsdb_idl_txn_delete(row);
2405 static struct json *
2406 where_uuid_equals(const struct uuid *uuid)
2409 json_array_create_1(
2410 json_array_create_3(
2411 json_string_create("_uuid"),
2412 json_string_create("=="),
2413 json_array_create_2(
2414 json_string_create("uuid"),
2415 json_string_create_nocopy(
2416 xasprintf(UUID_FMT, UUID_ARGS(uuid))))));
2420 vsctl_context_init(struct vsctl_context *ctx, struct vsctl_command *command,
2421 struct ovsdb_idl *idl, struct ovsdb_idl_txn *txn,
2422 const struct ovsrec_open_vswitch *ovs)
2424 ctx->argc = command->argc;
2425 ctx->argv = command->argv;
2426 ctx->options = command->options;
2428 ds_swap(&ctx->output, &command->output);
2436 vsctl_context_done(struct vsctl_context *ctx, struct vsctl_command *command)
2438 ds_swap(&ctx->output, &command->output);
2442 do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
2443 struct ovsdb_idl *idl)
2445 struct ovsdb_idl_txn *txn;
2446 const struct ovsrec_open_vswitch *ovs;
2447 enum ovsdb_idl_txn_status status;
2448 struct vsctl_command *c;
2449 int64_t next_cfg = 0;
2452 txn = ovsdb_idl_txn_create(idl);
2454 ovsdb_idl_txn_set_dry_run(txn);
2457 comment = xasprintf("ovs-vsctl: %s", args);
2458 ovsdb_idl_txn_add_comment(txn, comment);
2461 ovs = ovsrec_open_vswitch_first(idl);
2463 /* XXX add verification that table is empty */
2464 ovs = ovsrec_open_vswitch_insert(txn);
2467 if (wait_for_reload) {
2468 struct json *where = where_uuid_equals(&ovs->header_.uuid);
2469 ovsdb_idl_txn_increment(txn, "Open_vSwitch", "next_cfg", where);
2470 json_destroy(where);
2473 for (c = commands; c < &commands[n_commands]; c++) {
2474 struct vsctl_context ctx;
2476 ds_init(&c->output);
2477 vsctl_context_init(&ctx, c, idl, txn, ovs);
2478 (c->syntax->run)(&ctx);
2479 vsctl_context_done(&ctx, c);
2482 while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) {
2484 ovsdb_idl_wait(idl);
2485 ovsdb_idl_txn_wait(txn);
2488 if (wait_for_reload && status == TXN_SUCCESS) {
2489 next_cfg = ovsdb_idl_txn_get_increment_new_value(txn);
2491 for (c = commands; c < &commands[n_commands]; c++) {
2492 if (c->syntax->postprocess) {
2493 struct vsctl_context ctx;
2495 vsctl_context_init(&ctx, c, idl, txn, ovs);
2496 (c->syntax->postprocess)(&ctx);
2497 vsctl_context_done(&ctx, c);
2500 ovsdb_idl_txn_destroy(txn);
2503 case TXN_INCOMPLETE:
2507 /* Should not happen--we never call ovsdb_idl_txn_abort(). */
2508 vsctl_fatal("transaction aborted");
2515 for (c = commands; c < &commands[n_commands]; c++) {
2516 ds_destroy(&c->output);
2521 vsctl_fatal("transaction error");
2527 for (c = commands; c < &commands[n_commands]; c++) {
2528 struct ds *ds = &c->output;
2533 for (j = 0; j < ds->length; j++) {
2534 int c = ds->string[j];
2537 fputs("\\n", stdout);
2541 fputs("\\\\", stdout);
2550 fputs(ds_cstr(ds), stdout);
2554 if (wait_for_reload && status != TXN_UNCHANGED) {
2556 const struct ovsrec_open_vswitch *ovs;
2559 OVSREC_OPEN_VSWITCH_FOR_EACH (ovs, idl) {
2560 if (ovs->cur_cfg >= next_cfg) {
2564 ovsdb_idl_wait(idl);
2573 static const struct vsctl_command_syntax all_commands[] = {
2574 /* Open vSwitch commands. */
2575 {"init", 0, 0, cmd_init, NULL, ""},
2577 /* Bridge commands. */
2578 {"add-br", 1, 3, cmd_add_br, NULL, ""},
2579 {"del-br", 1, 1, cmd_del_br, NULL, "--if-exists"},
2580 {"list-br", 0, 0, cmd_list_br, NULL, ""},
2581 {"br-exists", 1, 1, cmd_br_exists, NULL, ""},
2582 {"br-to-vlan", 1, 1, cmd_br_to_vlan, NULL, ""},
2583 {"br-to-parent", 1, 1, cmd_br_to_parent, NULL, ""},
2584 {"br-set-external-id", 2, 3, cmd_br_set_external_id, NULL, ""},
2585 {"br-get-external-id", 1, 2, cmd_br_get_external_id, NULL, ""},
2587 /* Port commands. */
2588 {"list-ports", 1, 1, cmd_list_ports, NULL, ""},
2589 {"add-port", 2, 2, cmd_add_port, NULL, ""},
2590 {"add-bond", 4, INT_MAX, cmd_add_bond, NULL, "--fake-iface"},
2591 {"del-port", 1, 2, cmd_del_port, NULL, "--if-exists"},
2592 {"port-to-br", 1, 1, cmd_port_to_br, NULL, ""},
2594 /* Interface commands. */
2595 {"list-ifaces", 1, 1, cmd_list_ifaces, NULL, ""},
2596 {"iface-to-br", 1, 1, cmd_iface_to_br, NULL, ""},
2598 /* Controller commands. */
2599 {"get-controller", 0, 1, cmd_get_controller, NULL, ""},
2600 {"del-controller", 0, 1, cmd_del_controller, NULL, ""},
2601 {"set-controller", 1, 2, cmd_set_controller, NULL, ""},
2602 {"get-fail-mode", 0, 1, cmd_get_fail_mode, NULL, ""},
2603 {"del-fail-mode", 0, 1, cmd_del_fail_mode, NULL, ""},
2604 {"set-fail-mode", 1, 2, cmd_set_fail_mode, NULL, ""},
2607 {"get-ssl", 0, 0, cmd_get_ssl, NULL, ""},
2608 {"del-ssl", 0, 0, cmd_del_ssl, NULL, ""},
2609 {"set-ssl", 3, 3, cmd_set_ssl, NULL, "--bootstrap"},
2611 /* Parameter commands. */
2612 {"get", 3, INT_MAX, cmd_get, NULL, "--if-exists"},
2613 {"list", 1, INT_MAX, cmd_list, NULL, ""},
2614 {"set", 3, INT_MAX, cmd_set, NULL, "--force"},
2615 {"add", 4, INT_MAX, cmd_add, NULL, "--force"},
2616 {"remove", 4, INT_MAX, cmd_remove, NULL, "--force"},
2617 {"clear", 3, INT_MAX, cmd_clear, NULL, "--force"},
2618 {"create", 2, INT_MAX, cmd_create, post_create, "--force"},
2619 {"destroy", 1, INT_MAX, cmd_destroy, NULL, "--force,--if-exists"},
2621 {NULL, 0, 0, NULL, NULL, NULL},