From 3cb30851759e3a377da9d60844b7c5c5dfd0d119 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 9 Jan 2014 15:45:14 -0800 Subject: [PATCH] Adding utility method to parse consul nodes --- consul/util.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/consul/util.go b/consul/util.go index 826010547..eb9f765d0 100644 --- a/consul/util.go +++ b/consul/util.go @@ -78,6 +78,19 @@ func isConsulServer(m serf.Member) (bool, string, int) { return true, datacenter, port } +// Returns if a member is a consul node. Returns a boo, +// and the data center. +func isConsulNode(m serf.Member) (bool, string) { + role := m.Role + if !strings.HasPrefix(role, "node:") { + return false, "" + } + + parts := strings.SplitN(role, ":", 2) + datacenter := parts[1] + return true, datacenter +} + // Returns if the given IP is in a private block func isPrivateIP(ip_str string) bool { ip := net.ParseIP(ip_str)