20 May 2014

I'd like to develop for OpenStack

The eaiest way to start, is to use a project called devstack. Devstack is:

A documented shell script to build complete OpenStack development environments.

It looks promising. Unfortunately, the script is not as simple as what is claimed on the website:

git clone https://github.com/openstack-dev/devstack.git
# configure, while optional...
cd devstack; ./stack.sh

There be Dragons.

So?

After looking at a number of different search results on the Internets, digging through some Chef cookbooks, Puppet stuff, here's a Vagrant file to set up Devstack using Vagrant (Ubuntu 12.04):

Vagrant.configure("2") do |config|

  config.vm.provider "virtualbox" do |vbox, override|
    override.vm.box = "precise64"
    override.vm.box_url = "http://files.vagrantup.com/precise64_vmware.box"
    vbox.customize ["modifyvm", :id, "--memory", "2048"]
  end

  config.vm.define "devstack" do |devstack|
    # redirect horizon, we can't run on port 80
    devstack.vm.network :forwarded_port, guest: 80, host: 9000
    # redirect the API        
    devstack.vm.network :forwarded_port, guest: 8774, host: 8774
    # redirect the auth API
    devstack.vm.network :forwarded_port, guest: 35357, host: 35357
    # install git
    devstack.vm.provision :shell, :inline => "apt-get install -y git-core"
    # clone Devstack
    devstack.vm.provision :shell, :inline => "cd /opt && git clone https://github.com/openstack-dev/devstack.git"
    # Create the stack user
    devstack.vm.provision :shell, :inline => "/opt/devstack/tools/create-stack-user.sh"
    # add user to sudoers
    devstack.vm.provision :shell, :inline => "echo \"stack ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers"
    # localrc file, explained below
    # we are going to copy this file from the host to the guest where we run Devstack
    devstack.vm.provision :shell, :inline => "cat > /opt/devstack/localrc <<'VAGRANTEOP'\n#{File.read( File.dirname(__FILE__) + "/setup/devstack-localrc" )}\nVAGRANTEOP"
    # just make it work, it's dev
    devstack.vm.provision :shell, :inline => "chmod -R 0777 /opt/devstack"
    # and stack it all up
    devstack.vm.provision :shell, :inline => "su - stack -c '/opt/devstack/stack.sh'"
  end

end

About 12.5 minutes Vagrant should display something like this:

2014-05-20 15:03:49.711 | stack.sh completed in 758 seconds.

Horizon will be accessible via http://localhost:9000, the API is available on http://localhost:8774/v2/...

Wait, localrc!

The structure of the project should looks like this:

-- Vagrantfile
-- setup
 |-- devstack-localrc

The devstack-localrc file contains some critical information, its place is most likely in .gitignore. Here's the basic content, just put your own data in it:

DEST=/opt/devstack
ENABLED_SERVICES+=,heat
ADMIN_PASSWORD=meh
MYSQL_PASSWORD=meh
RABBIT_PASSWORD=meh
SERVICE_PASSWORD=meh
SERVICE_TOKEN=meh
HOST_IP=0.0.0.0
LOGFILE=stack.sh.log
LOGDAYS=1
LOG_COLOR=False
SCREEN_LOGDIR=/opt/stack/logs/screen
API_RATE_LIMIT=False
APT_FAST=True
RECLONE=yes

VoilĂ !