ovs-vsctl: Add "--real" and "--fake" options to "list-br".
authorJustin Pettit <jpettit@nicira.com>
Sat, 1 Dec 2012 02:50:18 +0000 (18:50 -0800)
committerJustin Pettit <jpettit@nicira.com>
Sun, 2 Dec 2012 00:49:45 +0000 (16:49 -0800)
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@nicira.com>
tests/ovs-vsctl.at
utilities/ovs-vsctl.8.in
utilities/ovs-vsctl.c

index e903619..6b35dd3 100644 (file)
@@ -439,6 +439,22 @@ CHECK_IFACES([xapi1], [eth0.$1])
 OVS_VSCTL_CLEANUP
 AT_CLEANUP
 
+AT_SETUP([list bridges -- real and fake (VLAN $1)])
+AT_KEYWORDS([ovs-vsctl fake-bridge])
+OVS_VSCTL_SETUP
+OVS_VSCTL_SETUP_SIMPLE_FAKE_CONF([$1])
+AT_CHECK([RUN_OVS_VSCTL_ONELINE([-- list-br])], [0],
+  [xapi1\nxenbr0
+], [], [OVS_VSCTL_CLEANUP])
+AT_CHECK([RUN_OVS_VSCTL_ONELINE([-- --real list-br])], [0],
+  [xenbr0
+], [], [OVS_VSCTL_CLEANUP])
+AT_CHECK([RUN_OVS_VSCTL_ONELINE([-- --fake list-br])], [0],
+  [xapi1
+], [], [OVS_VSCTL_CLEANUP])
+OVS_VSCTL_CLEANUP
+AT_CLEANUP
+
 AT_SETUP([simple fake bridge + del-br fake bridge (VLAN $1)])
 AT_KEYWORDS([ovs-vsctl fake-bridge])
 OVS_VSCTL_SETUP
index 1b80d05..79269db 100644 (file)
@@ -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,
index fda3a89..69e37e0 100644 (file)
@@ -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 : 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},