ovn: Get hostname from ovs external-ids.
authorRussell Bryant <russell@ovn.org>
Fri, 25 Mar 2016 00:38:07 +0000 (00:38 +0000)
committerRussell Bryant <russell@ovn.org>
Fri, 25 Mar 2016 03:10:59 +0000 (23:10 -0400)
A previous commit updated ovs-ctl to store the system's hostname as an
external-id in the Open_vSwitch table by default.  Make ovn-controller
read this by default and fall back to gethostname() only if needed.

Suggested-by: Justin Pettit <jpettit@ovn.org>
Suggested-at: http://openvswitch.org/pipermail/dev/2016-March/068225.html
Signed-off-by: Russell Bryant <russell@ovn.org>
Acked-by: Justin Pettit <jpettit@ovn.org>
ovn/controller/chassis.c
ovn/controller/ovn-controller.8.xml

index 4109b0c..52c9993 100644 (file)
@@ -62,13 +62,10 @@ chassis_run(struct controller_ctx *ctx, const char *chassis_id)
         return;
     }
 
-    const struct sbrec_chassis *chassis_rec;
     const struct ovsrec_open_vswitch *cfg;
     const char *encap_type, *encap_ip;
     static bool inited = false;
 
-    chassis_rec = get_chassis(ctx->ovnsb_idl, chassis_id);
-
     cfg = ovsrec_open_vswitch_first(ctx->ovs_idl);
     if (!cfg) {
         VLOG_INFO("No Open_vSwitch row defined.");
@@ -96,11 +93,18 @@ 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';
+    const char *hostname = smap_get(&cfg->external_ids, "hostname");
+    char hostname_[HOST_NAME_MAX + 1];
+    if (!hostname || !hostname[0]) {
+        if (gethostname(hostname_, sizeof hostname_)) {
+            hostname_[0] = '\0';
+        }
+        hostname = hostname_;
     }
 
+    const struct sbrec_chassis *chassis_rec
+        = get_chassis(ctx->ovnsb_idl, chassis_id);
+
     if (chassis_rec) {
         if (strcmp(hostname, chassis_rec->hostname)) {
             sbrec_chassis_set_hostname(chassis_rec, hostname);
index b261af9..69d4cc0 100644 (file)
@@ -78,6 +78,9 @@
       <dt><code>external_ids:system-id</code></dt>
       <dd>The chassis name to use in the Chassis table.</dd>
 
+      <dt><code>external_ids:hostname</code></dt>
+      <dd>The hostname to use in the Chassis table.</dd>
+
       <dt><code>external_ids:ovn-bridge</code></dt>
       <dd>
         The integration bridge to which logical ports are attached.  The