# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|

  # Supervisor node
  config.vm.define "pope" do |pope|
    pope.vm.box = "debian/jessie64"
    pope.vm.hostname = "pxe-server"
    #pope.ssh.username ='root'
    #pope.ssh.insert_key = 'true'
    #pope.ssh.forward_x11 = 'true'
    #using rsync to fix nfs issues
    pope.vm.synced_folder "vagrant-lab/pxe-server-config", "/config", type: "rsync"
    pope.vm.network "private_network", ip: "192.168.0.254", libvirt__network_name: "pxe_network", :libvirt__dhcp_enabled => false, virtualbox__intnet: "pxe_network"

    pope.vm.provider :libvirt do |libvirt|
      libvirt.cpu_mode = 'host-passthrough'
      libvirt.memory = '1024'
      libvirt.cpus = '1'
    end

    pope.vm.provider :virtualbox do |vb|
      vb.memory = '1024'
      vb.cpus = '1'
      vb.gui = false
    end

    pope.vm.provision "shell", path: "vagrant-lab/pxe-server-config/setup.sh"

  end

  # The blades
  for i in 1..3
    config.vm.define "cardinal#{i}" do |cardinal|

      cardinal.vm.box = "ubuntu/bionic64"
      cardinal.vm.boot_timeout = 0

      # Handle PXE settings for libvirt
      cardinal.vm.provider :libvirt do |libvirt|
        libvirt.cpu_mode = 'host-passthrough'
        libvirt.memory = '1024'
        libvirt.cpus = '1'
        libvirt.storage :file, :size => '10G', :type => 'qcow2'
        libvirt.boot 'network'
        libvirt.mgmt_attach = 'false'
        libvirt.management_network_name = "pxe_network"
        libvirt.management_network_address = "192.168.0.0/24"
        libvirt.management_network_mode = "nat"
      end

      # Same for virtualbox
      cardinal.vm.provider :virtualbox do |vb|
        vb.memory = '1024'
        vb.cpus = '1'
        vb.gui = 'true'

        vb.customize [
          'modifyvm', :id,
          '--nic1', 'intnet',
          '--intnet1', 'pxe_network',
          '--boot1', 'net',
          '--boot2', 'none',
          '--boot3', 'none',
          '--boot4', 'none'
        ]

      end
    end
  end

end
