From 18ee958b7bb33174327285562901de71ee4a5232 Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Fri, 30 Apr 2010 15:06:51 -0700 Subject: [PATCH] ovs-vsctl: Add emergency reset command Add the "emer-reset" command, which is used to clear the configuration of items likely to have been configured by the manager. This will leave the core networking configuration as it was. --- utilities/ovs-vsctl.8.in | 5 +++ utilities/ovs-vsctl.c | 84 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in index cd83d0a2..55ea3076 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -139,6 +139,11 @@ Any successful \fBovs\-vsctl\fR command automatically initializes the Open vSwitch database if it is empty. This command is provided to initialize the database without executing any other command. . +.IP "\fBemer\-reset\fR" +Reset the configuration into a clean state. This will clear the +configuration of items likely to have been configured by a manager. +The core networking configuration will be left as is. +. .SS "Bridge Commands" These commands examine and manipulate Open vSwitch bridges. . diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 091e6bc7..45c8194a 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -439,6 +439,9 @@ SSL commands:\n\ del-ssl delete the SSL configuration\n\ set-ssl PRIV-KEY CERT CA-CERT set the SSL configuration\n\ \n\ +Switch commands:\n\ + emer-reset reset switch to known good state\n\ +\n\ Database commands:\n\ list TBL [REC] list RECord (or all records) in TBL\n\ get TBL REC COL[:KEY] print values of COLumns in RECORD in TBL\n\ @@ -856,6 +859,84 @@ cmd_init(struct vsctl_context *ctx OVS_UNUSED) { } +static void +cmd_emer_reset(struct vsctl_context *ctx) +{ + const struct ovsdb_idl *idl = ctx->idl; + const struct ovsrec_bridge *br; + const struct ovsrec_port *port; + const struct ovsrec_interface *iface; + const struct ovsrec_mirror *mirror, *next_mirror; + const struct ovsrec_controller *ctrl, *next_ctrl; + const struct ovsrec_netflow *nf, *next_nf; + const struct ovsrec_ssl *ssl, *next_ssl; + const struct ovsrec_sflow *sflow, *next_sflow; + + + /* Reset the Open_vSwitch table. */ + ovsrec_open_vswitch_set_managers(ctx->ovs, NULL, 0); + ovsrec_open_vswitch_set_controller(ctx->ovs, NULL, 0); + ovsrec_open_vswitch_set_ssl(ctx->ovs, NULL); + + OVSREC_BRIDGE_FOR_EACH (br, idl) { + int i; + char *hw_key = "hwaddr"; + char *hw_val = NULL; + + ovsrec_bridge_set_controller(br, NULL, 0); + ovsrec_bridge_set_mirrors(br, NULL, 0); + ovsrec_bridge_set_netflow(br, NULL); + ovsrec_bridge_set_sflow(br, NULL); + ovsrec_bridge_set_flood_vlans(br, NULL, 0); + + /* We only want to save the "hwaddr" key from other_config. */ + for (i=0; i < br->n_other_config; i++) { + if (!strcmp(br->key_other_config[i], hw_key)) { + hw_val = br->value_other_config[i]; + break; + } + } + if (hw_val) { + char *val = xstrdup(hw_val); + ovsrec_bridge_set_other_config(br, &hw_key, &val, 1); + free(val); + } else { + ovsrec_bridge_set_other_config(br, NULL, NULL, 0); + } + } + + OVSREC_PORT_FOR_EACH (port, idl) { + ovsrec_port_set_other_config(port, NULL, NULL, 0); + } + + OVSREC_INTERFACE_FOR_EACH (iface, idl) { + /* xxx What do we do about gre/patch devices created by mgr? */ + + ovsrec_interface_set_ingress_policing_rate(iface, 0); + ovsrec_interface_set_ingress_policing_burst(iface, 0); + } + + OVSREC_MIRROR_FOR_EACH_SAFE (mirror, next_mirror, idl) { + ovsrec_mirror_delete(mirror); + } + + OVSREC_CONTROLLER_FOR_EACH_SAFE (ctrl, next_ctrl, idl) { + ovsrec_controller_delete(ctrl); + } + + OVSREC_NETFLOW_FOR_EACH_SAFE (nf, next_nf, idl) { + ovsrec_netflow_delete(nf); + } + + OVSREC_SSL_FOR_EACH_SAFE (ssl, next_ssl, idl) { + ovsrec_ssl_delete(ssl); + } + + OVSREC_SFLOW_FOR_EACH_SAFE (sflow, next_sflow, idl) { + ovsrec_sflow_delete(sflow); + } +} + static void cmd_add_br(struct vsctl_context *ctx) { @@ -2645,6 +2726,9 @@ static const struct vsctl_command_syntax all_commands[] = { {"del-ssl", 0, 0, cmd_del_ssl, NULL, ""}, {"set-ssl", 3, 3, cmd_set_ssl, NULL, "--bootstrap"}, + /* Switch commands. */ + {"emer-reset", 0, 0, cmd_emer_reset, NULL, ""}, + /* Parameter commands. */ {"get", 3, INT_MAX, cmd_get, NULL, "--if-exists"}, {"list", 1, INT_MAX, cmd_list, NULL, ""}, -- 2.30.2