Статьи

Как установить Devstack поверх Virtual Box с помощью Vagrant

Devstack через VirtualBox + Vagrant

[Эта статья была первоначально написана Shay Naeh.]

Многим из нас часто приходится разрабатывать и тестировать на OpenStack, однако это становится обременительным, поскольку OpenStack выпускает новые версии, где каждую из них необходимо установить и настроить с нуля.

Я обнаружил, что хорошим решением является установка DevStack поверх VirtualBox, но задача здесь состоит в том, чтобы преодолеть некоторые проблемы с конфигурацией и сетью OpenStack. Используя эту комбинацию Vagrant, VirtualBox и DevStack, я нашел простые обходные пути для простой установки и работы с OpenStack в локальной среде.

Мотивация состояла в том, чтобы иметь возможность иметь локальную среду разработки и тестирования для всей нашей команды разработчиков. Ниже приведен учебник для этой комбинации DevStack Vagrant.

Начиная

Давайте начнем с бродячего файла — это самый простой способ настроить виртуальную машину.

# -*- 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|
  # All Vagrant configuration is done here. The most common configuration
  # options are documented and commented below. For a complete reference,
  # please see the online documentation at vagrantup.com.

  # Every Vagrant virtual environment requires a box to build off of.
  config.vm.box = "devstack5"
  config.vm.network "private_network", ip: "171.15.19.31"
  config.vm.network :forwarded_port, guest: 80, host: 8080
  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.provider :virtualbox do |vb|
  #   # Don't boot with headless mode
  vb.gui = false
  #
  #   # Use VBoxManage to customize the VM. For example to change memory:
  vb.customize ["modifyvm", :id, "--memory", "4096"]
  end
  
  config.vm.provision "shell", path: "script.sh"
end

Вам нужно будет скачать правильный дистрибутив Linux и номер версии, я использовал Ubuntu 12.04. Вам нужно будет использовать имя, которое вы дали коробке (обратите внимание, что в Gist я назвал в devstack5). Затем вам необходимо предоставить IP-адрес для частной сети. После этого вы можете выделить или создать порты пересылки для всех конечных точек API сервисов OpenStack — Keystone, Neutron et al.

Vagrant supports also configuration of the Vagrant VM that is brought up.  You are able to configure its memory size, CPU, and other characteristics — for example look in the config VM provision section (towards the end of the file) where I created a machine 4 GB memory.

Next,  you supply your own script, which I’ll elaborate on later, that describes the initial configuration of the box, when it is brought up.

After this, run vagrant up, and the box will then load.

SSH into the box to install DevStack.  Reference Barak’s post for how to install DevStack.

Working with DevStack

DevStack comes with many configuration files, however, I’ve found that the simplest method is to change the localrc or the local.conf file to provide the information you need to configure DevStack.

In the localrc file you can provide passwords for your different services — RabbitMQ, Admin passwords, in addition to providing additional information you will need for the setup: floating IP ranges you’d like to use, the flat interface (e.g. ETH0), a location to store the log files,  where the gateway is located, and services you‘d like to enable.  For example, I enabled the Neutron service for networking purposes, (I’ll dive into networking hacks a bit later).  In the Gists below you will also see how to access Devstack from the host machine, as well as how to access the instances launched inside DevStack from the outside world.

After you create the configuration file, run stack.sh which will install MySQL and  RabbitMQ, will compile and install all of the OpenStack components, and finally will bring the system up.

After the system is up and running you will be able to access it through the Horizon dashboard.

That’s the simple stuff.  However, you will likely need to be able to have network access from the host machine to DevStack and to the launched instances. You’d be best off automating this as much as possible to simplify the process.

Kicking it Up a Notch

In the Vagrant file I defined a script that is being called to create networking routes, as well as allocate OpenStack resources and objects, and define security rules and more.  This enables you to access DevStack from the host machine. 

#!/bin/bash
echo `whoami`
sudo chmod +x /vagrant/start.sh
sudo -u stack /vagrant/start.sh
#!/bin/bash
cd /home/stack/devstack
source openrc admin
wget -q http://uec-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img 
/home/stack/devstack/stack.sh
glance image-create --name="Ubuntu12.04" --disk-format=qcow2 --container-format=bare --is-public=true < precise-server-cloudimg-amd64-disk1.img
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
nova flavor-create m1.tiny2 auto 512 10 1
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
nova secgroup-add-rule default tcp 80 80 0.0.0.0/0

When I did this, I had a problem running it in one script, since I discovered that it has to run under a specific user.  Since I installed DevStack under the “stack” user, I had to switch automatically from the vagrant user  to the stack user before the  script runs, as well as  change the execution permissions to the file.  To do so, I created a script called script.sh for the permission manipulation.

Through the start.sh file you can actually access external images, which you will need to do, since DevStack comes with a very small number of pre-loaded images that are not necessarily suitable, for example Ubuntu is not one of them.  To do so, you can provide a URL or HTTP, and by using w-get you can download additional images.  To bring DevStack up automatically, you’re also able to run the stack.sh from the script as well.

Note, that to add images it is not enough to download them and just put them in the directory, you will also need to tell Glance (the OpenStack image repository) to create a new image ID from the downloaded image.

Do this by calling glance image-create with the format, the container, and image reference.

Networking Hacks

Regarding networking, if you want to have DNS and name resolution the easiest way is to call the Neutron subnet update, and add a DNS name server. I added the Google public name server for name resolution —  it’s IP address is 8.8.8.8. 

Another networking configuration is to create security groups. I did this to be able to ping the new launched instances, and be able to SSH into them, as well as be able to access the web apps installed on port 80.

In order to be able to access the DevStack machine from the host machine, you have to use the route add command, as you can see in the example below. You will need to create a route using a gateway which tells the host machine if it receives a packet from a certain subnet to which interface it should be forwarded. 

#!/bin/bash
sudo /sbin/route add -net 10.0.2.0 netmask 255.255.255.0 gw 171.15.19.31
sudo /sbin/route add -net 172.24.4.0 netmask 255.255.255.0 gw 171.15.19.31
vagrant up

Для этого я добавил два разных маршрута. Я сделал это , прежде чем я побежал
бродячую вверх команду. Чтобы получить доступ к экземплярам запуска или пропинговать их, вы можете использовать пространства имен.

Я использовал команду netns для доступа к внутренним запущенным экземплярам. OpenStack использует пространства имен сети для изоляции сетей, где каждая виртуальная сеть получает свое собственное пространство. Пространство означает сетевые интерфейсы, таблицы маршрутизации, таблицы IP отдельно для каждого арендатора.

Вы можете запустить список IP-сетей, чтобы получить список пространств имен, а затем выбрать то, что вам нужно.

Run exec with the namespace you defined, and define additional parameters such as IP tables, and routing information, for example:

sudo ip netns exec qrouter-1520casp2-f23c-497a-8578-3b2dcb7c2457 ping 10.0.0.7

sudo ip netns exec qrouter-152mnwd2-f54c-481a-8895-3b2dcb7c2624 ssh –i keyname ubuntu@10.0.0.7

I ran into a few issues when attempting to debug, so I chose to use the screens method explained in the DevStack + Heat post by Yoram. With the screen command you can see all of the DevStack terminals/consoles (about 15), e.g. Neutron, Nova, Horizon, APIs and others, and dive into their error messages.

To check that everything worked as it should, I launched a few instances, and was able to access them from the network.

Once I saw that it was up and running as needed, I packaged everything into a Vagrant box, this enables:

  • Anyone to have their own DevStack local test and development environment.

  • Anyone can have an IaaS in a box (VBox) locally — where you can define instances, configure, etc.

That’s it.  With a few simple commands you can have your own local OpenStack and IaaS environments up and running.

If you want to upgrade to the newest OpenStack release follow the setup above, repackage it, and you’re good to go.