forked from SUSE-Cloud/suse-cloud-appliances
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
285 lines (235 loc) · 8.47 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
284
285
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
default_config_file = File.expand_path('configs/2-controllers-1-compute.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 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)
virtualbox_nics(provider)
virtualbox_drbd_disk(provider, node_name) if vmcfg['drbd']
if vmcfg['sbd']
virtualbox_sbd_disk(provider, vmcfg['sbd'])
init_sbd_disk(override, '/dev/sdc')
end
end
node.vm.provider 'libvirt' do |provider, override|
common_provider_settings(provider, vmcfg, vmdefaults)
provider.volume_cache = 'none'
libvirt_drbd_disk(provider, node_name) if vmcfg['drbd']
if vmcfg['sbd']
libvirt_sbd_disk(provider)
init_sbd_disk(override, '/dev/vdc')
end
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)
else
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
end
setup_glance_NFS(node, admin_ip) if vmcfg['glance-nfs']
# admin.ssh.forward_agent = true
disable_default_synced_folder(node)
#admin.vm.synced_folder '/mnt/suse-cloud-4', '/srv/tftpboot/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']
# Don't use headless mode
provider.gui = true
end
def libvirt_drbd_disk(provider, node_name)
## create disk for DRBD
provider.storage :file,
path: "drbd-#{node_name}.qcow2",
size: '2100M',
device: 'vdb',
cache: 'none'
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', 1,
'--device', 0,
'--type', 'hdd',
'--medium', "drbd-#{node_name}.vmdk",
]
end
def libvirt_sbd_disk(provider)
provider.storage :file,
path: 'sbd.qcow2',
size: '8M',
device: 'vdc',
allow_existing: true,
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', 2,
'--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 setup_glance_NFS(node, admin_ip)
node.vm.provision 'shell',
path: 'provisioning/controller/setup-glance-NFS.sh',
args: admin_ip
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)
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',
# Provide NFS export to share /var/lib/glance
'barclamp-provisioner-nfs-export.patch',
# another evil hack to avoid a crasher when applying the keystone
# barclamp
'barclamp-pacemaker-ignore-target-role-changes.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',
# handy utility for setting up node aliases in Crowbar
'setup-node-aliases.sh',
# handy utility for configuring proposals in batch
'crowbar_batch',
# update to library required by crowbar_batch
'barclamp_lib.rb',
# gem required by crowbar_batch
'easy_diff-0.0.3.gem',
# sample input files for crowbar_batch
'simple-cloud.yaml',
'HA-cloud.yaml',
'HA-cloud-no-compute.yaml',
# handy utility for dealing with nodes/roles via knife
'node-sh-vars',
].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'
# Automatically install SUSE Cloud on first-boot
admin.vm.provision 'shell', path: 'provisioning/admin/install-suse-cloud.sh'
admin.vm.provision 'shell', path: 'provisioning/admin/switch-vdisks.sh'
admin.vm.provision 'shell', path: 'provisioning/admin/setup-node-sh-vars.sh'
admin.vm.provision 'shell', inline: <<-'EOSHELL'
set -e
cd /opt/dell
patch -p1 < /tmp/increase-SBD-timeout-30s.patch
/opt/dell/bin/barclamp_install.rb --rpm pacemaker
EOSHELL
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