[ovs-dev] [PATCH v2] ovn: Add hostname to Chassis.

Russell Bryant russell at ovn.org
Tue Mar 22 19:20:04 UTC 2016


We currently use the system-id from the Open_vSwitch schema on each host
to populate the unique name field of a Chassis in OVN_Southbound.  On
most systems, this is a UUID.  It would be very convenient to also have
the hostname available as that will allow people to more quickly
identify which host a Chassis record is associated with in most cases.

This is also useful for correlating an OVN Chassis with the knowledge of
hosts that exists in other systems (such as OpenStack).

Also add the hostname of each chassis to the output of "ovn-sbctl show".

Signed-off-by: Russell Bryant <russell at ovn.org>
---
 ovn/controller/chassis.c  | 12 ++++++++++++
 ovn/ovn-sb.ovsschema      |  5 +++--
 ovn/ovn-sb.xml            |  6 ++++++
 ovn/utilities/ovn-sbctl.c |  4 ++--
 4 files changed, 23 insertions(+), 4 deletions(-)

v1->v2:
 - Detect hostname changes after a chassis record is created.


diff --git a/ovn/controller/chassis.c b/ovn/controller/chassis.c
index 67f3085..1e2aaec 100644
--- a/ovn/controller/chassis.c
+++ b/ovn/controller/chassis.c
@@ -14,6 +14,8 @@
  */
 
 #include <config.h>
+#include <unistd.h>
+
 #include "chassis.h"
 
 #include "lib/vswitch-idl.h"
@@ -89,7 +91,16 @@ chassis_run(struct controller_ctx *ctx, const char *chassis_id)
     }
     free(tokstr);
 
+    char hostname[HOST_NAME_MAX + 1];
+    if (gethostname(hostname, sizeof hostname)) {
+        hostname[0] = '\0';
+    }
+
     if (chassis_rec) {
+        if (strcmp(hostname, chassis_rec->hostname)) {
+            sbrec_chassis_set_hostname(chassis_rec, hostname);
+        }
+
         /* Compare desired tunnels against those currently in the database. */
         uint32_t cur_tunnels = 0;
         bool same = true;
@@ -127,6 +138,7 @@ chassis_run(struct controller_ctx *ctx, const char *chassis_id)
     if (!chassis_rec) {
         chassis_rec = sbrec_chassis_insert(ctx->ovnsb_idl_txn);
         sbrec_chassis_set_name(chassis_rec, chassis_id);
+        sbrec_chassis_set_hostname(chassis_rec, hostname);
     }
 
     int n_encaps = count_1bits(req_tunnels);
diff --git a/ovn/ovn-sb.ovsschema b/ovn/ovn-sb.ovsschema
index ead733b..32f8748 100644
--- a/ovn/ovn-sb.ovsschema
+++ b/ovn/ovn-sb.ovsschema
@@ -1,11 +1,12 @@
 {
     "name": "OVN_Southbound",
-    "version": "1.1.0",
-    "cksum": "1223981720 5320",
+    "version": "1.2.0",
+    "cksum": "1259182303 5368",
     "tables": {
         "Chassis": {
             "columns": {
                 "name": {"type": "string"},
+                "hostname": {"type": "string"},
                 "encaps": {"type": {"key": {"type": "uuid",
                                             "refTable": "Encap"},
                                     "min": 1, "max": "unlimited"}},
diff --git a/ovn/ovn-sb.xml b/ovn/ovn-sb.xml
index d62f1e4..e1a5812 100644
--- a/ovn/ovn-sb.xml
+++ b/ovn/ovn-sb.xml
@@ -162,6 +162,12 @@
       not prescribe a particular format for chassis names.
     </column>
 
+    <column name="hostname">
+      The hostname of the chassis, if applicable.  ovn-controller will populate
+      this column with the hostname of the host it is running on.
+      ovn-controller-vtep will leave this column empty.
+    </column>
+
     <group title="Encapsulation Configuration">
       <p>
         OVN uses encapsulation to transmit logical dataplane packets
diff --git a/ovn/utilities/ovn-sbctl.c b/ovn/utilities/ovn-sbctl.c
index 706ab2e..d080952 100644
--- a/ovn/utilities/ovn-sbctl.c
+++ b/ovn/utilities/ovn-sbctl.c
@@ -504,8 +504,8 @@ pre_get_info(struct ctl_context *ctx)
 static struct cmd_show_table cmd_show_tables[] = {
     {&sbrec_table_chassis,
      &sbrec_chassis_col_name,
-     {&sbrec_chassis_col_encaps,
-      NULL,
+     {&sbrec_chassis_col_hostname,
+      &sbrec_chassis_col_encaps,
       NULL},
      {&sbrec_table_port_binding,
       &sbrec_port_binding_col_logical_port,
-- 
2.5.5




More information about the dev mailing list