## © University of Southampton IT Innovation Centre, 2018
##
## Copyright in this software belongs to University of Southampton
## IT Innovation Centre of Gamma House, Enterprise Road,
## Chilworth Science Park, Southampton, SO16 7NS, UK.
##
## This software may not be used, sold, licensed, transferred, copied
## or reproduced in whole or in part in any manner or form or in or
## on any media by any person other than in accordance with the terms
## of the Licence Agreement supplied with the software, or otherwise
## without the prior written consent of the copyright owners.
##
## This software is distributed WITHOUT ANY WARRANTY, without even the
## implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE, except where stated in the Licence Agreement supplied with
## the software.
##
##      Created By :            Michael Boniface
##      Created Date :          18-12-2018
##      Created for Project :   FLAME

$lxc_script = <<-SCRIPT

apt-get update
apt-get install python3 python3-setuptools jq -y

# install util for persistent ip tables
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
apt-get -y install iptables-persistent

lxd init --auto --storage-backend dir 
lxc network create lxcbr0 ipv6.address=none ipv4.address=172.40.231.1/24 ipv4.nat=true

# enable NTP
# use network time to make sure we are synchronised
echo "Disabling timesyncd..."
timedatectl set-ntp no

# The following hangs with bionic
#until timedatectl | grep -m 1 "Network time on: no";
#do
#  echo "Waiting for timesyncd to turn off.."
#  sleep 1
#done

apt-get install ntp -y
echo "timesync set to ntpd"

# set timezone to London
timedatectl set-timezone Europe/London

SCRIPT

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.disksize.size = '50GB'
  config.vm.provider "virtualbox" do |vb|
    vb.cpus = 4
    vb.memory = "8192"
  end

  #config.vm.network "forwarded_port", guest: 8888, host: 8888

  # Install lxc
  config.vm.provision :shell, inline: $lxc_script
end