Devstack with Vagrant, Quick and Dirty

Devstack with Vagrant

You can test the openstack with vagrant using devstack. We will assume that you have Vagrant, virtualbox and git installed on your computer, and configure virtualBox as the default provider. Following tutorial was created to make your life easier, especially when implementing devstack to build an openstack development environment for demo or training to end users.

Step 1: Create a new vagrant box

Execute the following commands to create a new Vagrant box:

C:\pseudo\Vagrant>mkdir devstack
C:\pseudo\Vagrant>cd devstack
C:\pseudo\Vagrant\devstack>vagrant init

There is now a Vagrantfile in the current directory

Step 2: Modify Vagrantfile

We use bento/ubuntu-16.04 boxes as base images.

Vagrant.configure("2") do |config|
  config.vm.box = "bento/ubuntu-16.04"
  config.vm.hostname = 'devstack'

# We also expose the port to the devstack interface, this will create port mapping, and set the network interface IP Address

config.vm.network "forwarded_port", guest: 80, host: 80
  config.vm.network "forwarded_port", guest: 5000, host: 5000
  config.vm.network "forwarded_port", guest: 9696, host: 9696
  config.vm.network "forwarded_port", guest: 8774, host: 8774
  config.vm.network "forwarded_port", guest: 35357, host: 35357
  config.vm.network "private_network", ip: "192.168.56.11"

# virtualbox provisioning, e.g. Memory and CPU

config.vm.provider :virtualbox do |v|
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    v.customize ['modifyvm', :id, '--natnet1', '192.168.56.0/24']
    v.customize ["modifyvm", :id, "--memory", 4096]
    v.customize ["modifyvm", :id, "--cpus", 2]
  end

# To make it easier, we set shell script to provision the devstack environment once the VM is running, so no need manual stacking.

config.vm.provision "shell", path: "script.sh"
end

Here’s the script.sh as above explanation.

#!/bin/bash

echo "****** Provisioning virtual machine...******"
echo "****** Install Git...******"
sudo apt-get install git

echo "****** Devstack deployment...******"
sudo useradd -s /bin/bash -d /opt/stack -m stack
echo "stack ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/stack
su - stack -c "cd /opt/stack && git clone https://git.openstack.org/openstack-dev/devstack"
su - stack -c "cat > /opt/stack/devstack/local.conf << END
[[local|localrc]]
HOST_IP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
DATABASE_PASSWORD=kosonginajah
RABBIT_PASSWORD=kosonginajah
SERVICE_TOKEN=kosonginajah
SERVICE_PASSWORD=kosonginajah
ADMIN_PASSWORD=kosonginajah
END"

echo "****** Stack.sh started...******"
su - stack -c "cd /opt/stack/devstack && ./stack.sh"

Step 3: Start Devstack

Start devstack by executing:

C:\pseudo\Vagrant>vagrant up

Now open the horizon thru the IP Address with credentials as mentioned earlier, for this case is http://192.168.56.11