[ovs-dev] [PATCHv2 1/2] ovs-vsctl: Add "--real" and "--fake" options to "list-br".

Justin Pettit jpettit at nicira.com
Sat Dec 1 19:20:35 UTC 2012


By default, "ovs-vsctl list-br" returns all bridges, real or fake.  This
commit adds "--real" and "--fake" options that limit the output to only
bridges of that type.  This will be useful in a future commit that needs
to perform actions only on bridges of a particular type.

Signed-off-by: Justin Pettit <jpettit at nicira.com>
---
 utilities/ovs-vsctl.8.in |    5 +++--
 utilities/ovs-vsctl.c    |   14 ++++++++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in
index 1b80d05..79269db 100644
--- a/utilities/ovs-vsctl.8.in
+++ b/utilities/ovs-vsctl.8.in
@@ -195,9 +195,10 @@ Without \fB\-\-if\-exists\fR, attempting to delete a bridge that does
 not exist is an error.  With \fB\-\-if\-exists\fR, attempting to
 delete a bridge that does not exist has no effect.
 .
-.IP "\fBlist\-br\fR"
+.IP "[\fB\-\-real\fR|\fB\-\-fake\fR] \fBlist\-br\fR"
 Lists all existing real and fake bridges on standard output, one per
-line.
+line.  With \fB\-\-real\fR or \fB\-\-fake\fR, only bridges of that type
+are returned.
 .
 .IP "\fBbr\-exists \fIbridge\fR"
 Tests whether \fIbridge\fR exists as a real or fake bridge.  If so,
diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
index fda3a89..1df8572 100644
--- a/utilities/ovs-vsctl.c
+++ b/utilities/ovs-vsctl.c
@@ -1582,13 +1582,23 @@ cmd_list_br(struct vsctl_context *ctx)
 {
     struct shash_node *node;
     struct svec bridges;
+    bool real = shash_find(&ctx->options, "--real");
+    bool fake = shash_find(&ctx->options, "--fake");
+
+    /* If neither fake nor real were requested, return both. */
+    if (!real && !fake) {
+        real = fake = true;
+    }
 
     vsctl_context_populate_cache(ctx);
 
     svec_init(&bridges);
     SHASH_FOR_EACH (node, &ctx->bridges) {
         struct vsctl_bridge *br = node->data;
-        svec_add(&bridges, br->name);
+
+        if ((br->parent && fake) || (!br->parent && real)) { 
+            svec_add(&bridges, br->name);
+        }
     }
     output_sorted(&bridges, &ctx->output);
     svec_destroy(&bridges);
@@ -3961,7 +3971,7 @@ static const struct vsctl_command_syntax all_commands[] = {
     /* Bridge commands. */
     {"add-br", 1, 3, pre_get_info, cmd_add_br, NULL, "--may-exist", RW},
     {"del-br", 1, 1, pre_get_info, cmd_del_br, NULL, "--if-exists", RW},
-    {"list-br", 0, 0, pre_get_info, cmd_list_br, NULL, "", RO},
+    {"list-br", 0, 0, pre_get_info, cmd_list_br, NULL, "--real,--fake", RO},
     {"br-exists", 1, 1, pre_get_info, cmd_br_exists, NULL, "", RO},
     {"br-to-vlan", 1, 1, pre_get_info, cmd_br_to_vlan, NULL, "", RO},
     {"br-to-parent", 1, 1, pre_get_info, cmd_br_to_parent, NULL, "", RO},
-- 
1.7.5.4




More information about the dev mailing list