From patchwork Wed Feb 27 17:28:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Alvares Gomes X-Patchwork-Id: 1049077 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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 448jmn0kmvz9s4Y for ; Thu, 28 Feb 2019 04:47:04 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 2143292D8; Wed, 27 Feb 2019 17:47:02 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 16B459287 for ; Wed, 27 Feb 2019 17:38:54 +0000 (UTC) X-Greylist: delayed 00:09:57 by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 8B5E482E for ; Wed, 27 Feb 2019 17:38:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D944300BBA8; Wed, 27 Feb 2019 17:28:56 +0000 (UTC) Received: from lucas-t460s.redhat.com (ovpn-117-195.ams2.redhat.com [10.36.117.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 512586103B; Wed, 27 Feb 2019 17:28:55 +0000 (UTC) From: lucasagomes@gmail.com To: dev@openvswitch.org Date: Wed, 27 Feb 2019 17:28:53 +0000 Message-Id: <20190227172853.6792-1-lucasagomes@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 27 Feb 2019 17:28:56 +0000 (UTC) X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] ovn-nbctl: Add lsp-get-ls command 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Lucas Alvares Gomes This commit adds the following command: lsp-get-ls: Get the logical switch which the port belongs to. This command is handy for scripting since there's no logical switch id in the Logical_Switch_Port table. Signed-off-by: Lucas Alvares Gomes --- ovn/utilities/ovn-nbctl.8.xml | 5 +++++ ovn/utilities/ovn-nbctl.c | 26 ++++++++++++++++++++++++++ tests/ovn-nbctl.at | 14 ++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/ovn/utilities/ovn-nbctl.8.xml b/ovn/utilities/ovn-nbctl.8.xml index 14cc02f53..a7a9c2701 100644 --- a/ovn/utilities/ovn-nbctl.8.xml +++ b/ovn/utilities/ovn-nbctl.8.xml @@ -476,6 +476,11 @@ Get the configured DHCPv6 options for the logical port. +
lsp-get-ls port
+
+ Get the logical switch which the port belongs to. +
+

Logical Router Commands

diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index cca7dbaa1..8a72e9574 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -613,6 +613,7 @@ Logical switch port commands:\n\ lsp-set-dhcpv6-options PORT [DHCP_OPTIONS_UUID]\n\ set dhcpv6 options for PORT\n\ lsp-get-dhcpv6-options PORT get the dhcpv6 options for PORT\n\ + lsp-get-ls PORT get the logical switch which the port belongs to\n\ \n\ Logical router commands:\n\ lr-add [ROUTER] create a logical router named ROUTER\n\ @@ -1876,6 +1877,30 @@ nbctl_lsp_get_dhcpv6_options(struct ctl_context *ctx) } } +static void +nbctl_lsp_get_ls(struct ctl_context *ctx) +{ + const char *id = ctx->argv[1]; + const struct nbrec_logical_switch_port *lsp = NULL; + + char *error = lsp_by_name_or_uuid(ctx, id, true, &lsp); + if (error) { + ctx->error = error; + return; + } + + const struct nbrec_logical_switch *ls; + NBREC_LOGICAL_SWITCH_FOR_EACH(ls, ctx->idl) { + for (size_t i = 0; i < ls->n_ports; i++) { + if (ls->ports[i] == lsp) { + ds_put_format(&ctx->output, UUID_FMT " (%s)\n", + UUID_ARGS(&ls->header_.uuid), ls->name); + break; + } + } + } +} + enum { DIR_FROM_LPORT, DIR_TO_LPORT @@ -5115,6 +5140,7 @@ static const struct ctl_command_syntax nbctl_commands[] = { nbctl_lsp_set_dhcpv6_options, NULL, "", RW }, { "lsp-get-dhcpv6-options", 1, 1, "PORT", NULL, nbctl_lsp_get_dhcpv6_options, NULL, "", RO }, + { "lsp-get-ls", 1, 1, "PORT", NULL, nbctl_lsp_get_ls, NULL, "", RO }, /* logical router commands. */ { "lr-add", 0, 1, "[ROUTER]", NULL, nbctl_lr_add, NULL, diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index a4c8ed3c3..f884fc7d2 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -153,6 +153,20 @@ AT_CHECK([ovn-nbctl --may-exist lsp-add ls0 lp2 lp3 5], [1], [], dnl --------------------------------------------------------------------- +OVN_NBCTL_TEST([ovn_nbctl_lsp_get_ls], [lsp get ls], [ +AT_CHECK([ovn-nbctl ls-add ls0]) +AT_CHECK([ovn-nbctl lsp-add ls0 lp0]) + +AT_CHECK([ovn-nbctl lsp-get-ls lp0 | uuidfilt], [0], [dnl +<0> (ls0) +]) + +AT_CHECK([ovn-nbctl lsp-get-ls lp1], [1], [], + [ovn-nbctl: lp1: port name not found +])]) + +dnl --------------------------------------------------------------------- + OVN_NBCTL_TEST([ovn_nbctl_lport_addresses], [lport addresses], [ AT_CHECK([ovn-nbctl ls-add ls0]) AT_CHECK([ovn-nbctl lsp-add ls0 lp0])