nat: use correct data types for memory sizes
[vpp.git] / extras / vagrant / Vagrantfile
1 # -*- mode: ruby -*-
2 # vi: set ft=ruby :
3
4 Vagrant.configure(2) do |config|
5
6   # Pick the right distro and bootstrap, default is ubuntu1604
7   distro = ( ENV['VPP_VAGRANT_DISTRO'] || "ubuntu1604")
8   if distro == 'centos7'
9     config.vm.box = "centos/7"
10     config.vm.box_version = "1708.01"
11     config.ssh.insert_key = false
12   elsif distro == 'opensuse'
13     config.vm.box = "opensuse/openSUSE-42.3-x86_64"
14     config.vm.box_version = "1.0.4.20170726"
15   elsif distro == 'ubuntu1804'
16     config.vm.box = "bento/ubuntu-18.04"
17   else
18     config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm"
19   end
20   config.vm.box_check_update = false
21
22   config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"update.sh")
23   config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"build.sh"), :args => "/vpp vagrant"
24
25   post_build = ( ENV['VPP_VAGRANT_POST_BUILD'] )
26   if post_build == "test"
27     config.vm.provision "shell", inline: "echo Testing VPP; cd /vpp; make test"
28   elsif post_build == "install"
29     config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"install.sh"), :args => "/vpp"
30     config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"clearinterfaces.sh")
31     config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"run.sh")
32   end
33
34   # Add .gnupg dir in so folks can sign patches
35   # Note, as gnupg puts socket files in that dir, we have
36   # to be cautious and make sure we are dealing with a plain file
37   homedir = File.expand_path("~/")
38   Dir["#{homedir}/.gnupg/**/*"].each do |fname|
39     if File.file?(fname)
40       destname = fname.sub(Regexp.escape("#{homedir}/"),'')
41       config.vm.provision "file", source: fname, destination: destname
42     end
43   end
44
45   # Copy in the .gitconfig if it exists
46   if File.file?(File.expand_path("~/.gitconfig"))
47     config.vm.provision  "file", source: "~/.gitconfig", destination: ".gitconfig"
48   end
49
50   # vagrant-cachier caches apt/yum etc to speed subsequent
51   # vagrant up
52   # to enable, run
53   # vagrant plugin install vagrant-cachier
54   #
55   if Vagrant.has_plugin?("vagrant-cachier")
56     config.cache.scope = :box
57   end
58
59   # Define some physical ports for your VMs to be used by DPDK
60   nics = (ENV['VPP_VAGRANT_NICS'] || "2").to_i(10)
61   for i in 1..nics
62     config.vm.network "private_network", type: "dhcp"
63   end
64
65   # use http proxy if avaiable
66   if ENV['http_proxy'] && Vagrant.has_plugin?("vagrant-proxyconf")
67    config.proxy.http     = ENV['http_proxy']
68    config.proxy.https    = ENV['https_proxy']
69    config.proxy.no_proxy = "localhost,127.0.0.1"
70   end
71
72   vmcpu=(ENV['VPP_VAGRANT_VMCPU'] || 2)
73   vmram=(ENV['VPP_VAGRANT_VMRAM'] || 4096)
74
75   config.ssh.forward_agent = true
76   config.ssh.forward_x11 = true
77
78   config.vm.provider "virtualbox" do |vb|
79       vb.customize ["modifyvm", :id, "--ioapic", "on"]
80       vb.memory = "#{vmram}"
81       vb.cpus = "#{vmcpu}"
82
83       # rsync the vpp directory if provision hasn't happened yet
84       unless File.exist? (".vagrant/machines/default/virtualbox/action_provision")
85         config.vm.synced_folder "../../", "/vpp", type: "rsync",
86          rsync__auto: false,
87          rsync__exclude: [
88           "build-root/build*/",
89           "build-root/install*/",
90           "build-root/images*/",
91           "build-root/*.deb",
92           "build-root/*.rpm",
93           "build-root/*.changes",
94           "build-root/python",
95           "build-root/deb/debian/*.dkms",
96           "build-root/deb/debian/*.install",
97           "build-root/deb/debian/changes",
98           "build-root/tools"]
99       end
100
101       #support for the SSE4.x instruction is required in some versions of VB.
102       vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"]
103       vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"]
104   end
105   config.vm.provider "vmware_fusion" do |fusion,override|
106     fusion.vmx["memsize"] = "#{vmram}"
107     fusion.vmx["numvcpus"] = "#{vmcpu}"
108   end
109   config.vm.provider "libvirt" do |lv|
110     lv.memory = "#{vmram}"
111     lv.cpus = "#{vmcpu}"
112   end
113   config.vm.provider "vmware_workstation" do |vws,override|
114     vws.vmx["memsize"] = "#{vmram}"
115     vws.vmx["numvcpus"] = "#{vmcpu}"
116   end
117 end