Skip to content

Instantly share code, notes, and snippets.

@tknerr
Created October 9, 2014 05:26
Show Gist options
  • Save tknerr/b5ecc3d809fce8f22cbe to your computer and use it in GitHub Desktop.
Save tknerr/b5ecc3d809fce8f22cbe to your computer and use it in GitHub Desktop.
Devstackomat - a Vagrantfile to bring up DevStack
# -*- mode: ruby -*-
# vi: set ft=ruby :
HOST_IP = "192.168.33.2"
VM_NET = "192.168.27"
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
# set the hostname, otherwise qrouter will be lost upon reload
config.vm.hostname = "devstack"
# eth1, this will be the management endpoint
config.vm.network :private_network, ip: "#{HOST_IP}"
# eth2, this will be the "public" VM network
config.vm.network :private_network, ip: "#{VM_NET}.2", netmask: "255.255.255.0", auto_config: false
# virtual-box specific settings
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 4096]
# eth2 must be in promiscuous mode for floating IPs to be accessible
vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
end
config.vm.provision "shell", inline: <<-EOF
apt-get update
apt-get install git -y
git clone https://github.com/openstack-dev/devstack.git /home/vagrant/devstack
cd /home/vagrant/devstack && git checkout -b stable/icehouse origin/stable/icehouse
cat << CONF > /home/vagrant/devstack/local.conf
[[local|localrc]]
# Default passwords
ADMIN_PASSWORD=password
MYSQL_PASSWORD=password
RABBIT_PASSWORD=password
SERVICE_PASSWORD=password
SERVICE_TOKEN=password
SCREEN_LOGDIR=/opt/stack/logs
LOGFILE=/home/vagrant/devstack/stack.sh.log
INSTANCES_PATH=/home/vagrant/instances
FLAT_INTERFACE=eth2
PUBLIC_INTERFACE=eth2
HOST_IP=#{HOST_IP}
FIXED_RANGE=10.0.0.0/24
FLOATING_RANGE=#{VM_NET}.0/24
PUBLIC_NETWORK_GATEWAY=#{VM_NET}.2
Q_FLOATING_ALLOCATION_POOL=start=#{VM_NET}.3,end=#{VM_NET}.254
disable_service n-net
enable_service q-svc
enable_service q-agt
enable_service q-dhcp
enable_service q-l3
enable_service q-meta
enable_service neutron
CONF
# fix permissions as the cloned repo is owned by root
chown -R vagrant:vagrant /home/vagrant
# fix routing so that VMs can reach out to the internets
cat << SYSCTL > /etc/sysctl.d/60-devstack.conf
net.ipv4.conf.eth0.proxy_arp = 1
net.ipv4.ip_forward = 1
SYSCTL
sysctl --system
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# bring up eth2
ip link set dev eth2 up
# setup devstack
cd /home/vagrant/devstack
sudo -u vagrant env HOME=/home/vagrant ./stack.sh
# fix network setup to make VMs pingable from inside and outside devstack
ovs-vsctl add-port br-ex eth2
# make sure eth2 comes up and br-ex is properly configured after reboot
cat << ETH2 > /etc/network/interfaces.d/eth2.cfg
auto eth2
iface eth2 inet manual
ETH2
cat << BREX > /etc/network/interfaces.d/br-ex.cfg
auto br-ex
iface br-ex inet static
address #{VM_NET}.2
netmask 255.255.255.0
up ip route add 10.0.0.0/24 via #{VM_NET}.3 dev br-ex
BREX
# generate a keypair and make it available via share
ssh-keygen -t rsa -N "" -f /home/vagrant/.ssh/vm_key
cp -f /home/vagrant/.ssh/vm_key /vagrant/vm_key
# add the vagrant keypair and open up security groups
for user in admin demo; do
source openrc $user $user
nova keypair-add --pub-key /home/vagrant/.ssh/vm_key.pub default
nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
done
# use the google dns server as a sane default
source openrc admin admin
neutron subnet-update public-subnet --dns_nameservers list=true 8.8.8.8
neutron subnet-update private-subnet --dns_nameservers list=true 8.8.8.8
EOF
end
@tknerr
Copy link
Author

tknerr commented Oct 9, 2014

Once the DevStack VM is up and running, you should be able to boot an instance and assign a floating ip:

cd ~/devstack
source openrc demo demo

# boot a cirros instance
nova boot --flavor m1.nano --image cirros-0.3.2-x86_64-uec --key-name vagrant cirros
sleep 10
nova list

# assign a floating ip
device_id=`nova list --name cirros | tail -n2 | head -n1 | awk '{print $2}'`
port_id=`neutron port-list -c id -- --device_id $device_id | tail -n2 | head -n1 | awk '{print $2}'`
neutron floatingip-create public --port-id $port_id

Once the floating ip is assigned, you should be able to:

  • ping the cirros VM from inside the DevStack VM
  • ping the cirros VM from outside the DevStack VM (i.e. from your host)
  • ssh into the cirros VM from your host via ssh -i ./my_key cirros@<floatingip>
  • reach out to the internets from within the cirros VM
  • talk to other other cirros VMs in the same tenant's network via their private and public ip

The network configuration is persistent and will happily survive a vagrant reload. However, after restarting the VM you have to bring up devstack again:

cd devstack
./rejoin-stack.sh
<ctrl + a + d>  # detach screen session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment