diff options
| author | Michael Klishin <mklishin@pivotal.io> | 2016-11-10 04:28:34 +0300 |
|---|---|---|
| committer | Michael Klishin <mklishin@pivotal.io> | 2016-11-10 04:28:34 +0300 |
| commit | 4c01ecd27e15da05d2a42abba0ba0ada9d3722d2 (patch) | |
| tree | e941eaf0789df37997a9be9693adbda13ed5e529 | |
| parent | 6eff8127f55b0e90bfb1460ce2e9b11d1717838c (diff) | |
| download | rabbitmq-server-git-4c01ecd27e15da05d2a42abba0ba0ada9d3722d2.tar.gz | |
Prefix hostnames discovered via DNS
| -rw-r--r-- | src/rabbit_peer_discovery.erl | 29 | ||||
| -rw-r--r-- | src/rabbit_peer_discovery_dns.erl | 3 |
2 files changed, 30 insertions, 2 deletions
diff --git a/src/rabbit_peer_discovery.erl b/src/rabbit_peer_discovery.erl index 965be3946d..e04df6a02d 100644 --- a/src/rabbit_peer_discovery.erl +++ b/src/rabbit_peer_discovery.erl @@ -19,7 +19,7 @@ %% API -export([discover_cluster_nodes/0, backend/0, normalize/1, format_discovered_nodes/1]). - +-export([append_node_prefix/1, node_prefix/0]). -spec backend() -> atom(). @@ -57,3 +57,30 @@ normalize({error, Reason}) -> format_discovered_nodes(Nodes) -> string:join(lists:map(fun (Val) -> hd(io_lib:format("~s", [Val])) end, Nodes), ", "). + + +-define(DEFAULT_PREFIX, "rabbit"). +-define(NODENAME_PART_SEPARATOR, "@"). + + +-spec node_prefix() -> string(). + +node_prefix() -> + case string:tokens(atom_to_list(node()), ?NODENAME_PART_SEPARATOR) of + [Prefix, _] -> Prefix; + [_] -> ?DEFAULT_PREFIX + end. + + + +-spec append_node_prefix(Value :: binary() | list()) -> atom(). + +append_node_prefix(Value) -> + Val = rabbit_data_coercion:to_list(Value), + Hostname = case string:tokens(Val, ?NODENAME_PART_SEPARATOR) of + [_ExistingPrefix, Val] -> + Val; + [Val] -> + Val + end, + string:join([node_prefix(), Hostname], ?NODENAME_PART_SEPARATOR). diff --git a/src/rabbit_peer_discovery_dns.erl b/src/rabbit_peer_discovery_dns.erl index 5f20b66016..3e9e2d988a 100644 --- a/src/rabbit_peer_discovery_dns.erl +++ b/src/rabbit_peer_discovery_dns.erl @@ -20,6 +20,7 @@ -include("rabbit.hrl"). -export([list_nodes/0, register/0, unregister/0]). +%% for tests -export([discover_nodes/2]). %% @@ -58,7 +59,7 @@ unregister() -> %% discover_nodes(SeedHostname, LongNamesUsed) -> - discover_hostnames(SeedHostname, LongNamesUsed). + [rabbit_peer_discovery:append_node_prefix(H) || H <- discover_hostnames(SeedHostname, LongNamesUsed)]. discover_hostnames(SeedHostname, LongNamesUsed) -> Hosts = [extract_host(inet_res:gethostbyaddr(A), LongNamesUsed) || A <- inet_res:lookup(SeedHostname, in, a)], |
