Sunday, October 11, 2015

Setting up OpenStack python SDK on Oracle Enterprise Linux 6

To setup openstacksdk on Oracle VM Server 3.3.3 or Oracle Enterprise Linux 6:

Oracle Enterprise Linux 6 comes with python 2.6.6 by default.

OpenStackSDK requires at least python 2.7 or 3.3.

Following are the steps to upgrade local python to 2.7.10 and 3.5.0 (the latest as of this writing) and install openstacksdk for development.

It is assumed that OpenStack is hosted on the same host where the test program is being executed.

$ sudo su -
# cd /etc/yum.repos.d
# rm -f *
# yum clean all
# yum makecache
# yum install gcc

The above step may take quite some time and is only required to install gcc. If one already has gcc installed then skip to the following step.

# yum groupinstall "Development tools"
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
# cd /usr/src

Get ez_setup to install easy_install for python interpreter.

# tar xzf Python-2.7.10.tgz
# tar xzf Python-3.5.0.tgz

Install Python-2.7.10
# cd Python-2.7.10
# ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
# make && make altinstall
# python2.7 -V
# python2.7
# easy_install-2.7 pip


Install Python 3.5.0
# cd Python-3.5.0
# ./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
# make && make altinstall
# python3.5 -V
# python3.3
# easy_install-3.3 pip

Setup Virtualenv for your project:
# cd /files/project
# pip2.7 install virtualenv
# virtualenv -p /usr/local/bin/python2.7 venv

# python3.5 -m venv venv

Activate virtualenv
# source venv/bin/activate

Now install the SDK:
# pip2.7 install openstacksdk
# pip3.5 install openstacksdk

# Run the following test program ( as:
# python3.5 ./
# OR
# python2.7 ./

from openstack import connection
from openstack import utils
import logging
import sys

# Enable requests logging
logger = logging.getLogger('requests')
formatter = logging.Formatter(
    '%(asctime)s %(levelname)s: %(name)s %(message)s')
console = logging.StreamHandler(sys.stdout)

# Enable logging to console
utils.enable_logging(debug=True, stream=sys.stdout)

# Get connection
conn = connection.Connection(auth_url="http://localhost:5000/v2.0",

# Get network API
network ="watshnet")
if network is None:
    network ="watshnet")

If everything went fine so far then you are all set to begin writing your extensions for OpenStack. Examples using the sdk are available here -

No comments:

15 sorting algorithms visualized in 5 minutes, with awesome arcade sounds

15 sorting algorithms visualized in 5 minutes, with awesome arcade sounds from r/programming