From patchwork Sun Apr 30 23:22:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 756956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wGP141jzYz9sCX for ; Mon, 1 May 2017 09:30:16 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id B03B9BAD; Sun, 30 Apr 2017 23:23:23 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp2.linuxfoundation.org (smtp2.linux-foundation.org [172.17.192.36]) by mail.linuxfoundation.org (Postfix) with ESMTPS id C1F01BA9 for ; Sun, 30 Apr 2017 23:23:22 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by smtp2.linuxfoundation.org (Postfix) with ESMTPS id 281331DEE0 for ; Sun, 30 Apr 2017 23:23:22 +0000 (UTC) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by relay8-d.mail.gandi.net (Postfix) with ESMTPS id 91DA0406BF; Mon, 1 May 2017 01:23:20 +0200 (CEST) Received: from mfilter11-d.gandi.net (mfilter11-d.gandi.net [217.70.178.131]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 80D5641C080; Mon, 1 May 2017 01:23:20 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter11-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter11-d.gandi.net (mfilter11-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id 58OAFSffVJkm; Mon, 1 May 2017 01:23:19 +0200 (CEST) X-Originating-IP: 173.228.112.23 Received: from sigabrt.gateway.sonic.net (173-228-112-23.dsl.dynamic.fusionbroadband.com [173.228.112.23]) (Authenticated sender: blp@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 7528A41C084; Mon, 1 May 2017 01:23:16 +0200 (CEST) From: Ben Pfaff To: dev@openvswitch.org Date: Sun, 30 Apr 2017 16:22:17 -0700 Message-Id: <20170430232231.15151-14-blp@ovn.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170430232231.15151-1-blp@ovn.org> References: <20170430232231.15151-1-blp@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp2.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH 13/27] ovn-nbctl: Display and accept Neutron port names. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org These are slightly less useful in practice than switch or router names because Neutron doesn't by default give names to ports. (You can add them with "openstack port set --name", though.) Signed-off-by: Ben Pfaff Acked-by: Andy Zhou --- ovn/utilities/ovn-nbctl.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 3cae7c548784..8ec5389f6a8a 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -564,6 +564,15 @@ lb_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist) return lb; } +static void +print_alias(const struct smap *external_ids, const char *key, struct ds *s) +{ + const char *alias = smap_get(external_ids, key); + if (alias && alias[0]) { + ds_put_format(s, " (aka %s)", alias); + } +} + /* Given pointer to logical router, this routine prints the router * information. */ static void @@ -571,11 +580,7 @@ print_lr(const struct nbrec_logical_router *lr, struct ds *s) { ds_put_format(s, "router "UUID_FMT" (%s)", UUID_ARGS(&lr->header_.uuid), lr->name); - const char *neutron_name = smap_get(&lr->external_ids, - "neutron:router_name"); - if (neutron_name) { - ds_put_format(s, " (aka %s)", neutron_name); - } + print_alias(&lr->external_ids, "neutron:router_name", s); ds_put_char(s, '\n'); for (size_t i = 0; i < lr->n_ports; i++) { @@ -614,17 +619,15 @@ print_ls(const struct nbrec_logical_switch *ls, struct ds *s) { ds_put_format(s, "switch "UUID_FMT" (%s)", UUID_ARGS(&ls->header_.uuid), ls->name); - const char *neutron_name = smap_get(&ls->external_ids, - "neutron:network_name"); - if (neutron_name) { - ds_put_format(s, " (aka %s)", neutron_name); - } + print_alias(&ls->external_ids, "neutron:network_name", s); ds_put_char(s, '\n'); for (size_t i = 0; i < ls->n_ports; i++) { const struct nbrec_logical_switch_port *lsp = ls->ports[i]; - ds_put_format(s, " port %s\n", lsp->name); + ds_put_format(s, " port %s", lsp->name); + print_alias(&lsp->external_ids, "neutron:port_name", s); + ds_put_char(s, '\n'); if (lsp->type[0]) { ds_put_format(s, " type: %s\n", lsp->type); @@ -3074,8 +3077,10 @@ static const struct ctl_table_class tables[NBREC_N_TABLES] = { = {{&nbrec_logical_switch_col_name, NULL, NULL}, {&nbrec_logical_switch_col_external_ids, "neutron:network_name", NULL}}, - [NBREC_TABLE_LOGICAL_SWITCH_PORT].row_ids[0] - = {&nbrec_logical_switch_port_col_name, NULL, NULL}, + [NBREC_TABLE_LOGICAL_SWITCH_PORT].row_ids + = {{&nbrec_logical_switch_port_col_name, NULL, NULL}, + {&nbrec_logical_switch_port_col_external_ids, + "neutron:port_name", NULL}}, [NBREC_TABLE_LOGICAL_ROUTER].row_ids = {{&nbrec_logical_router_col_name, NULL, NULL},