-
Notifications
You must be signed in to change notification settings - Fork 882
/
machines
executable file
·111 lines (96 loc) · 2.37 KB
/
machines
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#/bin/sh
set -e
usage()
{
cat << EOF
NAME:
machines - Create Test Environments for Docker Networking
VERSION:
0.1
USAGE:
$0 <command> [command_options] [arguments...]
COMMANDS:
help
Help and usage
up <kv-store> <scale>
Create environment with given KV store
zookeeper | etcd | consul (default)
Create N nodes, default = 2
destroy
Destroy Environment
EOF
}
step() {
printf "\033[0;36m-----> $@\033[0m\n"
}
up()
{
step "Creating KV Store Machine"
docker-machine create \
-d virtualbox \
mh-kv
step "KV Store is $1"
step "Starting KV Container"
case "$1" in
etcd)
cluster_store="cluster-store=etcd://$(docker-machine ip mh-kv):2379"
docker $(docker-machine config mh-kv) run -d \
-p "2379:2379" \
-h "etcd" \
--name "etcd" \
quay.io/coreos/etcd:v2.2.1 \
--listen-client-urls="http://0.0.0.0:2379" \
--advertise-client-urls="http://$(docker-machine ip mh-kv):2379"
;;
zookeeper)
cluster_store="cluster-store=zk://$(docker-machine ip mh-kv):2181"
docker $(docker-machine config mh-kv) run -d \
-p "2181:2181" \
-h "zookeeper" \
--name "zookeeper" \
tianon/zookeeper
;;
*)
cluster_store="cluster-store=consul://$(docker-machine ip mh-kv):8500"
docker $(docker-machine config mh-kv) run -d \
-p "8500:8500" \
-h "consul" \
--name "consul" \
progrium/consul -server -bootstrap-expect 1
;;
esac
machines=$2
if [ -z machines ]; then
machines=2
fi
step "Creating $machines Machines"
for i in $(seq $machines); do
step "Creating machine $i"
docker-machine create \
-d virtualbox \
--engine-opt="cluster-advertise=eth1:2376" \
--engine-opt="$cluster_store" \
mh-$i
done
}
destroy()
{
for x in $(docker-machine ls | grep mh- | awk '{ print $1 }'); do
docker-machine rm $x
done
}
case "$1" in
up)
shift
up $@
;;
destroy)
destroy $@
;;
help)
usage
;;
*)
usage
;;
esac