Showing posts with label nova. Show all posts
Showing posts with label nova. Show all posts

Friday, February 26, 2016

Nova Docker Installation

After going through a lot of links (some good, some confusing), I finally figured out the installation of nova-docker. So whats the whole idea ?
When we create an OpenStack compute node with kvm as the underlying hypervisor, the VMs on that node get created using kvm hypervisor. Simple..
In the same way, there's a nova-docker driver. When we use nova-docker driver on a compute node, we can create docker containers using the "nova boot" command. That's what I did on my OpenStack kilo setup.

I created an All-in-one OpenStack kilo setup and used qemu as the hypervisor. Then, I thought of adding another compute node to the setup - but this one with nova-docker driver. Without any delay, I'll tell you how I did it (Though you would find a lot of links on it, but I prefer writing it my way :) ).

Step 1: Install docker on your VM - http://docs.docker.io/en/latest/installation/
Step 2: usermod -aG docker nova
Step 3: pip install docker-py
Step 4: git clone https://github.com/stackforge/nova-docker
[Steps 1-4 copied shamelessly from here]
Step 5: git checkout stable/kilo
Step 6: cd nova-docker
    Step 6.1: Edit the file driver.py - vi novadocker/virt/docker/driver.py as explained below
                   In def spawn(...), args{} needs to be edited as given below:

                    args = {
                   'hostname': instance['name'],
                   'mem_limit': self._get_memory_limit_bytes(instance),
                   'cpu_shares': self._get_cpu_shares(instance),
                   'network_disabled': True,
                   'tty': True,   # This line needs to be added.
        }
[Now again, step 6.1 is copied from here.]
Step 7: Follow the steps to configure and install a compute node from Openstack Kilo guide. - http://docs.openstack.org/kilo/install-guide/install/apt/content/neutron-compute-node.html
Step 8:python setup.py install - Install the nova-docker driver.
Step 9: Now we need to make some modifications to the nova configuration files that we edited in step 7. In "/etc/nova/nova.conf" under DEFAULT section, set 
compute_driver = novadocker.virt.docker.DockerDriver 
In /etc/nova/nova-compute.conf, we will set the compute driver as novadocker [that we installed in step 8].
cat /etc/nova/nova-compute.conf 
[DEFAULT]
#compute_driver=libvirt.LibvirtDriver
compute_driver=novadocker.virt.docker.DockerDriver
[libvirt]
virt_type=qemu
Step 10: Create the directory /etc/nova/rootwrap.d, if it does not already exist, and inside that directory create a file "docker.filters" with the following content:

# nova-rootwrap command filters for setting up network in the docker driver
# This file should be owned by (and only-writeable by) the root user

[Filters]
# nova/virt/docker/driver.py: 'ln', '-sf', '/var/run/netns/.*'
ln: CommandFilter, /bin/ln, root

Step 11: In "/etc/glance/glance-api.conf", set 
container_formats=ami,ari,aki,bare,ovf,ova,docker

Step 12: Follow "Uploading Images to Glance" onwards from this. If you get any error, follow this link. I got some of the same errors as described in this wonderful link. Many thanks to the author.

Once you are done with this, I would suggest you to create a new availability zone for this compute host. This way, while creating the docker instance, you can choose the docker availability zone. Here's what I did,

Step 1: nova aggregate-create docker-aggregate docker-availability-zone 
Step 2: nova aggregate-add-host

Now you can create an instance using the docker image. Check your instance using docker ps command on the compute node that we just created.

Thats all folks, I have consolidated everything in this blog post along with the helpful links. 

Putting all the links that I used for reference:

Saturday, March 21, 2015

Writing OpenStack application - A simple example

Finally, after reading Brent Salisbury's post I got my OpenStack-ODL environment up and running. So, I thought of writing a small application on OpenStack using the novaclient.v1_1.client package.

Setup Environment:

  • As described in this post till the line "The state of OVS after the stack should be the following:" [Just grep this line and do everything done before this.]
  • 2 VM running instances namely test_vm1, test_vm
  • The script should run on the Controller VM.


If you have your own setup, then you can take down the below details

  • Python version 2.7.5
  • Below packages need to be installed
  • pip install python-keystoneclient
  • pip install python-novaclient
Lets look at the below sample script.

  1 #!/usr/bin/env python
  2 import novaclient.v1_1.client as nvclient
  3
  4 # Replace the values below  the ones from your local config,
  5 auth_url = "http://192.168.56.104:5000/v2.0"
  6 username = "admin"
  7 password = "admin"
  8 tenant_name = "demo"
  9 project_id = "demo"
 10
 11
 12 nova = nvclient.Client(auth_url=auth_url, username=username,
 13                            api_key=password, project_id=project_id)
 14
 15 # Get the list of VMs
 16 srv_list =  nova.servers.list()
 17 server = nova.servers.find(name="test_vm1")
 18 print server
 19 print 'Rebooting server '+'test_vm1 ...'
 20 server.reboot()
 21 print 'test_vm1 rebooted'


Line 2 is used for importing nova package with.
Line 5-9 describe your local settings. When you run the controller node using devstack, you'll get the below output:
Horizon is now available at http://192.168.56.104/
Keystone is serving at http://192.168.56.104:5000/v2.0/
The IP Address here is the IP on which horizon service is running.
On line 5, the port number 5000 is used. You may also use port number 35357. Port 5000, 35357 are keystone's port numbers of public and administrative end-points.
For more details on port numbers, check this.

Line 12 is used to create a nova client object against which nova API calls would be made.
Line 16 and 17 are used to obtain the list of VMs and get the object of instance with name "test_vm1".
API call on line 20 finally reboots the instance.
Refer this to see the list of Server module APIs.

*********************************OUTPUT************************************
[fedora@fedora-odl-1 ~]$ python os_sample.py
[, ]
Rebooting server test_vm1 ...
test_vm1 rebooted
[fedora@fedora-odl-1 ~]$


Dashboard state before running the script.

After running the script os_sample, you'll see the rebooting message in the Power state column.

Acknowledgements:
This post is incomplete without acknowledging this wonderful link.