3e18192bec0e969c68df25cc8a62d318666a1f13
[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     sudo apt-get -y purge vpp\*
34     cd /vagrant
35     if [ -e /vagrant/vpp-*.deb ]; then
36         sudo dpkg -i vpp-*.deb
37     fi
38 SHELL
39
40
41 def add_dut(config, name, mgmt_ip, net1, net2)
42   config.vm.define name do |node|
43     node.vm.box = "puppetlabs/ubuntu-14.04-64-nocm"
44     node.vm.hostname = name
45     node.vm.provision "shell", inline: $user_addition
46     node.vm.provision "shell", inline: $install_prereqs
47     node.vm.provision "shell", inline: $install_vpp
48
49     node.vm.network "private_network", ip: mgmt_ip
50     node.vm.network "private_network", type: "dhcp", auto_config: false,
51         virtualbox__intnet: net1
52     node.vm.network "private_network", type: "dhcp", auto_config: false,
53         virtualbox__intnet: net2
54     node.vm.provider "virtualbox" do |vb|
55       vb.memory = "2048"
56       vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
57       vb.customize ["modifyvm", :id, "--nicpromisc4", "allow-all"]
58     end
59   end
60
61 end
62
63 Vagrant.configure(2) do |config|
64   config.vm.define "tg" do |tg|
65     tg.vm.box = "puppetlabs/ubuntu-14.04-64-nocm"
66     tg.vm.hostname = "tg"
67
68     tg.vm.provision "shell", inline: $user_addition
69     tg.vm.provision "shell", inline: $install_prereqs
70     tg.vm.network "private_network", ip: '192.168.255.100/24'
71     tg.vm.network "private_network", type: "dhcp", auto_config: false,
72         virtualbox__intnet: "tg_dut1"
73     tg.vm.network "private_network", type: "dhcp", auto_config: false,
74         virtualbox__intnet: "tg_dut2"
75     tg.vm.provider "virtualbox" do |vb|
76       vb.memory = "2048"
77       vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
78       vb.customize ["modifyvm", :id, "--nicpromisc4", "allow-all"]
79     end
80
81   end
82
83   add_dut(config, "dut1", "192.168.255.101/24", "tg_dut1", "dut1_dut2")
84   add_dut(config, "dut2", "192.168.255.102/24", "tg_dut2", "dut1_dut2")
85 end
86