1
1
# -*- mode: ruby -*-
2
2
# vi: set ft=ruby :
3
3
4
+ require 'fileutils'
5
+
4
6
netplugin_synced_gopath = "/opt/golang"
5
- host_gobin_path = "/opt/go/bin"
6
- host_goroot_path = "/opt/go/root"
7
+ FileUtils . cp "/etc/resolv.conf" , Dir . pwd
7
8
8
9
provision_common = <<SCRIPT
9
10
## setup the environment file. Export the env-vars passed as args to 'vagrant up'
10
11
echo Args passed: [[ $@ ]]
12
+
13
+ echo -n "$1" > /etc/hostname
14
+ hostname -F /etc/hostname
15
+
16
+ /sbin/ip addr add "$3/24" dev eth1
17
+ /sbin/ip link set eth1 up
18
+ /sbin/ip link set eth2 up
19
+
11
20
echo 'export GOPATH=#{ netplugin_synced_gopath } ' > /etc/profile.d/envvar.sh
12
21
echo 'export GOBIN=$GOPATH/bin' >> /etc/profile.d/envvar.sh
13
22
echo 'export GOSRC=$GOPATH/src' >> /etc/profile.d/envvar.sh
14
- echo 'export GOROOT=#{ host_goroot_path } ' >> /etc/profile.d/envvar.sh
15
- echo 'export PATH=$PATH:#{ host_goroot_path } /bin:#{ host_gobin_path } :$GOBIN' >> /etc/profile.d/envvar.sh
16
- if [ $# -gt 0 ]; then
17
- echo "export $@" >> /etc/profile.d/envvar.sh
18
- fi
23
+ echo 'export PATH=$PATH:/usr/local/go/bin:$GOBIN' >> /etc/profile.d/envvar.sh
24
+ echo "export http_proxy='$4'" >> /etc/profile.d/envvar.sh
25
+ echo "export https_proxy='$5'" >> /etc/profile.d/envvar.sh
26
+ echo "export no_proxy=192.168.0.0/16,localhost,127.0.0.0/8" >> /etc/profile.d/envvar.sh
19
27
20
28
source /etc/profile.d/envvar.sh
21
29
22
- ## set the mounted host filesystems to be read-only.Just a safety check
23
- ## to prevent inadvertent modifications from vm.
24
- (mount -o remount,ro,exec,norelatime /vagrant) || exit 1
25
- if [ -e #{ host_gobin_path } ]; then
26
- (mount -o remount,ro,exec,norelatime #{ host_gobin_path } ) || exit 1
27
- fi
28
- if [ -e #{ host_goroot_path } ]; then
29
- (mount -o remount,ro,exec,norelatime #{ host_goroot_path } ) || exit 1
30
- fi
31
- if [ -e #{ netplugin_synced_gopath } ]; then
32
- (mount -o remount,ro,exec,norelatime #{ netplugin_synced_gopath } ) || exit 1
33
- fi
30
+ mv /etc/resolv.conf /etc/resolv.conf.bak
31
+ cp #{ netplugin_synced_gopath } /src/github.com/contiv/netplugin/resolv.conf /etc/resolv.conf
34
32
35
- ### install basic packages
36
- #(apt-get update -qq > /dev/null && apt-get install -y vim curl python-software-properties git > /dev/null) || exit 1
37
- #
38
- ### install Go 1.4
39
- #(cd /usr/local/ && \
40
- #curl -L https://storage.googleapis.com/golang/go1.4.linux-amd64.tar.gz -o go1.4.linux-amd64.tar.gz && \
41
- #tar -xzf go1.4.linux-amd64.tar.gz) || exit 1
42
- #
43
- ### install etcd
44
- #(cd /tmp && \
45
- #curl -L https://github.com/coreos/etcd/releases/download/v2.0.0/etcd-v2.0.0-linux-amd64.tar.gz -o etcd-v2.0.0-linux-amd64.tar.gz && \
46
- #tar -xzf etcd-v2.0.0-linux-amd64.tar.gz && \
47
- #mv /tmp/etcd-v2.0.0-linux-amd64/etcd /usr/bin/ && \
48
- #mv /tmp/etcd-v2.0.0-linux-amd64/etcdctl /usr/bin/ ) || exit 1
49
- #
50
- ### install and start docker
51
- #(curl -sSL https://get.docker.com/ubuntu/ | sh > /dev/null) || exit 1
52
- #
53
- ## pass the env-var args to docker and restart the service. This helps passing
54
- ## stuff like http-proxy etc
55
- if [ $# -gt 0 ]; then
56
- (echo "export $@" >> /etc/default/docker) || exit 1
33
+ mkdir /etc/systemd/system/docker.service.d
34
+ echo "[Service]" | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf
35
+ echo "Environment=\\ \" no_proxy=192.168.0.0/16,localhost,127.0.0.0/8\\ \" \\ \" http_proxy=$http_proxy\\ \" \\ \" https_proxy=$https_proxy\\ \" " | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf
36
+ sudo systemctl daemon-reload
37
+ sudo systemctl stop docker
38
+ sudo systemctl start docker
39
+
40
+ if [ $# -gt 5 ]; then
41
+ shift; shift; shift; shift; shift
42
+ echo "export $@" >> /etc/profile.d/envvar.sh
57
43
fi
58
- (service docker restart) || exit 1
59
44
60
- ## install openvswitch and enable ovsdb-server to listen for incoming requests
61
- #(apt-get install -y openvswitch-switch > /dev/null) || exit 1
62
- ## Install OVS 2.3.1
63
- # (wget -nv -O ovs-common.deb https://cisco.box.com/shared/static/v1dvgoboo5zgqrtn6tu27vxeqtdo2bdl.deb &&
64
- # wget -nv -O ovs-switch.deb https://cisco.box.com/shared/static/ymbuwvt2qprs4tquextw75b82hyaxwon.deb) || exit 1
65
- # (dpkg -i ovs-common.deb &&
66
- # dpkg -i ovs-switch.deb) || exit 1
45
+ (service docker restart) || exit 1
67
46
68
47
(ovs-vsctl set-manager tcp:127.0.0.1:6640 && \
69
48
ovs-vsctl set-manager ptcp:6640) || exit 1
70
-
71
- ### install consul
72
- #(apt-get install -y unzip && cd /tmp && \
73
- # wget https://dl.bintray.com/mitchellh/consul/0.5.2_linux_amd64.zip && \
74
- # unzip 0.5.2_linux_amd64.zip && \
75
- # mv /tmp/consul /usr/bin) || exit 1
76
-
77
- # add vagrant user to docker group
78
- (usermod -a -G docker vagrant)
79
-
80
49
SCRIPT
81
50
82
51
VAGRANTFILE_API_VERSION = "2"
83
52
Vagrant . configure ( VAGRANTFILE_API_VERSION ) do |config |
84
53
if ENV [ 'CONTIV_NODE_OS' ] && ENV [ 'CONTIV_NODE_OS' ] == "centos" then
85
- config . vm . box = "contiv/centos "
54
+ config . vm . box = "contiv/centos71-netplugin "
86
55
else
87
- config . vm . box = "contiv/ubuntu-v4 "
56
+ config . vm . box = "contiv/ubuntu1504-netplugin "
88
57
end
89
58
num_nodes = 1
90
59
if ENV [ 'CONTIV_NODES' ] && ENV [ 'CONTIV_NODES' ] != "" then
@@ -93,12 +62,12 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
93
62
base_ip = "192.168.2."
94
63
node_ips = num_nodes . times . collect { |n | base_ip + "#{ n +10 } " }
95
64
node_names = num_nodes . times . collect { |n | "netplugin-node#{ n +1 } " }
65
+ node_peers = [ ]
66
+
96
67
num_nodes . times do |n |
97
68
node_name = node_names [ n ]
98
69
node_addr = node_ips [ n ]
99
- node_peers = ""
100
- node_ips . length . times { |i | node_peers += "#{ node_names [ i ] } =http://#{ node_ips [ i ] } :2380 " }
101
- node_peers = node_peers . strip ( ) . gsub ( ' ' , ',' )
70
+ node_peers += [ "#{ node_name } =http://#{ node_addr } :2380,#{ node_name } =http://#{ node_addr } :7001" ]
102
71
consul_join_flag = if n > 0 then "-join #{ node_ips [ 0 ] } " else "" end
103
72
consul_bootstrap_flag = "-bootstrap-expect=3"
104
73
if num_nodes < 3 then
@@ -109,11 +78,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
109
78
end
110
79
end
111
80
config . vm . define node_name do |node |
112
- node . vm . hostname = node_name
81
+ # node.vm.hostname = node_name
113
82
# create an interface for etcd cluster
114
- node . vm . network :private_network , ip : node_addr , virtualbox__intnet : "true"
83
+ node . vm . network :private_network , ip : node_addr , virtualbox__intnet : "true" , auto_config : false
115
84
# create an interface for bridged network
116
- node . vm . network :private_network , ip : "0.0.0.0" , virtualbox__intnet : "true"
85
+ node . vm . network :private_network , ip : "0.0.0.0" , virtualbox__intnet : "true" , auto_config : false
117
86
node . vm . provider "virtualbox" do |v |
118
87
# make all nics 'virtio' to take benefit of builtin vlan tag
119
88
# support, which otherwise needs to be enabled in Intel drivers,
@@ -125,45 +94,25 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
125
94
v . customize [ 'modifyvm' , :id , '--nicpromisc3' , 'allow-all' ]
126
95
end
127
96
# mount the host directories
128
- node . vm . synced_folder "." , "/vagrant"
129
- # godep modifies the host's GOPATH env variable, CONTIV_HOST_GOPATH
130
- # contains the unmodified path passed from the Makefile, use that
131
- # when it is defined.
132
- if ENV [ 'CONTIV_HOST_GOPATH' ] != nil
133
- node . vm . synced_folder ENV [ 'CONTIV_HOST_GOPATH' ] , netplugin_synced_gopath
134
- else
135
- node . vm . synced_folder ENV [ 'GOPATH' ] , netplugin_synced_gopath
136
- end
137
- if ENV [ 'CONTIV_HOST_GOBIN' ] != nil
138
- node . vm . synced_folder ENV [ 'CONTIV_HOST_GOBIN' ] , host_gobin_path
139
- end
140
- if ENV [ 'CONTIV_HOST_GOROOT' ] != nil
141
- node . vm . synced_folder ENV [ 'CONTIV_HOST_GOROOT' ] , host_goroot_path
142
- end
97
+ node . vm . synced_folder "." , "/opt/golang/src/github.com/contiv/netplugin"
98
+ node . vm . synced_folder File . join ( File . dirname ( __FILE__ ) , "bin" ) , File . join ( netplugin_synced_gopath , "bin" )
99
+
143
100
node . vm . provision "shell" do |s |
144
101
s . inline = provision_common
145
- s . args = ENV [ 'CONTIV_ENV' ]
102
+ s . args = [ node_name , ENV [ "CONTIV_NODE_OS" ] || "" , node_addr , ENV [ "http_proxy" ] || "" , ENV [ "https_proxy" ] || "" , * ENV [ 'CONTIV_ENV' ] ]
146
103
end
147
104
provision_node = <<SCRIPT
148
105
## start etcd with generated config
149
- (echo etcd -name #{ node_name } -data-dir /opt/etcd \
150
- -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
151
- -advertise-client-urls http://#{ node_addr } :2379,http://#{ node_addr } :4001 \
152
- -initial-advertise-peer-urls http://#{ node_addr } :2380 \
153
- -listen-peer-urls http://#{ node_addr } :2380 \
154
- -initial-cluster #{ node_peers } \
155
- -initial-cluster-state new)
156
- (nohup etcd -name #{ node_name } -data-dir /opt/etcd \
157
- -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
158
- -advertise-client-urls http://#{ node_addr } :2379,http://#{ node_addr } :4001 \
159
- -initial-advertise-peer-urls http://#{ node_addr } :2380 \
160
- -listen-peer-urls http://#{ node_addr } :2380 \
161
- -initial-cluster #{ node_peers } \
162
- -initial-cluster-state new 0<&- &>/tmp/etcd.log &) || exit 1
106
+ set -x
107
+ (nohup etcd --name #{ node_name } --data-dir /tmp/etcd \
108
+ --listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
109
+ --advertise-client-urls http://#{ node_addr } :2379,http://#{ node_addr } :4001 \
110
+ --initial-advertise-peer-urls http://#{ node_addr } :2380,http://#{ node_addr } :7001 \
111
+ --listen-peer-urls http://#{ node_addr } :2380 \
112
+ --initial-cluster #{ node_peers . join ( "," ) } --initial-cluster-state new \
113
+ 0<&- &>/tmp/etcd.log &) || exit 1
163
114
164
115
## start consul
165
- (echo && echo consul agent -server #{ consul_join_flag } #{ consul_bootstrap_flag } \
166
- -bind=#{ node_addr } -data-dir /opt/consul)
167
116
(nohup consul agent -server #{ consul_join_flag } #{ consul_bootstrap_flag } \
168
117
-bind=#{ node_addr } -data-dir /opt/consul 0<&- &>/tmp/consul.log &) || exit 1
169
118
SCRIPT
0 commit comments