-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathVagrantfile
More file actions
219 lines (197 loc) · 8.92 KB
/
Vagrantfile
File metadata and controls
219 lines (197 loc) · 8.92 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# frozen_string_literal: true
# -*- mode: ruby -*-
# vi: set ft=ruby :
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2020
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
require "yaml"
vagrant_boxes = YAML.load_file("#{File.dirname(__FILE__)}/../../distros_supported.yml")
subnet = "10.10.13"
controller_ip = "#{subnet}.8"
debug = ENV["OS_DEBUG"] || "false"
num_compute_nodes = ENV["OS_NUM_COMPUTE_NODES"] || "2"
no_proxy = ENV["NO_PROXY"] || ENV["no_proxy"] || "127.0.0.1,localhost"
(1..254).each do |i|
no_proxy += ",10.0.2.#{i}"
end
File.open("#{File.dirname(__FILE__)}/header.ini", "w") do |inventory_file|
inventory_file.puts("[control]\ncontroller\n\n[network]")
(1..num_compute_nodes.to_i).each do |i|
inventory_file.puts("compute#{i.to_s.rjust(2, '0')}")
end
inventory_file.puts("\n[compute]")
(1..num_compute_nodes.to_i).each do |i|
inventory_file.puts("compute#{i.to_s.rjust(2, '0')}")
end
inventory_file.puts("\n[storage]")
(1..num_compute_nodes.to_i).each do |i|
inventory_file.puts("compute#{i.to_s.rjust(2, '0')}")
end
inventory_file.puts("\n[monitoring]\ncontroller\n")
end
hosts = "#{controller_ip} controller\n"
(1..num_compute_nodes.to_i).each do |i|
no_proxy += ",#{subnet}.#{i + 8}"
hosts += "#{subnet}.#{i + 8} compute#{i.to_s.rjust(2, '0')}\n"
end
no_proxy += ",#{controller_ip}"
# NOTE: Execute awk commands results in no outputs in stdout
public_nic = `ip r get 1.1.1.1 | head -n 1 | cut -d ' ' -f 5`.strip! || "eth0"
cloud_public_cidr = `ip r | grep "dev $(ip r get 1.1.1.1 | head -n 1 | cut -d ' ' -f 5) .* scope link" | cut -d ' ' -f 1`.strip! || "192.168.0.0/24"
cloud_public_gw = `ip r | grep "^default" | head -n 1 | cut -d ' ' -f 3`.strip! || "192.168.0.1"
def which(cmd)
exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
end
end
nil
end
vb_public_nic = `VBoxManage list bridgedifs | grep "^Name:.*#{public_nic}" | cut -d "Name:[ ]*" -f 2`.strip! if which "VBoxManage"
system("echo -e \"\n\n\n\" | ssh-keygen -f #{File.dirname(__FILE__)}/../../insecure_keys/key -t rsa -N ''") unless File.exist?("#{File.dirname(__FILE__)}/../../insecure_keys/key")
Vagrant.configure("2") do |config|
config.vm.provider :libvirt
config.vm.provider :virtualbox
config.vm.synced_folder "../../", "/vagrant"
config.vm.box = vagrant_boxes["ubuntu_22"]["name"]
config.vm.box_version = vagrant_boxes["ubuntu_22"]["version"]
config.ssh.insert_key = false
# Basic requirements installation
config.vm.provision "shell", path: "#{File.dirname(__FILE__)}/../../requirements/base.sh"
config.vm.provider :libvirt do |v, override|
override.vm.synced_folder "../../", "/vagrant", type: "virtiofs"
v.memorybacking :access, mode: "shared"
v.cpu_mode = "host-passthrough"
v.random_hostname = true
v.management_network_address = "10.0.2.0/24"
v.management_network_name = "administration" # Administration - Provides Internet access for all nodes and is used for administration to install software packages
v.management_network_mode = "nat" # NATed forwarding typically to reach networks outside of hypervisor
v.cpu_mode = "host-passthrough"
v.disk_device = "sda"
v.disk_bus = "sata"
end
config.vm.provider "virtualbox" do |v|
v.gui = false
v.customize ["modifyvm", :id, "--nictype1", "virtio", "--cableconnected1", "on"]
# Enable nested paging for memory management in hardware
v.customize ["modifyvm", :id, "--nestedpaging", "on"]
# Use large pages to reduce Translation Lookaside Buffers usage
v.customize ["modifyvm", :id, "--largepages", "on"]
# Use virtual processor identifiers to accelerate context switching
v.customize ["modifyvm", :id, "--vtxvpid", "on"]
end
config.vm.provision "shell", inline: <<~SHELL
# Prefer IPv4 over IPv6 in dual-stack environment
sudo sed -i "s|^#precedence ::ffff:0:0/96 100$|precedence ::ffff:0:0/96 100|g" /etc/gai.conf
cat << EOF > /etc/hosts
127.0.0.1 localhost
#{hosts}
EOF
SHELL
(1..num_compute_nodes.to_i).each do |i|
config.vm.define "compute#{i.to_s.rjust(2, '0')}" do |nodeconfig|
nodeconfig.vm.hostname = "compute#{i.to_s.rjust(2, '0')}"
nodeconfig.vm.network :private_network, ip: "#{subnet}.#{i + 8}", type: :static, libvirt__network_name: "tunnel-net", nic_type: "virtio", virtualbox__intnet: true
nodeconfig.vm.network :public_network, dev: public_nic, bridge: vb_public_nic, auto_config: false
%i[virtualbox libvirt].each do |provider|
nodeconfig.vm.provider provider do |p|
p.memory = ENV["MEMORY"] || (4 * 1024)
end
end
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--nested-hw-virt", "on"]
end
nodeconfig.vm.disk :disk, name: "cinder", size: "50GB"
nodeconfig.vm.provider :libvirt do |v|
v.nested = true
v.storage :file, bus: "sata", device: "sdb", size: 50 # Cinder volume
end
nodeconfig.vm.provision "shell", privileged: false do |sh|
sh.env = {
OPENSTACK_NODE_ROLES: "compute",
OS_DEBUG: debug.to_s
}
sh.inline = <<-SHELL
cd /vagrant
./node.sh -c /dev/sdb | tee ~/node_$(hostname).log
SHELL
end
nodeconfig.trigger.after :up do |trigger|
trigger.info = "Configure Authorized Keys"
trigger.run_remote = { inline: "cat /vagrant/insecure_keys/key.pub >> /home/vagrant/.ssh/authorized_keys" }
end
end
end
config.vm.define "controller", primary: true, autostart: false do |controller|
controller.vm.hostname = "controller"
controller.vm.network :private_network, ip: controller_ip.to_s, type: :static, libvirt__network_name: "tunnel-net", nic_type: "virtio", virtualbox__intnet: true
controller.vm.network :public_network, dev: public_nic, bridge: vb_public_nic, auto_config: false
# SSH Keys configuration
controller.vm.provision "shell", privileged: false, inline: <<-SHELL
cd /vagrant
cp insecure_keys/key ~/.ssh/id_rsa
cp insecure_keys/key.pub ~/.ssh/id_rsa.pub
chown "$USER" ~/.ssh/id_rsa
chmod 400 ~/.ssh/id_rsa
SHELL
controller.vm.provision "shell", privileged: false do |sh|
sh.env = {
SOCKS_PROXY: ENV["socks_proxy"] || ENV["SOCKS_PROXY"] || "",
OS_FOLDER: "/vagrant/",
OS_DEBUG: debug.to_s,
OS_ENABLE_LOCAL_REGISTRY: ENV["OS_ENABLE_LOCAL_REGISTRY"] || "true",
OS_INVENTORY_FILE: "./samples/noha/hosts.ini",
OS_KOLLA_API_INTERFACE: "eth1",
OS_KOLLA_NEUTRON_EXTERNAL_INTERFACE: "eth2",
OS_KOLLA_ENABLE_NEUTRON_PROVIDER_NETWORKS: "yes",
OS_KOLLA_KOLLA_INTERNAL_VIP_ADDRESS: controller_ip.to_s,
OS_KOLLA_ENABLE_HEAT: ENV["OS_KOLLA_ENABLE_HEAT"] || "false",
EXT_NET_RANGE: "start=#{cloud_public_cidr.sub('0/24', '50')},end=#{cloud_public_cidr.sub('0/24', '100')}",
EXT_NET_CIDR: cloud_public_cidr.to_s,
EXT_NET_GATEWAY: cloud_public_gw.to_s
}
sh.inline = <<-SHELL
set -o errexit
for os_var in $(printenv | grep "OS_|EXT_NET_" ); do echo "export $os_var" | sudo tee --append /etc/environment ; done
cd /vagrant
cat ./insecure_keys/key.pub >> ~/.ssh/authorized_keys
# Create ansible inventory file
pushd samples/noha/
rm -f $(basename $OS_INVENTORY_FILE)
cat header.ini | tee --append $(basename $OS_INVENTORY_FILE)
cat tail.ini | tee --append $(basename $OS_INVENTORY_FILE)
popd
./node.sh -v sdb=/var/lib/docker/ | tee ~/node_controller.log
./install.sh | tee ~/install_controller.log
SHELL
end
%i[virtualbox libvirt].each do |provider|
config.vm.provider provider do |p|
p.cpus = ENV["CPU"] || 4
p.memory = ENV["MEMORY"] || (8 * 1024)
end
end
# Volumes
controller.vm.disk :disk, name: "docker", size: "50GB"
controller.vm.provider :libvirt do |v|
v.storage :file, bus: "sata", device: "sdb", size: 50
end
controller.trigger.after :up do |trigger|
trigger.info = "OpenStack environment variables"
trigger.run_remote = { inline: "printenv | grep OS_ ||:" }
end
end
if !ENV["http_proxy"].nil? && !ENV["https_proxy"].nil? && Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = ENV["http_proxy"] || ENV["HTTP_PROXY"] || ""
config.proxy.https = ENV["https_proxy"] || ENV["HTTPS_PROXY"] || ""
config.proxy.no_proxy = no_proxy
config.proxy.enabled = { docker: false }
end
end