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 <jpet...@ovn.org> Suggested-at: http://openvswitch.org/pipermail/dev/2016-March/068225.html Signed-off-by: Russell Bryant <russ...@ovn.org> --- ovn/controller/chassis.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ovn/controller/chassis.c b/ovn/controller/chassis.c index 4109b0c..52c9993 100644 --- a/ovn/controller/chassis.c +++ b/ovn/controller/chassis.c @@ -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); -- 2.5.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev