Openstack local development — How to install, test and use OpenStack in Virtualbox
OpenStack is a cloud operating system that controls large pools of compute, storage, and networking resources throughout a datacenter, all managed and provisioned through APIs with common authentication mechanisms.
~OpenStack
OpenStack is one of the biggest cloud computing platforms and provides an “Infrastructure-as-a-Service” solution. The variety of different services offered allows the administrator to install and configure the environment according to his own requirements. The goal is a simple implementation, great scalability and richness of functionality.
The large German telecommunications company Telekom AG has one of the largest public clouds implemented using Openstack and proves its scalability. CERN - the European Organization for Nuclear Research - is one of the world’s largest and most respected centers for scientific research. It uses OpenStack for its private cloud among other technologies, to explore and understand the secrets of the universe.
And now the best thing… It is open source! A large community supports the continuous development, which is why it is also one of the top 3 most active open source projects with Linux and Chromium. This is also a great advantage. Due to the constant review and testing of the code, bugs, security issues and the like are minimized. Each release is transparent for the administrator and the customer.
You may be wondering: “But how can I start developing with Openstack myself and take a closer look at this technology? Don’t I need the hardware first to implement a cloud on it using Openstack?”
Nope! All you need is your PC or laptop. In the following, I’ll explain how you can install, configure and test Openstack locally on your machine, so that you can also make your first experiences without much effort.
Recently I was dealing with OpenStack and looking for instructions on how to install and test it locally. However, I found only sketchy tutorials, so I’ll summarize my findings here. I am not a cloud engineer or OpenStack developer, but would like to do add my part.
The whole tutorial is divided into the following sections:
- Preparation of the necessary components
- Openstack installation
- Testing the installation
- Development using Openstack
Preparation of the necessary components
Virtualbox and Virtualbox Extension Pack
The first thing you will need is Virtualbox. Virtualbox is a cross-platfrom virtualization software used to run and host multiple operating systems in virtual machines in a separated environment. It is easy to use and has a tone of documentation. We will use it to host an Ubunutu server on which we will install Openstack.
You can download Virtualbox and the Virtualbox Extension Pack on its official download website.
Ubuntu Server
The second thing we will need is to download an Ubuntu server image, which will be started as a VM in Virtualbox.
You can download Ubuntu server image on its official download website.
Setup of Ubuntu Server in Virtualbox
Now we will configure our Ubuntu in Virtualbox. In order to do this create a new VM in Virtualbox.
The following settings are taken:
Name and operating system
Name: Some name for your VM
Machine folder: Storage location for your VM
Type: Linux
Version: Ubuntu (64-bit)
Memory size:
RAM: 8192 MB
Hard disk
Hard disk: Create a virtual hard disk now
Hard disk file type
Type: VDI (VirtualBox Disk Image)
Storage on phyisical hard disk
Storage: Dynamically allocated
File location and size
Location: Storage location for your hard disk
Size: 20GB
Now you have created a new VM in Virtualbox. Before we start it, we need to add some additional settings. First we need an host network in order to communicate between host and guest (your local machine and VM).
Host Network
In order to be able to connect to the VM from your local machine we will need to create a Host-Network in Virtualbox. Go to the Virtualbox-Window and then “File -> Host-Network-Manager”. Click “Create” to a create a new network. Make sure it looks like the following:
Now we have to some more VM settings. Select the newly created VM and click “Settings”. A menu should open where you can select additional settings. Change the following:
System
Processor: 4 CPUs
Storage
Controller IDE: Your downloaded ubuntu server image
Network
Adapter 1: NAT
Adapter 2: Host-only Adapter (Name of new host created network - this case: vboxnet0)
Summary
Now we are finished! Start the configured VM…
The virtual machine should start now and the Ubuntu configuration should open shortly. You don’t have to set much here. I only set keyboard, my root-user (username: openstack/ password: openstack) and check the open-ssh option. The rest I leave untouched and default.
If the installation is successful, there should be an option to restart. Now you will get an error because the ubuntu server image is still mounted. Just press “Enter” and it will be removed.
If everything worked fine, you should now be able to login as root! Also you should now be able to ping the VM from your local machine and ssh into it with the following commands:
ping -c1 192.168.56.105
ssh openstack@192.168.56.105
# If you connect with ssh you have to confirm the connection with yes
IP-Address: In order to get the IP-Address (in my case 192.168.56.105) of the VM type following command in the VM and use th ip starting 192.168.56.XXX.
ip addr
Openstack installation
Now that the virtual machine is ready, we can start with the actual installation of Openstack. For this we use “Devstack”.
I recommend to connect to the VM via ssh, because you can use copy & paste without problems.
DevStack is a series of extensible scripts used to quickly bring up a complete OpenStack environment based on the latest versions of everything from git master. It is used interactively as a development environment and as the basis for much of the OpenStack project’s functional testing.
First we need a non-root user to host the devstack.
sudo useradd -s /bin/bash -d /opt/stack -m stack
echo "stack ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/stack
sudo -u stack -i
Next we will need to download the devstack repository.
git clone https://opendev.org/openstack/devstack
cd devstack
Finally, we create a configuration file in the root directory of the devstack. (“vim local.conf” -> open config file). The content should look like this:
[[local|localrc]]
ADMIN_PASSWORD=openstack
DATABASE_PASSWORD=openstack
RABBIT_PASSWORD=openstack
SERVICE_PASSWORD=openstack
HOST_IP=IP Address of your VM starting 192.168.56.XXX!!!!!!!
Now we just need to start the installation.
./stack.sh
The installation can take up to 30min, depending on the performance of the VM. At the end you will see a message that the devstack has been successfully installed.
With the URL http://192.168.56.105/dashboard (adjust the ip to accordingly to your VM ip) you should now be able to see the Login-Page of OpenStack.
The credentials for the login:
user: admin
password: openstack
Congrats! You did everything right!
Testing and Development using Openstack
Now we want to test and develop using the OpenStack-API. To do this, it is best to download the official OpenStackSDK. This is in Python, but there are also community SDKs for other programming languages (Go, JS, Java, …).
pip install openstacksdk
Now we create an empty folder (“test-openstack”) and add those files:
clouds.yml: This is a configuration file and describes the connection to the cloud and therefore contains properties like credentials and authentication-url. Ours shoud look like this:
clouds:
test:
auth:
username: "admin"
password: openstack
project_name: "demo"
auth_url: "http://192.168.56.105/identity/" #CHANGE YOUR IP
domain_name: "Default"
test-openstack.py: This Python script contains the actual code. In our example we will only connect to the cloud and get a list of all users. The SDK is of course much more powerful and can manage all cloud resources. For demonstration purposes, however, we will stay here.
import openstack# Initialize and turn on debug logging
openstack.enable_logging(debug=True)# Initialize connection
conn = openstack.connect(cloud=’test’)# Get users and print
for user in conn.list_users():
print(user)
If no error is thrown here, you have done everything right! An list of users should now appear in the console. Otherwise check your cloud.yml file.
You are now ready to develop with an simple configured OpenStack! Have fun!