Launch VM using Vagrant - hqzhang/cloudtestbed GitHub Wiki
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Require the reboot plugin.
require './vagrant-provision-reboot-plugin'
$NUM_CPUS = (ENV['NUM_CPUS'] || 1).to_i
$MEMORY = (ENV['MEMORY'] || 1024).to_i
$IFACE = (ENV['BRIDGE_IFACE'] || "eth0")
$num_node = (ENV['NUM_NODES'] || 1).to_i
$mgmt_ip_base = "192.168.56."
$node_ip_base = "192.168.57."
$first_ip_suffix = "11"
$mgmt_ips = $num_node.times.collect { |n| $mgmt_ip_base + "#{$first_ip_suffix.to_i + n }"}
$node_ips = $num_node.times.collect { |n| $node_ip_base + "#{$first_ip_suffix.to_i + n }"}
Vagrant.configure("2") do |config|
#config.vm.box_url = "file:///tmp/ican.box"
config.vm.box = "ubuntu/xenial64"
#use common public key
config.ssh.insert_key = false
config.ssh.private_key_path = File.expand_path('~/.ssh/id_rsa')
config.ssh.forward_agent = true
config.ssh.username = 'ubuntu'
config.vm.provider "virtualbox" do |vb|
vb.memory = $MEMORY
vb.cpus = $NUM_CPUS
#config.vm.synced_folder '.', '/home/vagrant/iCan', type: "rsync"
vb.customize ['modifyvm', :id, '--nictype1', 'Am79C973']
vb.customize ['modifyvm', :id, '--nictype2', 'Am79C973']
vb.customize ['modifyvm', :id, '--nictype3', 'Am79C973']
vb.customize ['modifyvm', :id, '--nicpromisc1', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc3', 'allow-all']
end
$num_node.times do |i|
node_vm_name = "iCan-#{i}"
config.vm.define node_vm_name do |node|
node.vm.hostname = node_vm_name
node.vm.synced_folder "../../", "/tmp/ican-plus"
mgmt_ip = $mgmt_ips[i]
node_ip = $node_ips[i]
node.vm.provision "shell" do |s|
ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
s.inline = <<-SHELL
echo #{ssh_pub_key} >> /home/ubuntu/.ssh/authorized_keys
echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
SHELL
end
#apt-get
node.vm.provision "install_upstart", type: "shell", run: "once", privileged: true, inline: $install_upstart
node.vm.provision :unix_reboot
node.vm.provision "bootstrap", type: "shell", run: "once", privileged: true, inline: $bootstrap
node.vm.provision "postinstall", type: "shell", run: "once", privileged: true, inline: $postinstall
#network
node.vm.network "private_network", ip: "#{mgmt_ip}"
node.vm.network "public_network", bridge: $IFACE, ip: "#{node_ip}"
node.vm.provision "shell", inline: <<-EOC
echo '
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0' >> /etc/sysctl.conf
sysctl net.bridge.bridge-nf-call-ip6tables=0
sysctl net.bridge.bridge-nf-call-iptables=0
sysctl net.bridge.bridge-nf-call-arptables=0
EOC
end
end
end