-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
283 lines (238 loc) · 8.69 KB
/
Vagrantfile
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
require 'yaml'
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Four networks:
# 0 - VM host NAT
# 1 - COE build/deploy
# 2 - COE openstack internal
# 3 - COE openstack external (public)
def parse_vagrant_config(
config_file=File.expand_path(File.join(File.dirname(__FILE__), 'config.yaml'))
)
config = {
'gui_mode' => false,
'operatingsystem' => 'ubuntu',
'verbose' => false,
'update_repos' => true,
'node_group' => 'multi_node'
}
if File.exists?(config_file)
overrides = YAML.load_file(config_file)
config.merge!(overrides)
end
config
end
#
# process the node group that is used to determine the
# nodes that should be provisioned. The group of nodes
# can be set with the node_group param from config.yaml
# and maps to its corresponding file in the nodes directory.
#
def process_nodes(config, v_config, apt_cache_proxy)
node_group = v_config['node_group']
node_group_file = File.expand_path(File.join(File.dirname(__FILE__), 'nodes', "#{node_group}.yaml"))
abort('node_group much be specific in config') unless node_group
abort('file must exist for node group') unless File.exists?(node_group_file)
(YAML.load_file(node_group_file)['nodes'] || {}).each do |name, options|
config.vm.define name.intern do |config|
configure_openstack_node(
config,
options['hostname'],
options['memory'],
options['image_name'],
options['ip_number'],
apt_cache_proxy,
v_config,
options['post_config']
)
end
end
end
# get the correct box based on the specidied type
# currently, this just retrieves a single box for precise64
def get_box(config, box_type)
if box_type == 'precise64'
config.vm.box = 'precise64'
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
else
abort("Box type: #{box_type} is no good.")
end
end
#
# setup networks for openstack. Currently, this just sets up
# 4 virtual interfaces as follows:
#
# * eth1 => 192.168.242.0/24
# this is the network that the openstack services use to communicate with each other
# * eth2 => 10.2.3.0/24
# * eth3 => 10.2.3.0/24
#
# == Parameters
# config - vm config object
# number - the lowest octal in a /24 network
# options - additional options
# eth1_mac - mac address to set for eth1 (used for PXE booting)
#
def setup_networks(config, number, options = {})
config.vm.network :hostonly, "192.168.242.#{number}", :mac => options[:eth1_mac]
config.vm.network :hostonly, "10.2.3.#{number}"
config.vm.network :hostonly, "10.3.3.#{number}"
# set eth3 in promiscuos mode
config.vm.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
# set the boot priority to use eth1
config.vm.customize(['modifyvm', :id ,'--nicbootprio2','1'])
end
#
# setup the hostname of our box
#
def setup_hostname(config, hostname)
config.vm.customize ['modifyvm', :id, '--name', hostname]
config.vm.host_name = hostname
end
#
# run puppet apply on the site manifest
#
def apply_manifest(config, v_config, manifest_name='site.pp')
options = []
if v_config[:verbose]
options = options + ['--verbose', '--trace', '--debug', '--show_diff']
end
# ensure that when puppet applies the site manifest, it has hiera configured
if manifest_name == 'site.pp'
config.vm.share_folder("hiera_data", '/etc/puppet/hiera_data', './hiera_data/')
end
config.vm.provision(:puppet, :pp_path => "/etc/puppet") do |puppet|
puppet.manifests_path = 'manifests'
puppet.manifest_file = manifest_name
puppet.module_path = 'modules'
puppet.options = options
end
# uninstall the puppet gem b/c setup.pp installs the puppet package
if manifest_name == 'setup.pp'
config.vm.provision :shell do |shell|
shell.inline = "gem uninstall -x -a puppet;echo -e '#!/bin/bash\npuppet agent $@' > /sbin/puppetd;chmod a+x /sbin/puppetd"
end
end
end
# run the puppet agent
def run_puppet_agent(
config,
node_name,
v_config = {},
master = 'build-server.domain.name'
)
options = ["--certname #{node_name}", '-t', '--pluginsync']
if v_config[:verbose]
options = options + ['--trace', '--debug', '--show_diff']
end
config.vm.provision(:puppet_server) do |puppet|
puppet.puppet_server = 'build-server.domain.name'
puppet.options = options
end
end
#
# configure apt repos with mirrors and proxies and what-not
# I really want to move this to puppet
#
def configure_apt_mirror(config, apt_mirror, apt_cache_proxy)
# Configure apt mirror
config.vm.provision :shell do |shell|
shell.inline = "sed -i 's/us.archive.ubuntu.com/%s/g' /etc/apt/sources.list" % apt_mirror
end
config.vm.provision :shell do |shell|
shell.inline = '%s apt-get update;apt-get install ubuntu-cloud-keyring' % apt_cache_proxy
end
end
#
# methods that performs all openstack config
#
def configure_openstack_node(
config,
node_name,
memory,
box_name,
net_id,
apt_cache_proxy,
v_config,
post_config = false
)
cert_name = "#{node_name}-#{Time.now.strftime('%Y%m%d%m%s')}.domain.name"
get_box(config, box_name)
setup_hostname(config, node_name)
config.vm.customize ["modifyvm", :id, "--memory", memory]
setup_networks(config, net_id)
configure_apt_mirror(config, v_config['apt_mirror'], apt_cache_proxy)
apply_manifest(config, v_config, 'setup.pp')
run_puppet_agent(config, cert_name, v_config)
if post_config
config.vm.provision :shell do |shell|
shell.inline = post_config
end
end
end
Vagrant::Config.run do |config|
require 'fileutils'
v_config = parse_vagrant_config
apt_cache_proxy = ''
if v_config['apt_cache'] != 'false'
apt_cache_proxy = 'echo "Acquire::http { Proxy \"http://%s:3142\"; };" > /etc/apt/apt.conf.d/01apt-cacher-ng-proxy;' % v_config['apt_cache']
end
config.vm.define :cache do |config|
get_box(config, 'precise64')
setup_networks(config, '99')
setup_hostname(config, 'cache')
apply_manifest(config, v_config, 'setup.pp')
apply_manifest(config, v_config)
end
# Cobbler based "build" server
config.vm.define :build do |config|
get_box(config, 'precise64')
setup_networks(config, '100')
setup_hostname(config, 'build-server')
config.vm.customize ["modifyvm", :id, "--memory", 2525]
# Configure apt mirror
config.vm.provision :shell do |shell|
shell.inline = "sed -i 's/us.archive.ubuntu.com/%s/g' /etc/apt/sources.list" % v_config['apt_mirror']
end
# Ensure DHCP isn't going to join us to a domain other than domain.name
# since puppet has to sign its cert against the domain it makes when it runs.
config.vm.provision :shell do |shell|
shell.inline = "sed -i 's/\#supersede/supersede/g' /etc/dhcp/dhclient.conf; sed -i 's/fugue.com home.vix.com/%s/g' /etc/dhcp/dhclient.conf; sed -i 's/domain-name,//g' /etc/dhcp/dhclient.conf" % v_config['domain']
end
config.vm.provision :shell do |shell|
shell.inline = "%s apt-get update; dhclient -r eth0 && dhclient eth0;" % apt_cache_proxy
end
apply_manifest(config, v_config, 'setup.pp')
# pre-import the ubuntu image if we are using a custom mirror
if v_config['apt-mirror'] != 'us.archive.ubuntu.com'
config.vm.provision :shell do |shell|
shell.inline = "cobbler-ubuntu-import -c precise-x86_64; if [ $? == '0' ]; then apt-get install -y cobbler; cobbler-ubuntu-import -m http://%s/ubuntu precise-x86_64; fi" % v_config['apt_mirror']
end
end
apply_manifest(config, v_config)
# Configure puppet
config.vm.provision :shell do |shell|
shell.inline = 'if [ ! -h /etc/puppet/modules ]; then rmdir /etc/puppet/modules;ln -s /etc/puppet/modules-0 /etc/puppet/modules; fi;puppet plugin download --server build-server.domain.name;service apache2 restart'
end
# enable ip forwarding and NAT so that the build server can act
# as an external gateway for the quantum router.
config.vm.provision :shell do |shell|
shell.inline = "ip addr add 172.16.2.1/24 dev eth2; sysctl -w net.ipv4.ip_forward=1; iptables -A FORWARD -o eth0 -i eth1 -s 172.16.2.0/24 -m conntrack --ctstate NEW -j ACCEPT; iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT; iptables -t nat -F POSTROUTING; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE"
end
end
# Openstack control server
config.vm.define :control_pxe do |config|
config.vm.box = 'blank'
config.vm.boot_mode = 'gui'
config.ssh.port = 2727
setup_networks(config, '10', :eth1_mac => '001122334455')
end
# Openstack compute server
config.vm.define :compute_pxe do |config|
config.vm.box = 'blank'
config.vm.boot_mode = 'gui'
config.ssh.port = 2728
setup_networks(config, '10', :eth1_mac => '001122334466')
end
process_nodes(config, v_config, apt_cache_proxy)
end