-
Notifications
You must be signed in to change notification settings - Fork 2
/
serf.go
43 lines (34 loc) · 918 Bytes
/
serf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"reflect"
"strings"
serf_client "github.com/hashicorp/serf/client"
)
type serfFilter struct {
Tags map[string]string
Status string
Name string
}
func (sf1 *serfFilter) Compare(sf2 serfFilter) bool {
if strings.Compare(sf1.Status, sf2.Status) != 0 {
return false
}
if strings.Compare(sf1.Name, sf2.Name) != 0 {
return false
}
return reflect.DeepEqual(sf1.Tags, sf2.Tags)
}
func connectSerfAgent(serfRPCAddress string, serfRPCAuthKey string) (*serf_client.RPCClient, error) {
return serf_client.ClientFromConfig(&serf_client.Config{
Addr: serfRPCAddress,
AuthKey: serfRPCAuthKey,
})
}
func closeSerfConnection(client *serf_client.RPCClient) {
if client != nil {
client.Close()
}
}
func getSerfMembers(client *serf_client.RPCClient, filter serfFilter) ([]serf_client.Member, error) {
return client.MembersFiltered(filter.Tags, filter.Status, filter.Name)
}