0355ad77301dcd30a8e4956803dac7a29fd60bc7
[csit.git] / resources / tools / vagrant / Vagrantfile
1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5
6 #     http://www.apache.org/licenses/LICENSE-2.0
7
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 # -*- mode: ruby -*-
15 # vi: set ts=2 sw=2 sts=2 et ft=ruby :
16
17 $user_addition = <<-SHELL
18     sudo deluser csit
19     sudo adduser --disabled-password --gecos "" csit
20     echo csit:csit | sudo chpasswd
21     sudo adduser csit vagrant
22     id csit
23 SHELL
24
25 $install_prereqs = <<-SHELL
26     sudo apt-get -y update
27     sudo apt-get -y -f install
28     sudo apt-get -y install python-virtualenv python-dev iproute2 debhelper dkms
29     sudo update-alternatives --install /bin/sh sh /bin/bash 100
30 SHELL
31
32 $install_vpp = <<-SHELL
33     cd /vagrant
34     vpp_pkgs="$(echo vpp*.deb)"
35     if [ "$vpp_pkgs" != "vpp*.deb" ]; then
36       if [ "$(dpkg -l | grep vpp)" != "" ] ; then
37         sudo apt-get -y purge vpp\*
38       fi
39       sudo dpkg -i vpp*.deb
40       vppcfg="/etc/vpp/startup.conf"
41       sudo rm -f $vppcfg.orig
42       sudo cp $vppcfg $vppcfg.orig
43       echo -e '\nheapsize 512M' | sudo tee -a $vppcfg
44     fi
45 SHELL
46
47
48 def add_dut(config, name, mgmt_ip, net1, net2)
49   config.vm.define name do |node|
50     node.vm.box = "puppetlabs/ubuntu-14.04-64-nocm"
51     node.vm.hostname = name
52     node.vm.provision "shell", inline: $user_addition
53     node.vm.provision "shell", inline: $install_prereqs
54     node.vm.provision "shell", inline: $install_vpp
55
56     node.vm.network "private_network", ip: mgmt_ip
57     node.vm.network "private_network", type: "dhcp", auto_config: false,
58         virtualbox__intnet: net1
59     node.vm.network "private_network", type: "dhcp", auto_config: false,
60         virtualbox__intnet: net2
61     node.vm.provider "virtualbox" do |vb|
62       vb.memory = "2048"
63       vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
64       vb.customize ["modifyvm", :id, "--nicpromisc4", "allow-all"]
65     end
66   end
67
68 end
69
70 Vagrant.configure(2) do |config|
71   if Vagrant.has_plugin?("vagrant-proxyconf")
72     if ENV["http_proxy"]
73       config.proxy.http     = ENV["http_proxy"]
74     end
75     if ENV["https_proxy"]
76       config.proxy.https    = ENV["https_proxy"]
77     end
78     if ENV["no_proxy"]
79       config.proxy.no_proxy = ENV["no_proxy"]
80     end
81   end
82   config.vm.define "tg" do |tg|
83     tg.vm.box = "puppetlabs/ubuntu-14.04-64-nocm"
84     tg.vm.hostname = "tg"
85
86     tg.vm.provision "shell", inline: $user_addition
87     tg.vm.provision "shell", inline: $install_prereqs
88     tg.vm.network "private_network", ip: '192.168.255.100/24'
89     tg.vm.network "private_network", type: "dhcp", auto_config: false,
90         virtualbox__intnet: "tg_dut1"
91     tg.vm.network "private_network", type: "dhcp", auto_config: false,
92         virtualbox__intnet: "tg_dut2"
93     tg.vm.provider "virtualbox" do |vb|
94       vb.memory = "2048"
95       vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
96       vb.customize ["modifyvm", :id, "--nicpromisc4", "allow-all"]
97     end
98
99   end
100
101   add_dut(config, "dut1", "192.168.255.101/24", "tg_dut1", "dut1_dut2")
102   add_dut(config, "dut2", "192.168.255.102/24", "tg_dut2", "dut1_dut2")
103 end
104