diff mbox

[ovs-dev,13/27] ovn-nbctl: Display and accept Neutron port names.

Message ID 20170430232231.15151-14-blp@ovn.org
State Accepted
Headers show

Commit Message

Ben Pfaff April 30, 2017, 11:22 p.m. UTC
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 <blp@ovn.org>
---
 ovn/utilities/ovn-nbctl.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

Comments

Andy Zhou May 3, 2017, 7:56 a.m. UTC | #1
On Sun, Apr 30, 2017 at 4:22 PM, Ben Pfaff <blp@ovn.org> wrote:
> 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 <blp@ovn.org>

Any reason to split this patch out from the last one?

Acked-by: Andy Zhou <azhou@ovn.org>
Ben Pfaff May 3, 2017, 3:29 p.m. UTC | #2
On Wed, May 03, 2017 at 12:56:53AM -0700, Andy Zhou wrote:
> On Sun, Apr 30, 2017 at 4:22 PM, Ben Pfaff <blp@ovn.org> wrote:
> > 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 <blp@ovn.org>
> 
> Any reason to split this patch out from the last one?

No strong reason.  I'll squash them.

> Acked-by: Andy Zhou <azhou@ovn.org>

Thank you!
diff mbox

Patch

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},