-
Notifications
You must be signed in to change notification settings - Fork 23
/
Vagrantfile
282 lines (235 loc) · 8.55 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
default_config_file = File.expand_path('configs/2-controllers-2-computes.yaml',
File.dirname(__FILE__))
config_file = ENV['VAGRANT_CONFIG_FILE'] || default_config_file
config = YAML.load_file(config_file)
vmdefaults = config['vms'].find {|vm| vm['name'] == 'DEFAULT' } || {}
admin_ip = config['networks']['crowbar']['admin_ip']
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
vagrantfile_api_version = '2'
Vagrant.configure(vagrantfile_api_version) do |vconfig|
vconfig.vm.provider :libvirt do |libvirt|
# libvirt.host = 'localhost'
# libvirt.username = 'root'
# libvirt.password = 'linux'
# libvirt.connect_via_ssh = true
# libvirt.storage_pool_name = 'default'
end
config['vms'].each_with_index do |vmcfg, i|
node_name = vmcfg['name']
next if node_name == 'DEFAULT'
primary = vmcfg['primary'] == 'true' ? true : false
personality = vmcfg['personality']
ip = personality == 'admin' \
? admin_ip
: config['networks']['crowbar']['pool_start'].
sub(/\.(\d+)$/) { '.%d' % ($1.to_i + i) }
vconfig.vm.define node_name, :primary => primary do |node|
box = vmcfg['box'] || vmdefaults['box']
node.vm.box = box if box
node.vm.box_check_update = false
# Setup NIC for admin network and for Crowbar in general.
# Vagrant requires the first interface of every VM to be NAT:
#
# https://docs.vagrantup.com/v2/virtualbox/boxes.html
#
# which with VirtualBox means it can't communicate with the
# other VMs. SUSE OpenStack Cloud needs at least one (other)
# interface which is able to communicate with other VMs.
# On VirtualBox this will result in it being made host-only.
node.vm.network 'private_network',
ip: ip,
auto_config: false,
libvirt__dhcp_enabled: false
# The override parameter lets us configure global config parameters
# per provider.
#
# See the 'OVERRIDING CONFIGURATION' section of
# http://docs.vagrantup.com/v2/providers/configuration.html and
# https://github.com/mitchellh/vagrant/issues/1867 for a full
# explanation.
node.vm.provider 'virtualbox' do |provider, override|
common_provider_settings(provider, vmcfg, vmdefaults)
# Don't use headless mode
provider.gui = true
virtualbox_nics(provider)
if vmcfg['sbd']
virtualbox_sbd_disk(provider, vmcfg['sbd'])
init_sbd_disk(override, '/dev/sdb')
end
virtualbox_drbd_disk(provider, node_name) if vmcfg['drbd']
end
node.vm.provider 'libvirt' do |provider, override|
common_provider_settings(provider, vmcfg, vmdefaults)
provider.volume_cache = 'unsafe'
if vmcfg['sbd']
libvirt_sbd_disk(provider)
init_sbd_disk(override, '/dev/vdb')
end
libvirt_drbd_disk(provider, node_name) if vmcfg['drbd']
provider.nested = true if personality == 'compute'
libvirt_mgmt_network(config, provider)
end
(vmcfg['forward_ports'] || []).each do |forward|
node.vm.network :forwarded_port,
host_ip:
ENV['VAGRANT_INSECURE_PORT_FORWARDS'] =~ /^(y(es)?|true|on)$/i ?
'*' : '127.0.0.1',
host: forward['host'],
guest: forward['guest']
end
if personality == 'admin'
provision_admin(node, admin_ip)
else
provision_non_admin(node, node_name, admin_ip)
end
if personality == 'controller'
provision_controller(node, admin_ip)
end
# admin.ssh.forward_agent = true
disable_default_synced_folder(node)
#admin.vm.synced_folder '/mnt/suse-cloud-7', '/srv/tftpboot/suse-12.2/repos/Cloud', type: 'nfs'
end
end
end
def common_provider_settings(provider, vmcfg, vmdefaults)
provider.memory = vmcfg['ram'] || vmdefaults['ram']
provider.cpus = vmcfg['cpus'] || vmdefaults['cpus']
end
def libvirt_drbd_disk(provider, node_name)
## create disk for DRBD
provider.storage :file,
path: "drbd-#{node_name}.qcow2",
size: '2100M',
device: 'vdc',
cache: 'unsafe'
end
def virtualbox_drbd_disk(provider, node_name)
## create disk for DRBD
provider.customize [
'createhd',
'--filename', "drbd-#{node_name}.vmdk",
'--size', 2100,
'--format', 'VMDK'
]
provider.customize [
'storageattach', :id,
'--storagectl', 'SCSI Controller',
'--port', 2,
'--device', 0,
'--type', 'hdd',
'--medium', "drbd-#{node_name}.vmdk",
]
end
def libvirt_sbd_disk(provider)
provider.storage :file,
path: 'sbd.img',
size: '8M',
device: 'vdb',
allow_existing: true,
shareable: true,
type: 'raw',
cache: 'none'
end
def virtualbox_sbd_disk(provider, mode)
if mode == 'create'
provider.customize [
'createhd',
'--filename', 'sbd.vmdk',
'--size', 8,
'--format', 'VMDK',
'--variant', 'Fixed'
]
provider.customize [ 'modifyhd', 'sbd.vmdk', '--type', 'shareable' ]
end
provider.customize [
'storageattach', :id,
'--storagectl', 'SCSI Controller',
'--port', 1,
'--device', 0,
'--type', 'hdd',
'--medium', 'sbd.vmdk',
]
end
def init_sbd_disk(override, device)
# Set up SBD disk
override.vm.provision 'shell', inline: <<-EOSHELL
zypper -n in sbd
/usr/sbin/sbd -d #{device} create
EOSHELL
end
def libvirt_mgmt_network(config, provider)
# The vagrant-libvirt provider requires a private management network:
#
# https://github.com/pradels/vagrant-libvirt
#
# This defaults to 192.168.121.0/24 but that's a bit too close to
# conventional OpenStack networks for comfort.
provider.management_network_address = config['networks']['management']
provider.management_network_name = 'vagrant-mgmt'
end
def virtualbox_nics(provider)
# Use AMD instead of Intel NICs to avoid VLAN problems
provider.customize [ 'modifyvm', :id, '--nictype1', 'Am79C973' ]
provider.customize [ 'modifyvm', :id, '--nictype2', 'Am79C973' ]
end
def provision_admin(admin, admin_ip)
files_to_provision = [
'network.json',
# Normally Crowbar seizes control of *all* interfaces. But in the Vagrant
# case we don't want it to touch eth0, so we need this evil patch:
'barclamp-network-ignore-eth0.patch',
# increase SBD timeout to 30 seconds since Vagrant environments
# can result in very sluggish VMs, especially when low on memory
'increase-SBD-timeout-30s.patch',
# fix for https://bugs.launchpad.net/nova/+bug/1691831 is not in a
# maintenance update yet, apply it manually
'apply-fix-lp#1691831.patch',
# handy utility for setting up node aliases in Crowbar
'setup-node-aliases.sh',
# sample input files for crowbar_batch
#'simple-cloud.yaml',
#'HA-cloud.yaml',
#'HA-cloud-no-compute.yaml',
'HA-compute-cloud.yaml',
'HA-compute-cloud-demo.yaml',
].map { |file| 'provisioning/admin/' + file }
provision_to_tmp(admin, files_to_provision)
admin.vm.provision 'shell', path: 'provisioning/admin/prep-admin.sh'
admin.vm.provision 'shell', path: 'provisioning/admin/provision-root-files.sh'
admin.vm.provision 'shell', path: 'provisioning/admin/switch-vdisks.sh'
admin.vm.provision 'shell', path: 'provisioning/admin/switch-admin-ip.sh',
args: admin_ip
# Automatically install SUSE OpenStack Cloud on first-boot
admin.vm.provision 'shell', path: 'provisioning/admin/install-suse-cloud.sh'
end
def provision_non_admin(node, node_name, admin_ip)
node.vm.provision 'shell', path: 'provisioning/non-admin/update-motd'
node.vm.provision 'shell', path: 'provisioning/non-admin/store-vagrant-name.sh',
args: node_name
node.vm.provision 'shell', path: 'provisioning/non-admin/register-with-suse-cloud',
args: admin_ip
node.vm.provision 'shell', path: 'provisioning/non-admin/deps-release'
end
def provision_controller(node, admin_ip)
files_to_provision = [
# utility to upload Cirros
'upload-cirros',
# script to start instance
'start-testvm',
].map { |file| 'provisioning/controller/' + file }
provision_to_tmp(node, files_to_provision)
node.vm.provision 'shell', path: 'provisioning/controller/provision-root-files.sh',
args: admin_ip
end
def provision_to_tmp(node, files_to_provision)
files_to_provision.each do |source|
filename = File.basename(source)
node.vm.provision 'file', source: source, destination: "/tmp/#{filename}"
end
end
def disable_default_synced_folder(node)
node.vm.synced_folder '.', '/vagrant', disabled: true
end