# -*- mode: ruby -*-
# vi: set ft=ruby :
#

NODES = 4
DISKS = 8

DRIVE_SIZE = "500G"
VM_MEM_MB = 1024
VM_CPU_COUNT = 2

Vagrant.configure("2") do |config|
    config.ssh.insert_key = false

    config.vm.provider :libvirt do |v,override|
        override.vm.box = "centos/7"
        override.vm.synced_folder '.', '/home/vagrant/sync', disabled: true
        # change cpu mode to passthrough as workaround, refer bugs:
        #https://bugzilla.redhat.com/show_bug.cgi?id=1467599
        #https://bugzilla.redhat.com/show_bug.cgi?id=1386223#c10
        #vagrant-libvirt/vagrant-libvirt#667
        v.cpu_mode = 'host-passthrough'
    end

    # Make the glusterfs cluster, each with DISKS number of drives
    (0..NODES-1).each do |i|
        config.vm.define "storage#{i}" do |testvm|
            testvm.vm.hostname = "storage#{i}"
            localoctet = 100+i
            testvm.vm.network :private_network, ip: "192.168.10.#{localoctet}"
            driverletters = ('b'..'z').to_a
            testvm.vm.provider :libvirt do  |lv|
                lv.memory = VM_MEM_MB
                lv.cpus = VM_CPU_COUNT
                (0..DISKS-1).each do |d|
                    lv.storage :file, :device => "vd#{driverletters[d]}", :path => "heketi_testvm_disk-#{i}-#{d}.disk", :size => "#{DRIVE_SIZE}"
                end
            end

            if i == (NODES-1)
                testvm.vm.provision :ansible do |ansible|
                    ansible.limit = "all"
                    ansible.playbook = "site.yml"
                    ansible.groups = {
                        "client" => ["client"],
                        "heketi" => ["storage0"],
                        "gluster" => (0..NODES-1).map {|j| "storage#{j}"},
                    }
                end
            end
        end
    end
end
