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

#
# A Vagrantfile template that can be used for creating machines for libblockdev
# development/testing.
#
# Use 'vagrant up && vagrant ssh' to spawn the default machine (most recent
# Fedora) and ssh into it or e.g. 'vagrant up bl-f42 && vagrant ssh bl-f42' to
# use a Fedora 42 based machine, etc.
#

def os_cpu_cores
  case RbConfig::CONFIG['host_os']
  when /darwin/
    Integer(`sysctl -n hw.ncpu`)
  when /linux/
    Integer(`getconf _NPROCESSORS_ONLN`)
  else
    raise StandardError, "Unsupported platform"
  end
end

Vagrant.configure("2") do |config|
  # common configuration

  config.vm.synced_folder "../", "/home/vagrant/blivet/",
                          type: "rsync", rsync__args: ["-a", "-l", "--exclude=misc"]  # override the default args

  # CHECK THAT THE BELOW OPTIONS ARE OKAY FOR YOUR HW
  config.vm.provider :libvirt do |v|
    v.memory = "2048"
    v.cpus = os_cpu_cores
    v.disk_driver :cache => "unsafe"
  end

  config.vm.define "bl-f42", primary: true, autostart: true do |f42|
    f42.vm.box = "fedora/42-cloud-base"

    f42.vm.provision "ansible" do |ansible|
      ansible.playbook = "install-test-dependencies.yml"
      ansible.extra_vars = { ansible_python_interpreter:"/usr/bin/python3" }
    end
  end

  config.vm.define "bl-f41", primary: false, autostart: false do |f41|
    f41.vm.box = "fedora/41-cloud-base"

    f41.vm.provision "ansible" do |ansible|
      ansible.playbook = "install-test-dependencies.yml"
      ansible.extra_vars = { ansible_python_interpreter:"/usr/bin/python3" }
    end
  end

  config.vm.define "bl-c9s", primary: false, autostart: false do |c9s|
    c9s.vm.box = "centos/stream9"

    # install all test dependencies using ansible
    c9s.vm.provision "ansible" do |ansible|
      ansible.playbook = "install-test-dependencies.yml"
      ansible.extra_vars = { ansible_python_interpreter:"/usr/libexec/platform-python" }
    end
  end

  config.vm.define "bl-c10s", primary: false, autostart: false do |c10s|
    c10s.vm.box = "centos/stream10"

    # install all test dependencies using ansible
    c10s.vm.provision "ansible" do |ansible|
      ansible.playbook = "install-test-dependencies.yml"
      ansible.extra_vars = { ansible_python_interpreter:"/usr/libexec/platform-python" }
    end
  end

  config.vm.define "bl-u2404", primary: false, autostart: false do |u2404|
    u2404.vm.box = "generic/ubuntu2404"

    # install all test dependencies using ansible
    u2404.vm.provision "ansible" do |ansible|
      ansible.playbook = "install-test-dependencies.yml"
      ansible.extra_vars = { ansible_python_interpreter:"/usr/bin/python3" }
    end
  end

  config.vm.define "bl-debiant", primary: false, autostart: false do |debiant|
    debiant.vm.box = "debian/testing64"

    # install all test dependencies using ansible
    debiant.vm.provision "ansible" do |ansible|
      ansible.playbook = "install-test-dependencies.yml"
      ansible.extra_vars = { ansible_python_interpreter:"/usr/bin/python3" }
    end
  end
end
