Skip to content

Instantly share code, notes, and snippets.

@djoreilly
Last active August 29, 2015 14:03
Show Gist options
  • Save djoreilly/dbfee32346f87bee6e2e to your computer and use it in GitHub Desktop.
Save djoreilly/dbfee32346f87bee6e2e to your computer and use it in GitHub Desktop.
Vagrantfile with extra nets, disks and proxies
# -*- mode: ruby -*-
# vi: set ft=ruby :
# increment this so it is unique
$eth1_ip = "192.168.2.2"
def add_disk(vb, vm_id, port_num, size)
# sata port_num should be unique > 0
# size is in GB
# notes: will only work if the image uses a sata controller.
# The images from cloud-images.ubuntu.com use sata.
# vagrant destroy will not remove the backing files - use the
# media manager from the virtualbox gui instead
img_file = "disk_port%d.vdi" % port_num
unless File.exist?(img_file)
vb.customize ['createhd', '--filename', img_file, '--size', size * 1024]
end
vb.customize ['storageattach', vm_id, '--storagectl', 'SATAController',
'--port', port_num, '--device', 0, '--type', 'hdd', '--medium', img_file]
end
Vagrant.configure("2") do |config|
config.vm.box = "trusty"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
config.vm.hostname = "devstack"
# forward ssh keys from main host - handy for gerrit and github
config.ssh.forward_agent = true
# Add additional network interface - will appear as eth1.
# It's plugged to a VB host-only network, so its IP can be accessed
# directly from the main host without nat port-forwarding hassle.
config.vm.network :private_network, ip: $eth1_ip
# Add eth2 and eth3 - these can be used by Neutron or nova-network
# It's necessary to specify IPs here - but they won't be configured in the VM.
config.vm.network :private_network, ip: "192.168.3.2", auto_config: false
config.vm.network :private_network, ip: "192.168.4.2", auto_config: false
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--cpus", "4"]
vb.customize ["modifyvm", :id, "--memory", "5000"]
# enable serial port just in case vagrant image does not
vb.customize ["modifyvm", :id, "--uart1", "0x3F8", 4]
# add a 20GB disk - will appear as /dev/sdb
add_disk(vb, :id, 1, 20)
# add a 30GB disk - will appear as /dev/sdc
add_disk(vb, :id, 2, 30)
end
cmd = "echo export http_proxy=http://%{host}:%{port} >> %{bashrc}\n" \
"echo export https_proxy=https://%{host}:%{port} >> %{bashrc}\n" \
"echo export no_proxy=localhost,127.0.0.1,%{eth1_ip} >> %{bashrc}\n" \
% {host: 'web-proxy.europe.hp.com', port: '8080',
bashrc: '/home/vagrant/.bashrc', eth1_ip: $eth1_ip}
config.vm.provision "shell", inline: cmd, privileged: false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment