Ensure cli name ends with correct hostname
If longnames are in use, this also ensures that the domain (if known) is appended to the CLI node name CLI node names will be based on RabbitMQ host names Fixes #270
This commit is contained in:
		
							parent
							
								
									36ad6dfdb5
								
							
						
					
					
						commit
						585bdacba2
					
				|  | @ -13,9 +13,8 @@ | ||||||
| ## The Initial Developer of the Original Code is Pivotal Software, Inc. | ## The Initial Developer of the Original Code is Pivotal Software, Inc. | ||||||
| ## Copyright (c) 2016-2017 Pivotal Software, Inc.  All rights reserved. | ## Copyright (c) 2016-2017 Pivotal Software, Inc.  All rights reserved. | ||||||
| 
 | 
 | ||||||
| alias RabbitMQ.CLI.Core.Config |  | ||||||
| 
 |  | ||||||
| defmodule RabbitMQ.CLI.Core.Distribution do | defmodule RabbitMQ.CLI.Core.Distribution do | ||||||
|  |   alias RabbitMQ.CLI.Core.{Config, Helpers} | ||||||
| 
 | 
 | ||||||
|   # |   # | ||||||
|   # API |   # API | ||||||
|  | @ -79,26 +78,32 @@ defmodule RabbitMQ.CLI.Core.Distribution do | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   defp generate_cli_node_name(node_name_type) do |   defp generate_cli_node_name(node_name_type) do | ||||||
|     base                 = "rabbitmqcli" <> to_string(:rabbit_misc.random(100)) |     rmq_hostname         = Helpers.get_rabbit_hostname() | ||||||
|  |     base                 = "rabbitmqcli-#{:os.getpid()}-#{rmq_hostname}" | ||||||
|     inet_resolver_config = :inet.get_rc() |     inet_resolver_config = :inet.get_rc() | ||||||
| 
 |  | ||||||
|     case {node_name_type, Keyword.get(inet_resolver_config, :domain)} do |     case {node_name_type, Keyword.get(inet_resolver_config, :domain)} do | ||||||
|       {:longnames, nil} -> |       {:longnames, domain}  -> | ||||||
|         generate_dot_no_domain_name(base); |         ensure_ends_with_domain(base, domain) | ||||||
|       {:longnames, ""}  -> |  | ||||||
|         generate_dot_no_domain_name(base); |  | ||||||
|       _ -> |       _ -> | ||||||
|         base |         base | ||||||
|     end |> String.to_atom |     end |> String.to_atom | ||||||
| 
 |  | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   defp generate_dot_no_domain_name(base) do |   defp ensure_ends_with_domain(base, nil) do | ||||||
|  |     "#{base}.localdomain" | ||||||
|  |   end | ||||||
|  |   defp ensure_ends_with_domain(base, "") do | ||||||
|  |     "#{base}.localdomain" | ||||||
|  |   end | ||||||
|  |   defp ensure_ends_with_domain(base, domain) do | ||||||
|     # Distribution will fail to start if it's unable to |     # Distribution will fail to start if it's unable to | ||||||
|     # determine FQDN of a node (with at least one dot in |     # determine FQDN of a node (with at least one dot in | ||||||
|     # the name). |     # the name). | ||||||
|     # The CLI always acts as a connection initiator, so it |     case String.ends_with?(base, to_string(domain)) do | ||||||
|     # doesn't matter if the name will not resolve. |       true -> | ||||||
|     base <> "@" <> to_string(:inet_db.gethostname()) <> ".no-domain" |         base | ||||||
|  |       _ -> | ||||||
|  |         "#{base}.#{domain}" | ||||||
|  |     end | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue