2 # vi: ft=ruby:et:ts=2:sts=2:sw=2
4 VAGRANTFILE_API_VERSION = 2
10 # Defaults for Configuration data.
11 # Will be overridden from the settings file
12 # and (possibly later) from commandline parameters.
24 network_opts = [ :type, :link, :flags, :hwaddr, :name, :ipv4, :ipv6 ]
26 libvirt_network_parms = {
46 #:hostname => 'gluno1',
48 #:box => 'local-fedora-rawhide-64',
49 #:box => 'purpleidea-fedora-21',
50 #:box => 'local-fedora-21.2',
53 :container_name => 'gluno1',
54 #:container_name => 'node1',
57 :box => 'local-fedora-21.2',
61 :internal_if => 'virbr1',
65 :ipv4 => '172.20.10.30',
69 # #:ipv4 => '10.111.222.201',
76 # Load the config, if it exists,
77 # possibly override with commandline args,
78 # (currently none supported yet)
79 # and then store the config.
82 projectdir = File.expand_path File.dirname(__FILE__)
83 f = File.join(projectdir, 'vagrant.yaml')
85 settings = YAML::load_file f
87 if settings[:vms].is_a?(Array)
90 puts "Loaded settings from #{f}."
93 # TODO(?): ARGV-processing
99 File.open(f, 'w') do |file|
100 file.write settings.to_yaml
102 puts "Wrote settings to #{f}."
108 defaults.keys.each do |cat|
109 next if not vm.has_key?(cat)
110 defaults[cat].keys.each do |subcat|
111 next if not vm[cat].has_key?(subcat)
112 defaults[cat][subcat].keys.each do |key|
113 if not vm[cat][subcat].has_key?(key)
114 vm[cat][subcat][key] = defaults[cat][subcat][key]
120 #if not vm[:provider][:libvirt].has_key?(:prefix)
121 # vm[:provider][:libvirt][:prefix] = default_libvirt_prefix
124 vm[:networks].each do |net|
125 net_default.keys.each do |key|
126 if not net.has_key?(key)
127 net[key] = net_default[key]
134 # compose the list of cluster internal ips
136 cluster_internal_ips = vms.map do |vm|
138 vm[:networks].each do |n|
139 if n[:link] == vm[:internal_if]
149 #print "internal ips: "
150 #print cluster_internal_ips
153 #PROVISION_SCRIPT = <<SCRIPT
154 #yum -y install make samba
157 NET_FIX_ALWAYS_SCRIPT = <<SCRIPT
159 # eth1 is not brought up automatically
160 # by 'vagrant up' of the existing vm
164 NET_FIX_INITIAL_SCRIPT = <<SCRIPT
166 # Fix dhclient running on private network IF
168 systemctl restart NetworkManager
172 INSTALL_SCRIPT = <<SCRIPT
174 yum -y install xfsprogs
175 yum -y install glusterfs{,-server,-fuse,-geo-replication}
176 yum -y install ctdb samba
179 XFS_SCRIPT = <<SCRIPT
184 DISKDEV="/dev/${DEVICE}"
185 DISKPARTDEV="/dev/${PARTDEV}"
187 MOUNTP=/export/${PARTDEV}
188 BRICKD=${MOUNTP}/brick
190 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
192 parted -s ${DISKDEV} mklabel msdos
193 parted -s ${DISKDEV} mkpart primary 1 100%
194 mkfs.xfs -f ${DISKPARTDEV}
199 test -f ${FILE} || touch ${FILE}
200 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
203 ${DISKPARTDEV} ${MOUNTP} xfs defaults 0 0
211 GLUSTER_START_SCRIPT = <<SCRIPT
213 systemctl start glusterd.service
216 #GLUSTER_PROBE_SCRIPT = <<SCRIPT
221 #gluster peer probe ${PEER_IP}
224 GLUSTER_PROBE_SCRIPT = <<SCRIPT
229 for PEER_IP in ${PEER_IPS}
231 gluster peer probe ${PEER_IP}
235 GLUSTER_CREATEVOL_SCRIPT = <<SCRIPT
242 echo "gluster volume create $VOLNAME rep $REP transport tcp $@"
243 gluster volume create $VOLNAME rep $REP transport tcp $@
245 gluster volume start $VOLNAME
248 GLUSTER_MOUNT_SCRIPT = <<SCRIPT
255 MOUNTDEV="127.0.0.1:/${VOLNAME}"
259 #mount -t glusterfs ${MOUNTDEV} ${MOUNTPT}
261 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
265 grep -q -s "${MOUNTPT}" || {
266 test -f ${FILE} || touch ${FILE}
267 cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
270 ${MOUNTDEV} ${MOUNTPT} glusterfs defaults,selinux 0 0
279 # The vagrant machine definitions
282 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
284 if Vagrant.has_plugin?("vagrant-cachier")
285 config.cache.scope = :box
288 vms.each do |machine|
289 config.vm.define machine[:hostname] do |node|
290 node.vm.box = machine[:provider][:libvirt][:box]
291 node.vm.hostname = machine[:hostname]
293 node.vm.provider :libvirt do |libvirt|
294 libvirt.default_prefix = machine[:provider][:libvirt][:prefix]
295 libvirt.memory = 1024
296 libvirt.storage :file, :size => '64M', :device => 'vdb'
297 libvirt.storage :file, :size => '10G', :device => 'vdc'
299 machine[:networks].each do |net|
300 if not net[:ipv4] == ''
301 node.vm.network :private_network, :ip => net[:ipv4]
306 # There is some problem with the fedora base box:
307 # We need to up the interface on reboots.
308 # It does not come up automatically.
309 node.vm.provision "net_fix_always", type: "shell", run: "always" do |s|
310 s.inline = NET_FIX_ALWAYS_SCRIPT
313 # There is some problem with the fedora base box:
314 # Upon first boot, ifdown eth1 fails and the dhclient
315 # keep being active. Simply bringing down and up again
316 # the interface is not sufficient. We need to restart
317 # NetworkManager in order to teach it to not feel
318 # responsible for the interface any more.
319 node.vm.provision "net_fix_initial", type: "shell" do |s|
320 s.inline = NET_FIX_INITIAL_SCRIPT
323 node.vm.provision :shell do |s|
324 s.inline = INSTALL_SCRIPT
327 # multiple privisioners with same name possible?
328 node.vm.provision "xfs", type: "shell" do |s|
329 s.inline = XFS_SCRIPT
330 #s.args = [ "vdb", "/export/gluster/brick1" ]
334 node.vm.provision "xfs", type: "shell" do |s|
335 s.inline = XFS_SCRIPT
336 #s.args = [ "vdc" , "/export/gluster/brick2" ]
340 node.vm.provision "gluster_start", type: "shell" do |s|
341 s.inline = GLUSTER_START_SCRIPT
344 node.vm.provision "gluster_probe", type: "shell" do |s|
345 s.inline = GLUSTER_PROBE_SCRIPT
346 s.args = cluster_internal_ips
349 node.vm.provision "gluster_createvol", type: "shell" do |s|
350 mount_points = cluster_internal_ips.map do |ip|
351 "#{ip}:/export/vdb1/brick"
353 s.inline = GLUSTER_CREATEVOL_SCRIPT
354 s.args = [ "gv0", "3" ] + mount_points
357 node.vm.provision "gluster_mount", type: "shell" do |s|
358 s.inline = GLUSTER_MOUNT_SCRIPT
359 s.args = [ "gv0", "/gluster/gv0" ]