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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|

  if Vagrant.has_plugin?("vagrant-cachier")
    config.cache.scope = :box
  end

  # Handle local proxy settings
  if Vagrant.has_plugin?("vagrant-proxyconf")
    if ENV["http_proxy"]
      config.proxy.http = ENV["http_proxy"]
    end
    if ENV["https_proxy"]
      config.proxy.https = ENV["https_proxy"]
    end
    if ENV["no_proxy"]
      config.proxy.no_proxy = ENV["no_proxy"] + ',192.168.10.6,10.0.2.15'
    end

  end

  config.vm.hostname = "devstack"
  config.vm.box = "bento/ubuntu-16.04"
  # config.vm.box_check_update = false
  config.vm.network "private_network",ip:"192.168.10.6"
  config.vm.synced_folder "~/", "/vagrant_home"

  config.vm.provider "virtualbox" do |vb|
    vb.gui = false
    vb.memory = "12800"
    vb.cpus = 4
    # vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
    # bento box bug workaround - https://github.com/chef/bento/issues/688
    vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
  end

  if !ENV['LOCAL_REPO'] || ENV['LOCAL_REPO'].empty?
    puts "Using default repo"
    local_repo_location = "../."
  else
    puts "Getting repo from ENV"
    local_repo_location = ENV['LOCAL_REPO']
  end

  repo_path = File.expand_path(local_repo_location)
  puts "Resolved repo at #{repo_path}"
  # push up our monasca-transform code
  config.vm.synced_folder local_repo_location, "/monasca-ceilometer-source"

  config.vm.provision "shell", privileged: false, path: "ceilosca.sh"
end
