CSIT-117: CSIT Vagrant+Virtualbox dev environment inoperative on Ubuntu
[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     echo "csit ALL=(root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/csit
24     sudo chmod 0440 /etc/sudoers.d/csit
25 SHELL
26
27 $install_prereqs = <<-SHELL
28     sudo apt-get -y update
29     sudo apt-get -y -f install
30     sudo apt-get -y install python-virtualenv python-dev iproute2 debhelper dkms
31     sudo update-alternatives --install /bin/sh sh /bin/bash 100
32 SHELL
33
34 $install_vpp = <<-SHELL
35     sudo apt-get -y purge vpp\*
36     cd /vagrant
37     vpp_pkgs="$(echo vpp*.deb)"
38     if [ "$vpp_pkgs" != "vpp*.deb" ]; then
39         sudo dpkg -i vpp*.deb
40     fi
41 SHELL
42
43
44 def add_dut(config, name, mgmt_ip, net1, net2)
45   config.vm.define name do |node|
46     node.vm.box = "fdio-csit/ubuntu-14.04.4_2016-05-25_1.0"
47     node.vm.hostname = name
48     node.vm.provision "shell", inline: $user_addition
49     node.vm.provision "shell", inline: $install_prereqs
50     node.vm.provision "shell", inline: $install_vpp
51
52     node.vm.network "private_network", ip: mgmt_ip
53     node.vm.network "private_network", type: "dhcp", auto_config: false,
54         virtualbox__intnet: net1
55     node.vm.network "private_network", type: "dhcp", auto_config: false,
56         virtualbox__intnet: net2
57     node.vm.provider "virtualbox" do |vb|
58       vb.memory = "3232"
59       vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
60       vb.customize ["modifyvm", :id, "--nicpromisc4", "allow-all"]
61     end
62   end
63
64 end
65
66 Vagrant.configure(2) do |config|
67   config.vm.box_check_update = false
68   config.vm.define "tg" do |tg|
69     if Vagrant.has_plugin?("vagrant-proxyconf")
70       if ENV["http_proxy"]
71         config.proxy.http     = ENV["http_proxy"]
72       end
73       if ENV["https_proxy"]
74         config.proxy.https    = ENV["https_proxy"]
75       end
76       if ENV["no_proxy"]
77         config.proxy.no_proxy = ENV["no_proxy"]
78       end
79     end
80     tg.vm.box = "fdio-csit/ubuntu-14.04.4_2016-05-25_1.0"
81     tg.vm.hostname = "tg"
82
83     tg.vm.provision "shell", inline: $user_addition
84     tg.vm.provision "shell", inline: $install_prereqs
85     tg.vm.network "private_network", ip: '192.168.255.100/24'
86     tg.vm.network "private_network", type: "dhcp", auto_config: false,
87         virtualbox__intnet: "tg_dut1"
88     tg.vm.network "private_network", type: "dhcp", auto_config: false,
89         virtualbox__intnet: "tg_dut2"
90     tg.vm.provider "virtualbox" do |vb|
91       vb.memory = "2048"
92       vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
93       vb.customize ["modifyvm", :id, "--nicpromisc4", "allow-all"]
94     end
95
96   end
97
98   add_dut(config, "dut1", "192.168.255.101/24", "tg_dut1", "dut1_dut2")
99   add_dut(config, "dut2", "192.168.255.102/24", "tg_dut2", "dut1_dut2")
100 end
101