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