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.
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
# ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
# make && make altinstall
# python2.7 -V
# python2.7 ez_setup.py
# easy_install-2.7 pip
OR
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 ez_setup.py
# 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
OR
# python3.5 -m venv venv
Activate virtualenv
# source venv/bin/activate
Now install the SDK:
# pip2.7 install
openstacksdk
OR
# pip3.5 install
openstacksdk
# Run the following test
program (test.py) as:
# python3.5 ./test.py
# OR
# python2.7 ./test.py
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)
console.setFormatter(formatter)
logger.setLevel(logging.DEBUG)
logger.addHandler(console)
# Enable logging to console
utils.enable_logging(debug=True, stream=sys.stdout)
# Get connection
conn = connection.Connection(auth_url="http://localhost:5000/v2.0",
project_name="admin",
username="admin",
password="password")
# Get network API
network = conn.network.find_network("watshnet")
if network is None:
network = conn.network.create_network(name="watshnet")
else:
print(network)
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 - https://github.com/stackforge/python-openstacksdk/tree/master/examples.