# -*- 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|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # define machine in specific scope so that we can have a machines active
  # from multiple git branches.
  config.vm.define "ehx", primary: true do |machine|
    # Every Vagrant development environment requires a box. You can search for
    # boxes at https://atlas.hashicorp.com/search.
    machine.vm.box = "centos/7"
    machine.vm.box_version = "1902.01"

    machine.vm.hostname = "ehx"

    # Create a forwarded port mapping which allows access to a specific port
    # within the machine from a port on the host machine. In the example below,
    # accessing "localhost:8080" will access port 80 on the guest machine.
    # config.vm.network "forwarded_port", guest: 80, host: 8080

    # Share an additional folder to the guest VM. The first argument is
    # the path on the host to the actual folder. The second argument is
    # the path on the guest to mount the folder. And the optional third
    # argument is a set of non-required options.
    # config.vm.synced_folder "../data", "/vagrant_data"

    # Provider-specific configuration so you can fine-tune various
    # backing providers for Vagrant. These expose provider-specific options.
    # Example for VirtualBox:
    #
    machine.vm.provider "virtualbox" do |vb, override|
      vb.name = "ehx"

      # Display the VirtualBox GUI when booting the machine
      vb.gui = false

      # Customize the amount of memory on the VM:
      vb.memory = "8192"
      vb.cpus = "2"

      # sync the time of the guest with that of the host if it drifts more than 1 second.
      vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000 ]

      # set auto_update to false, if you do NOT want to check the correct
      # additions version when booting this machine
      override.vbguest.auto_update = true

      # do NOT download the iso file from a webserver
      override.vbguest.no_remote = true

      override.vm.synced_folder ".", "/vagrant", disabled: true
      override.vm.synced_folder ".", "/ehx", type: "virtualbox"
      override.vm.synced_folder "weblogic/domains/ehx_devl/autodeploy", "/u01/app/domains/ehx_devl/autodeploy", type: "virtualbox"
      override.vm.synced_folder "weblogic/domains/ehx_devl/servers/admin/logs", "/u01/app/domains/ehx_devl/servers/admin/logs", type: "virtualbox"
      override.vm.network "forwarded_port", guest: 7001, host: 7001, host_ip: "localhost"
      override.vm.network "forwarded_port", guest: 7002, host: 7002, host_ip: "localhost"
      override.vm.network "forwarded_port", guest: 1521, host: 7521, host_ip: "localhost"
      override.vm.network "forwarded_port", guest: 4000, host: 7004, host_ip: "localhost"
      override.vm.network "forwarded_port", guest: 5140, host: 5140, host_ip: "localhost"
      override.vm.network "forwarded_port", guest: 443, host: 7443, host_ip: "localhost"
      override.vm.network "forwarded_port", guest: 80, host: 7080, host_ip: "localhost"
    end

    machine.vm.provider "hyperv" do |vb, override|
      vb.vmname = "ehx"
      vb.memory = "8192"
      vb.cpus   = "2"

      override.vm.synced_folder ".", "/vagrant", disabled: true
      override.vm.synced_folder ".", "/ehx", type: "smb", mount_options: ["username=<windows_username>","password=<windows_password>"]
      override.vm.synced_folder "weblogic/domains/ehx_devl/autodeploy", "/u01/app/domains/ehx_devl/autodeploy", type: "smb", mount_options: ["username=<windows_username>","password=<windows_password>"]
      override.vm.synced_folder "weblogic/domains/ehx_devl/servers/admin/logs", "/u01/app/domains/ehx_devl/servers/admin/logs", type: "smb", mount_options: ["username=<windows_username>","password=<windows_password>"]
    end

    # ssh login using username/password (uncomment if you're using Vagrant 1.85).
    #machine.ssh.username = "vagrant"
    #machine.ssh.password = "vagrant"
    #machine.ssh.insert_key = true
    machine.ssh.forward_agent = true
    machine.ssh.forward_x11 = true

    # sync VMs timezone to hosts.
    if Vagrant.has_plugin?("vagrant-timezone")
      config.timezone.value = :host
    end

    # Enable provisioning with a shell script. Additional provisioners such as
    # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
    # documentation for more information about their specific syntax and use.
    machine.vm.provision "shell", inline: <<-SHELL
     . /ehx/vagrant-scripts/provision.sh
    SHELL
    machine.vm.provision "shell", run: "always", inline: <<-SHELL2
     . /ehx/vagrant-scripts/run.sh
    SHELL2
 end
end
