CSIT-755: Presentation and analytics layer
[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, port1, port2, port3, port4)
45   config.vm.box_check_update = false
46   config.vm.define name do |node|
47     node.vm.box = "fdio-csit/ubuntu-14.04.4_2016-05-25_1.0"
48     node.vm.hostname = name
49     node.vm.provision "shell", inline: $user_addition
50     node.vm.provision "shell", inline: $install_prereqs
51     node.vm.provision "shell", inline: $install_vpp
52
53     node.vm.network "private_network", ip: mgmt_ip
54     node.vm.network "private_network", type: "dhcp", auto_config: false, virtualbox__intnet: port1
55     node.vm.network "private_network", type: "dhcp", auto_config: false, virtualbox__intnet: port2
56     node.vm.network "private_network", type: "dhcp", auto_config: false, virtualbox__intnet: port3
57     node.vm.network "private_network", type: "dhcp", auto_config: false, virtualbox__intnet: port4
58     node.vm.provider "virtualbox" do |vb|
59       vb.memory = "3232"
60       vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
61       vb.customize ["modifyvm", :id, "--nicpromisc4", "allow-all"]
62       vb.customize ["modifyvm", :id, "--nicpromisc5", "allow-all"]
63       vb.customize ["modifyvm", :id, "--nicpromisc6", "allow-all"]
64     end
65   end
66 end
67
68 net_prefix = ''
69 if ENV.key?('VPP_VAGRANT_NET_PREFIX')
70   net_prefix = ENV['VPP_VAGRANT_NET_PREFIX'] + '_'
71 end
72
73 def add_tg(config, name, mgmt_ip, port1, port2, port3, port4, port5, port6)
74   config.vm.box_check_update = false
75   config.vm.define name do |node|
76     if Vagrant.has_plugin?("vagrant-proxyconf")
77       if ENV["http_proxy"]
78         config.proxy.http     = ENV["http_proxy"]
79       end
80       if ENV["https_proxy"]
81         config.proxy.https    = ENV["https_proxy"]
82       end
83       if ENV["no_proxy"]
84         config.proxy.no_proxy = ENV["no_proxy"]
85       end
86     end
87     node.vm.box = "fdio-csit/ubuntu-14.04.4_2016-05-25_1.0"
88     node.vm.hostname = name
89     node.vm.provision "shell", inline: $user_addition
90     node.vm.provision "shell", inline: $install_prereqs
91
92     node.vm.network "private_network", ip: mgmt_ip
93     node.vm.network "private_network", type: "dhcp", auto_config: false, virtualbox__intnet: port1
94     node.vm.network "private_network", type: "dhcp", auto_config: false, virtualbox__intnet: port2
95     node.vm.network "private_network", type: "dhcp", auto_config: false, virtualbox__intnet: port3
96     node.vm.network "private_network", type: "dhcp", auto_config: false, virtualbox__intnet: port4
97     node.vm.network "private_network", type: "dhcp", auto_config: false, virtualbox__intnet: port5
98     node.vm.network "private_network", type: "dhcp", auto_config: false, virtualbox__intnet: port6
99     node.vm.provider "virtualbox" do |vb|
100       vb.memory = "2048"
101       vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
102       vb.customize ["modifyvm", :id, "--nicpromisc4", "allow-all"]
103       vb.customize ["modifyvm", :id, "--nicpromisc5", "allow-all"]
104       vb.customize ["modifyvm", :id, "--nicpromisc6", "allow-all"]
105       vb.customize ["modifyvm", :id, "--nicpromisc7", "allow-all"]
106       vb.customize ["modifyvm", :id, "--nicpromisc8", "allow-all"]
107     end
108   end
109 end
110
111 Vagrant.configure(2) do |config|
112   add_tg(config,  "tg",   "192.168.255.100/24", net_prefix + "tg_tg", net_prefix + "tg_tg", net_prefix + "tg_dut1_1", net_prefix + "tg_dut1_2", net_prefix + "tg_dut2_1", net_prefix + "tg_dut2_2")
113   add_dut(config, "dut1", "192.168.255.101/24", net_prefix + "tg_dut1_1", net_prefix + "tg_dut1_2", net_prefix + "dut1_dut2_1", net_prefix + "dut1_dut2_2")
114   add_dut(config, "dut2", "192.168.255.102/24", net_prefix + "tg_dut2_1", net_prefix + "tg_dut2_2", net_prefix + "dut1_dut2_1", net_prefix + "dut1_dut2_2")
115 end