# -*- mode: ruby -*- # vi: ft=ruby:et:ts=2:sts=2:sw=2 VAGRANTFILE_API_VERSION = 2 require 'yaml' # # Defaults for Configuration data. # Will be overridden from the settings file # and (possibly later) from commandline parameters. # net_default = { :type => 'veth', :flags => 'up', :hwaddr => '', :name => '', :ipv4 => '', :ipv6 => '', } network_opts = [ :type, :link, :flags, :hwaddr, :name, :ipv4, :ipv6 ] libvirt_network_parms = { :hwaddr => :mac, :ipv4 => :ip, :ipv6 => '', :link => '', :flags => '', :type => '', } defaults = { :provider => { :libvirt => { :prefix => 'vagrant', :box => 'fedora/23-cloud-base', }, :virtualbox => { :prefix => 'vagrant', :box => 'fedora/23-cloud-base', }, }, } vms = [ { #:hostname => 'gluno1', :hostname => 'node1', #:box => 'local-fedora-rawhide-64', #:box => 'purpleidea-fedora-21', #:box => 'local-fedora-21.2', :provider => { :lxc => { :container_name => 'gluno1', #:container_name => 'node1', }, :libvirt => { :prefix => 'gluster', }, }, :internal_if => 'virbr1', :networks => [ { :link => 'virbr1', :ipv4 => '172.20.10.30', }, #{ # :link => 'virbr2', # #:ipv4 => '10.111.222.201', #}, ], }, ] # disks: hard-coded for all nodes for now: disks = [ { :size => 1, # in GB }, { :size => 10, }, ] # # Load the config, if it exists, # possibly override with commandline args, # (currently none supported yet) # and then store the config. # projectdir = File.expand_path File.dirname(__FILE__) f = File.join(projectdir, 'vagrant.yaml') if File.exists?(f) settings = YAML::load_file f if settings[:vms].is_a?(Array) vms = settings[:vms] end puts "Loaded settings from #{f}." end # TODO(?): ARGV-processing settings = { :vms => vms, } File.open(f, 'w') do |file| file.write settings.to_yaml end puts "Wrote settings to #{f}." # apply defaults: vms.each do |vm| defaults.keys.each do |cat| next if not vm.has_key?(cat) defaults[cat].keys.each do |subcat| next if not vm[cat].has_key?(subcat) defaults[cat][subcat].keys.each do |key| if not vm[cat][subcat].has_key?(key) vm[cat][subcat][key] = defaults[cat][subcat][key] end end end end #if not vm[:provider][:libvirt].has_key?(:prefix) # vm[:provider][:libvirt][:prefix] = default_libvirt_prefix #end vm[:networks].each do |net| net_default.keys.each do |key| if not net.has_key?(key) net[key] = net_default[key] end end end end # compose the list of cluster internal ips # cluster_internal_ips = vms.map do |vm| net = nil vm[:networks].each do |n| if n[:link] == vm[:internal_if] net = n break end end if net != nil net[:ipv4] end end #print "internal ips: " #print cluster_internal_ips #print "\n" NET_FIX_ALWAYS_SCRIPT = <