2 # vi: ft=ruby:et:ts=2:sts=2:sw=2
4 VAGRANTFILE_API_VERSION = "2"
11 f = ENV['AUTOCLUSTER_STATE'] + '/config.yml'
13 settings = YAML::load_file f
15 puts "Loaded config from #{f}."
20 u.host = Resolv.getaddress(u.host)
25 for i in 1..settings['shared_disks']['count']
26 shared_disk_ids[i] = sprintf('AUTO-%02d-', i) + SecureRandom.uuid[0..7]
30 # The vagrant machine definitions
33 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
35 if ENV['http_proxy'] or ENV['https_proxy']
36 if Vagrant.has_plugin?("vagrant-proxyconf")
38 config.proxy.http = resolvURL(ENV['http_proxy'])
41 config.proxy.https = resolvURL(ENV['https_proxy'])
43 config.proxy.no_proxy = "localhost,127.0.0.1"
47 if Vagrant.has_plugin?("vagrant-libvirt")
48 config.vm.provider :libvirt do |libvirt|
49 libvirt.storage_pool_name = "autocluster"
53 settings['nodes'].each do |hostname, node|
54 config.vm.define hostname do |v|
55 v.vm.box = settings['vagrant_box']
56 v.vm.hostname = hostname
58 node['ips'].each do |ip|
59 v.vm.network "private_network",
64 if settings['virthost']
65 virthost = settings['virthost']
66 v.vm.provision "shell",
68 inline: "ip route add default via " + virthost + " || :"
71 # No shared folders - they might require extra software on the
72 # nodes and installation can time out :-(
73 v.vm.synced_folder ".", "/vagrant", disabled: true
75 v.vm.provision "file",
76 source: "~/.ssh/id_autocluster",
77 destination: "~/.ssh/id_autocluster"
78 v.vm.provision "file",
79 source: "~/.ssh/id_autocluster.pub",
80 destination: "~/.ssh/id_autocluster.pub"
81 v.vm.provision :shell,
83 path: "autocluster_ssh_node_setup.sh"
85 v.vm.provider :libvirt do |libvirt|
87 libvirt.default_prefix = 'autocluster'
88 libvirt.cpus = settings['cpus']
89 libvirt.memory = settings['memory']
91 if node['has_shared_storage']
92 for i in 1..settings['shared_disks']['count']
93 libvirt.storage :file,
94 :serial => shared_disk_ids[i],
95 :path => sprintf('autocluster_%s_shared%02d.img',
96 settings['cluster'], i),
97 :size => settings['shared_disks'].size,
98 :allow_existing => true,
105 # The libvirt provider sometimes configures a private network
106 # but doesn't bring it up. Check that all desired IPs are
107 # assigned, failing if any are missing.
108 v.vm.provision "shell",
110 path: "autocluster_check_ips.sh",