Skip to content

Instantly share code, notes, and snippets.

@AdamIsrael
Last active August 29, 2015 14:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamIsrael/7ad1a5dd86f395060223 to your computer and use it in GitHub Desktop.
Save AdamIsrael/7ad1a5dd86f395060223 to your computer and use it in GitHub Desktop.
This is the Vagrantfile I use for my day-to-day work for Juju development and testing.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "trusty/juju"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-juju-vagrant-disk1.box"
config.vm.hostname = "jujubox"
config.vm.provider :virtualbox do |vb|
# Gratiously borrowed memory and cpu code from:
# https://stefanwrobel.com/how-to-make-vagrant-performance-not-suck
# Give VM 1/4 system memory & access to all cpu cores on the host
host = RbConfig::CONFIG['host_os']
if host =~ /darwin/
cpus = `sysctl -n hw.ncpu`.to_i
# sysctl returns Bytes and we need to convert to MB
mem = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 4
elsif host =~ /linux/
cpus = `nproc`.to_i
# meminfo shows KB and we need to convert to MB
mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 / 4
else # sorry Windows folks, I can't help you
cpus = 2
mem = 1024
end
vb.customize ["modifyvm", :id, "--memory", mem]
vb.customize ["modifyvm", :id, "--cpus", cpus]
# increase the cpu cap
# vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
###########################################################
# Configure routing so we can connect to lxc w/o sshuttle #
# $ vagrant plugin install vagrant-triggers #
###########################################################
config.trigger.after [:provision, :up, :reload] do
system('sudo route add -net 10.0.3.0/24 172.16.250.15 >/dev/null')
end
config.trigger.after [:halt, :destroy] do
system('sudo route delete -net 10.0.3.0/24 172.16.250.15 >/dev/null')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment