-
Rowan Powell authoredRowan Powell authored
Vagrantfile 3.85 KiB
#/////////////////////////////////////////////////////////////////////////
#//
#// (c) University of Southampton IT Innovation Centre, 2017
#//
#// 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 : 13/12/2017
#// Created for Project : FLAME
#//
#/////////////////////////////////////////////////////////////////////////
# Requirements
require 'getoptlong'
require 'yaml'
# Custom options:
# --infra <infradir>
# Set defaults
DEFAULT_INFRA = "streaming"
# Define custom options
opts = GetoptLong.new(
[ '--infra', GetoptLong::OPTIONAL_ARGUMENT]
)
# Retrieve custom option values
infra = DEFAULT_INFRA
opts.each do |opt, arg|
case opt
when '--infra'
infra = arg
end
end
# load custom config file
puts "loading custom infrastructure configuration: #{infra}"
puts "custom config file: /infra/#{infra}/rspec.yml"
host_rspec_file = "infra/#{infra}/rspec.yml"
hosts = YAML.load_file(host_rspec_file)
# Start creating VMS using xenial64 as the base box
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
# Dynamic VMs
hosts['hosts'].each do |host|
#p host["name"]
instance_name = host["name"]
config.vm.define instance_name do |instance_config|
# Specify VM properties
instance_config.vm.hostname = instance_name
instance_config.disksize.size = host["disk"]
instance_config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", host["memory"]]
v.customize ["modifyvm", :id, "--cpus", host["cpus"]]
end
# Configure network
config.vm.network :private_network, ip: "#{host["ip_address"]}", virtualbox__intnet: "clmc-net"
# Port forwarding
puts "Forwarding the following specified ports for #{host["name"]}:"
host['forward_ports'].each do |port|
puts "Forwarding guest:#{port["guest"]} => host:#{port["host"]}"
config.vm.network "forwarded_port", guest: port["guest"], host: port["host"]
end
# Switch case added here to make clmc-service provisioning simple without having to have a complex rspec.yml file
# We only run a service installation script and the agent installation script when creating a specific service VM, not the clmc-service VM
case host
when 'clmc-service'
config.vm.provision :shell, :path => "scripts/clmc-service/#{host["install_script"]}"
config.vm.provision :shell, :path => "scripts/clmc-service/#{host["start_script"]}"
when (not 'clmc-service')
# specific service install
service_install_path = "test/services/#{host["service_name"]}/install-#{host["service_name"]}.sh"
puts "installing service script: #{service_install_path}"
config.vm.provision :shell, :path => service_install_path
# agent install
config.vm.provision :shell, :path => "scripts/clmc-agent/install-clmc-agent.sh", :args => "/vagrant/test/services/#{host["service_name"]}/telegraf_#{host["service_name"]}_template.conf #{host["location"]} #{host["sfc_id"]} #{host["sfc_id_instance"]} #{host["sf_id"]} #{host["sf_id_instance"]} #{host["ipendpoint_id"]} #{host["influxdb_url"]} #{host["database_name"]}"
end
end
end
end