[ovs-dev] [PATCH 2/2] ovn: Add get/set-enabled to ovn-nbctl.
Russell Bryant
rbryant at redhat.com
Tue Jun 23 18:22:09 UTC 2015
This patch adds support for getting and setting the 'enabled' column
for logical ports using ovn-nbctl.
Signed-off-by: Russell Bryant <rbryant at redhat.com>
---
ovn/ovn-nbctl.8.xml | 13 ++++++++++++
ovn/ovn-nbctl.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/ovn/ovn-nbctl.8.xml b/ovn/ovn-nbctl.8.xml
index 0e89229..39ffb35 100644
--- a/ovn/ovn-nbctl.8.xml
+++ b/ovn/ovn-nbctl.8.xml
@@ -179,6 +179,19 @@
<code>down</code>.
</dd>
+ <dt><code>lport-set-enabled</code> <var>lport</var> <var>state</var></dt>
+ <dd>
+ Set the administrative state of <var>lport</var>, either <code>enabled</code>
+ or <code>disabled</code>. When a port is disabled, no traffic is allowed into
+ or out of the port.
+ </dd>
+
+ <dt><code>lport-get-enabled</code> <var>lport</var></dt>
+ <dd>
+ Prints the administrative state of <var>lport</var>, either <code>enabled</code>
+ or <code>disabled</code>.
+ </dd>
+
</dl>
<h1>Options</h1>
diff --git a/ovn/ovn-nbctl.c b/ovn/ovn-nbctl.c
index a8e5d08..6a35a1a 100644
--- a/ovn/ovn-nbctl.c
+++ b/ovn/ovn-nbctl.c
@@ -81,6 +81,11 @@ Logical port commands:\n\
set port security addresses for LPORT.\n\
lport-get-port-security LPORT get LPORT's port security addresses\n\
lport-get-up LPORT get state of LPORT ('up' or 'down')\n\
+ lport-set-enabled LPORT STATE\n\
+ set administrative state LPORT\n\
+ ('enabled' or 'disabled')\n\
+ lport-get-enabled LPORT get administrative state LPORT\n\
+ ('enabled' or 'disabled')\n\
\n\
Options:\n\
--db=DATABASE connect to DATABASE\n\
@@ -566,6 +571,46 @@ do_lport_get_up(struct ovs_cmdl_context *ctx)
printf("%s\n", (lport->up && *lport->up) ? "up" : "down");
}
+
+static void
+do_lport_set_enabled(struct ovs_cmdl_context *ctx)
+{
+ struct nbctl_context *nb_ctx = ctx->pvt;
+ const char *id = ctx->argv[1];
+ const char *state = ctx->argv[2];
+ const struct nbrec_logical_port *lport;
+
+ lport = lport_by_name_or_uuid(nb_ctx, id);
+ if (!lport) {
+ return;
+ }
+
+ if (!strcasecmp(state, "enabled")) {
+ bool enabled = true;
+ nbrec_logical_port_set_enabled(lport, &enabled, 1);
+ } else if (!strcasecmp(state, "disabled")) {
+ bool enabled = false;
+ nbrec_logical_port_set_enabled(lport, &enabled, 1);
+ } else {
+ VLOG_ERR("Invalid state '%s' provided to lport-set-enabled", state);
+ }
+}
+
+static void
+do_lport_get_enabled(struct ovs_cmdl_context *ctx)
+{
+ struct nbctl_context *nb_ctx = ctx->pvt;
+ const char *id = ctx->argv[1];
+ const struct nbrec_logical_port *lport;
+
+ lport = lport_by_name_or_uuid(nb_ctx, id);
+ if (!lport) {
+ return;
+ }
+
+ printf("%s\n",
+ (!lport->enabled || *lport->enabled) ? "enabled" : "disabled");
+}
static void
parse_options(int argc, char *argv[])
@@ -753,6 +798,20 @@ static const struct ovs_cmdl_command all_commands[] = {
.max_args = 1,
.handler = do_lport_get_up,
},
+ {
+ .name = "lport-set-enabled",
+ .usage = "LPORT STATE",
+ .min_args = 2,
+ .max_args = 2,
+ .handler = do_lport_set_enabled,
+ },
+ {
+ .name = "lport-get-enabled",
+ .usage = "LPORT",
+ .min_args = 1,
+ .max_args = 1,
+ .handler = do_lport_get_enabled,
+ },
{
/* sentinel */
--
2.4.3
More information about the dev
mailing list