From patchwork Thu Sep 3 21:47:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 514281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id C4F82140771 for ; Fri, 4 Sep 2015 07:55:06 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id CFE9710BC6; Thu, 3 Sep 2015 14:48:00 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e4.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id D0ABA10BC5 for ; Thu, 3 Sep 2015 14:47:59 -0700 (PDT) Received: from bar5.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id 2C5FC1E00AC for ; Thu, 3 Sep 2015 15:47:49 -0600 (MDT) X-ASG-Debug-ID: 1441316866-09eadd6031bcf70001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar5.cudamail.com with ESMTP id Yo5BFlXvQ7YbTzcu (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 03 Sep 2015 15:47:46 -0600 (MDT) X-Barracuda-Envelope-From: jpettit@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mail-pa0-f44.google.com) (209.85.220.44) by mx1-pf2.cudamail.com with ESMTPS (RC4-SHA encrypted); 3 Sep 2015 21:47:46 -0000 Received-SPF: unknown (mx1-pf2.cudamail.com: Multiple SPF records returned) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.44 Received: by pacfv12 with SMTP id fv12so2538188pac.2 for ; Thu, 03 Sep 2015 14:47:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=8t/D8++UGFbj7fLRue26kSd5hPGOXF0YaOU5qKFF6QE=; b=T59/tAbT10QMXiHGHgr7f+inNZRRTnzI56RjZRT7yUOOSPah3kwQ6trrx6T0iqtVhB har/cEejpPZmdyLQRZJN3GYUipIms0UY5+LXKeiwknhFPgnmAsgFTv+ouuMAg28MEmTz Y+ZqiYPFScbPayAT9/xOgJjLoTpDkzENZSAibq9clz7bWnROx3zQ70nuiw97QVyxHswH f8/jQ3a7KoCgK/R3/7q61wK6XOBO+jublFG5lQ+tuVjNNDBVKxtm1zyhJvlY1+2b8rSi YYoT1fbMkbZsuEFrOKW/uZNee+9iANFuQuwhpbUJ3vlCwQDPCBhdbbpWv0CZSpw8eeIQ 46rg== X-Gm-Message-State: ALoCoQn4YTtXzb77ZOT4fQjcy0mEvzqKh/h2cd54FCqLQiHaxVz8cM3SXl4bvl/C7n0HrhqmswNS X-Received: by 10.66.227.2 with SMTP id rw2mr260812pac.98.1441316865063; Thu, 03 Sep 2015 14:47:45 -0700 (PDT) Received: from localhost.localdomain ([208.91.2.4]) by smtp.gmail.com with ESMTPSA id u5sm96145pdr.63.2015.09.03.14.47.44 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 03 Sep 2015 14:47:44 -0700 (PDT) X-CudaMail-Envelope-Sender: jpettit@nicira.com X-Barracuda-Apparent-Source-IP: 208.91.2.4 From: Justin Pettit To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E2-902088601 X-CudaMail-DTE: 090315 X-CudaMail-Originating-IP: 209.85.220.44 Date: Thu, 3 Sep 2015 14:47:01 -0700 X-ASG-Orig-Subj: [##CM-E2-902088601##][PATCH 3/4] ovn-nbctl: Sort output of most commands. Message-Id: <1441316822-60290-3-git-send-email-jpettit@nicira.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1441316822-60290-1-git-send-email-jpettit@nicira.com> References: <1441316822-60290-1-git-send-email-jpettit@nicira.com> X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1441316866 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH 3/4] ovn-nbctl: Sort output of most commands. X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" This will be helpful for unit tests. Signed-off-by: Justin Pettit --- ovn/utilities/ovn-nbctl.c | 49 ++++++++++++++++++++++++++++++++++++++------ 1 files changed, 42 insertions(+), 7 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 0bdb3a3..aac7be1 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -25,8 +25,10 @@ #include "ovn/lib/ovn-nb-idl.h" #include "poll-loop.h" #include "process.h" +#include "smap.h" #include "stream.h" #include "stream-ssl.h" +#include "svec.h" #include "util.h" #include "openvswitch/vlog.h" @@ -217,11 +219,20 @@ do_lswitch_list(struct ovs_cmdl_context *ctx) { struct nbctl_context *nb_ctx = ctx->pvt; const struct nbrec_logical_switch *lswitch; + struct smap lswitches; + smap_init(&lswitches); NBREC_LOGICAL_SWITCH_FOR_EACH(lswitch, nb_ctx->idl) { - printf(UUID_FMT " (%s)\n", - UUID_ARGS(&lswitch->header_.uuid), lswitch->name); + smap_add_format(&lswitches, lswitch->name, UUID_FMT " (%s)", + UUID_ARGS(&lswitch->header_.uuid), lswitch->name); } + const struct smap_node **nodes = smap_sort(&lswitches); + for (size_t i = 0; i < smap_count(&lswitches); i++) { + const struct smap_node *node = nodes[i]; + printf("%s\n", node->value); + } + smap_destroy(&lswitches); + free(nodes); } static void @@ -408,17 +419,27 @@ do_lport_list(struct ovs_cmdl_context *ctx) struct nbctl_context *nb_ctx = ctx->pvt; const char *id = ctx->argv[1]; const struct nbrec_logical_switch *lswitch; + struct smap lports; + size_t i; lswitch = lswitch_by_name_or_uuid(nb_ctx, id); if (!lswitch) { return; } - for (size_t i = 0; i < lswitch->n_ports; i++) { + smap_init(&lports); + for (i = 0; i < lswitch->n_ports; i++) { const struct nbrec_logical_port *lport = lswitch->ports[i]; - printf(UUID_FMT " (%s)\n", - UUID_ARGS(&lport->header_.uuid), lport->name); + smap_add_format(&lports, lport->name, UUID_FMT " (%s)", + UUID_ARGS(&lport->header_.uuid), lport->name); } + const struct smap_node **nodes = smap_sort(&lports); + for (i = 0; i < smap_count(&lports); i++) { + const struct smap_node *node = nodes[i]; + printf("%s\n", node->value); + } + smap_destroy(&lports); + free(nodes); } static void @@ -532,6 +553,8 @@ do_lport_get_macs(struct ovs_cmdl_context *ctx) struct nbctl_context *nb_ctx = ctx->pvt; const char *id = ctx->argv[1]; const struct nbrec_logical_port *lport; + struct svec macs; + const char *mac; size_t i; lport = lport_by_name_or_uuid(nb_ctx, id); @@ -539,9 +562,14 @@ do_lport_get_macs(struct ovs_cmdl_context *ctx) return; } + svec_init(&macs); for (i = 0; i < lport->n_macs; i++) { - printf("%s\n", lport->macs[i]); + svec_add(&macs, lport->macs[i]); + } + SVEC_FOR_EACH(i, mac, &macs) { + printf("%s\n", mac); } + svec_destroy(&macs); } static void @@ -566,6 +594,8 @@ do_lport_get_port_security(struct ovs_cmdl_context *ctx) struct nbctl_context *nb_ctx = ctx->pvt; const char *id = ctx->argv[1]; const struct nbrec_logical_port *lport; + struct svec addrs; + const char *addr; size_t i; lport = lport_by_name_or_uuid(nb_ctx, id); @@ -573,9 +603,14 @@ do_lport_get_port_security(struct ovs_cmdl_context *ctx) return; } + svec_init(&addrs); for (i = 0; i < lport->n_port_security; i++) { - printf("%s\n", lport->port_security[i]); + svec_add(&addrs, lport->port_security[i]); + } + SVEC_FOR_EACH(i, addr, &addrs) { + printf("%s\n", addr); } + svec_destroy(&addrs); } static void