-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathetcdutils.go
More file actions
71 lines (64 loc) · 1.46 KB
/
etcdutils.go
File metadata and controls
71 lines (64 loc) · 1.46 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package etcdutils
import (
"fmt"
"strings"
"testing"
"github.com/coreos/go-etcd/etcd"
"github.com/deis/deis/tests/utils"
)
type EtcdHandle struct {
Dirs []string
Keys []string
C *etcd.Client
}
func getetcdClient(port string) *etcd.Client {
IPAddress := utils.GetHostIPAddress()
machines := []string{"http://" + IPAddress + ":" + port}
c := etcd.NewClient(machines)
return c
}
func InitetcdValues(setdir, setkeys []string, port string) *EtcdHandle {
cli := getetcdClient(port)
controllerHandle := new(EtcdHandle)
controllerHandle.Dirs = setdir
controllerHandle.Keys = setkeys
controllerHandle.C = cli
fmt.Println("Etcd client initialized")
return controllerHandle
}
func SetEtcdValues(t *testing.T, keys []string, values []string, c *etcd.Client) {
for i, key := range keys {
_, err := c.Set(key, values[i], 0)
if err != nil {
t.Fatal(err)
}
}
}
func Publishvalues(t *testing.T, ecli *EtcdHandle) {
fmt.Println("Publishing ETCD Key values")
for _, dir := range ecli.Dirs {
_, err := ecli.C.SetDir(dir, 0)
if err != nil {
t.Fatal(err)
}
}
for _, key := range ecli.Keys {
switch true {
case (strings.Contains(key, "host")):
_, err := ecli.C.Set(key, "172.17.8.100", 0)
if err != nil {
t.Fatal(err)
}
case (strings.Contains(key, "port")):
_, err := ecli.C.Set(key, "10881", 0)
if err != nil {
t.Fatal(err)
}
default:
_, err := ecli.C.Set(key, "deis", 0)
if err != nil {
t.Fatal(err)
}
}
}
}