summaryrefslogtreecommitdiff
path: root/src/rabbit_nodes.erl
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2012-02-02 14:36:17 +0000
committerSimon MacMullen <simon@rabbitmq.com>2012-02-02 14:36:17 +0000
commit76c8d30ea771b5c01b2c7bdfd246517fe7474d44 (patch)
treed9d96d16bee2004aca790e9209329db1a8caf221 /src/rabbit_nodes.erl
parent3baa52f36bd956cf1ce11ced8e18b7d28ef23eb3 (diff)
downloadrabbitmq-server-76c8d30ea771b5c01b2c7bdfd246517fe7474d44.tar.gz
Move rabbit_misc:nodeparts/1 and rabbit_misc:makenode/1 into rabbit_nodes
Diffstat (limited to 'src/rabbit_nodes.erl')
-rw-r--r--src/rabbit_nodes.erl23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/rabbit_nodes.erl b/src/rabbit_nodes.erl
index f3305127..9a39d16b 100644
--- a/src/rabbit_nodes.erl
+++ b/src/rabbit_nodes.erl
@@ -11,12 +11,12 @@
%% The Original Code is RabbitMQ.
%%
%% The Initial Developer of the Original Code is VMware, Inc.
-%% Copyright (c) 2007-2011 VMware, Inc. All rights reserved.
+%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved.
%%
-module(rabbit_nodes).
--export([names/1, diagnostics/1]).
+-export([names/1, diagnostics/1, make/1, parts/1]).
-define(EPMD_TIMEOUT, 30000).
@@ -29,6 +29,8 @@
-spec(names/1 :: (string()) -> rabbit_types:ok_or_error2(
[{string(), integer()}], term())).
-spec(diagnostics/1 :: ([node()]) -> string()).
+-spec(make/1 :: ({string(), string()} | string()) -> node()).
+-spec(parts/1 :: (node() | string()) -> {string(), string()}).
-endif.
@@ -47,8 +49,7 @@ names(Hostname) ->
Res.
diagnostics(Nodes) ->
- Hosts = lists:usort([element(2, rabbit_misc:nodeparts(Node)) ||
- Node <- Nodes]),
+ Hosts = lists:usort([element(2, parts(Node)) || Node <- Nodes]),
NodeDiags = [{"~nDIAGNOSTICS~n===========~n~n"
"nodes in question: ~p~n~n"
"hosts, their running nodes and ports:", [Nodes]}] ++
@@ -75,3 +76,17 @@ diagnostics_host(Host) ->
[Host, [{list_to_atom(Name), Port} ||
{Name, Port} <- NamePorts]]}
end.
+
+make({Prefix, Suffix}) ->
+ list_to_atom(lists:append([Prefix, "@", Suffix]));
+make(NodeStr) ->
+ make(parts(NodeStr)).
+
+parts(Node) when is_atom(Node) ->
+ parts(atom_to_list(Node));
+parts(NodeStr) ->
+ case lists:splitwith(fun (E) -> E =/= $@ end, NodeStr) of
+ {Prefix, []} -> {_, Suffix} = parts(node()),
+ {Prefix, Suffix};
+ {Prefix, Suffix} -> {Prefix, tl(Suffix)}
+ end.