-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVagrantfile
More file actions
199 lines (165 loc) · 5.71 KB
/
Copy pathVagrantfile
File metadata and controls
199 lines (165 loc) · 5.71 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# -*- mode: ruby -*-
# vi: set ft=ruby :
# --- VMs configuration -------------------------------------------------------
require 'vagrant-proxyconf'
require 'vagrant-cachier'
require 'vagrant-hosts'
# number of CPUs for every VM
host_cpus = `python -c "import multiprocessing; print multiprocessing.cpu_count()"`.to_i
max_cpus = [host_cpus, 32].min
min_cpus = 1
vm_cpus = ENV['VAGRANT_CPUS'].to_i
if vm_cpus == 0
vm_cpus = host_cpus / 2
end
vm_cpus = [min_cpus, vm_cpus, max_cpus].sort[1]
vm_boxes = {
"precise" => "ubuntu/precise64",
"trusty" => "ubuntu/trusty64",
"vivid" => "ubuntu/vivid64",
"wily" => "ubuntu/wily64",
"fedora21" => "box-cutter/fedora21",
"fedora22" => "box-cutter/fedora22",
"fedora23" => "box-cutter/fedora23",
"centos7" => "puppetlabs/centos-7.2-64-nocm"}
use_nfs = false
if ENV["USE_NFS"] == "true"
use_nfs = true
end
nfs_mount_options = ['rw', "vers=3", 'tcp', 'fsc']
vm_box_name = ENV["VAGRANT_BOX_NAME"]
if vm_box_name == nil
vm_box_name = "trusty"
elsif vm_box_name == "centos7"
vm_cpus = 1
use_nfs = true
end
# available VM images
vm_images = [
[0,
"control",
vm_box_name,
12288],
[1,
"compute",
vm_box_name,
16384],
]
git_proxy_wrapper = ENV["GIT_PROXY_COMMAND"]
http_proxy = ENV["http_proxy"]
https_proxy = ENV["https_proxy"]
no_proxy = ENV["no_proxy"]
build_dir = ENV["BUILD_DIR"]
if build_dir == nil
build_dir = "#{Dir.pwd}/build/0"
end
log_dir = ENV["LOG_DIR"]
if log_dir == nil
log_dir = "#{build_dir}/logs"
end
stack_dir = ENV["STACK_DIR"]
if stack_dir == nil
stack_dir = "#{build_dir}/stack"
end
user_id = ENV["USER"]
if user_id == nil
user_id = "anonymous"
end
control_networkt_prefix = '192.168.1'
tenent_network_prefix = '192.168.2'
nfs_network_prefix = '192.168.3'
# --- vagrant meat ------------------------------------------------------------
Vagrant.configure(2) do |config|
vm_images.each do |node_id, vm_name, vm_image, vm_memory|
control_ip = "#{control_networkt_prefix}.#{node_id + 2}"
tenent_ip = "#{tenent_network_prefix}.#{node_id + 2}"
nfs_ip = "#{tenent_network_prefix}.#{node_id + 2}"
config.vm.define vm_name do |conf|
conf.vm.box = vm_boxes[vm_image]
conf.vm.hostname = vm_name
# control network
conf.vm.network "private_network",
virtualbox__intnet: "controlnet-#{log_dir}",
ip: control_ip, auto_config: true
# tenent network
conf.vm.network "private_network",
virtualbox__intnet: "tenentnet-#{log_dir}",
ip: tenent_ip,
auto_config: true
# assign a different random port to every vm instance
# this avoid concurrency problems when running tests in parallel
conf.vm.network :forwarded_port, guest: 22,
host: 22000 + rand(9999), id: "ssh", auto_correct: true
if vm_name == 'control'
conf.vm.network :forwarded_port, guest: 6080, host: 6080,
id: "vnc-console", auto_correct: true
conf.vm.network :forwarded_port, guest: 80, host: 8000,
id: "openstack", auto_correct: true
end
if use_nfs
# nfs network
conf.vm.network "private_network",
ip: nfs_ip, auto_config: true
conf.nfs.map_uid = Process.uid
conf.vm.synced_folder ".", "/vagrant", create: true,
type: "nfs", mount_options: nfs_mount_options
conf.vm.synced_folder "#{log_dir}/#{vm_name}",
"/opt/stack/logs", create: true,
type: "nfs", mount_options: nfs_mount_options
else
conf.vm.synced_folder "#{log_dir}/#{vm_name}",
"/opt/stack/logs", create: true
end
conf.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = false
vb.memory = vm_memory # VM ram
vb.cpus = vm_cpus # VM CPU cores
# openstack guests to talk to each other
vb.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
end
# provision etc host with nodes by name
config.vm.provision :hosts do |hosts|
vm_images.each do |node_id, vm_name, vm_image, vm_memory|
hosts.add_host "#{control_networkt_prefix}.#{node_id + 2}",
[vm_name]
end
end
end
end
# try fixing NAT crashes
config.vm.provider :virtualbox do |vb|
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
end
if Vagrant.has_plugin?("vagrant-proxyconf")
if http_proxy != nil
config.proxy.http = http_proxy
end
if https_proxy != nil
config.proxy.https = https_proxy
end
if no_proxy != nil
config.proxy.no_proxy = no_proxy
end
end
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :machine
if use_nfs
config.cache.synced_folder_opts = {
type: :nfs,
mount_options: nfs_mount_options
}
end
end
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
end
if git_proxy_wrapper != nil
config.vm.provision "file",
source: git_proxy_wrapper,
destination: "/home/vagrant/git_proxy_wrapper"
end
config.vm.provision "shell", inline: <<-SHELL
su -l vagrant /vagrant/scripts/provision.sh
SHELL
end