Notes about various (technical) topics and encountered or solved puzzles from engineering, devops or networking disciplines.

Search This Blog

Saturday, April 20, 2013

How to develop and debug programs that use pyrax or python-novaclient libraries

Python belongs to a category of high-level, dynamically typed programming languages. This has enormous impact on the way how you write the code and how it is interpreted and executed.

As an example let's take a look at Python Rackspace pyrax module. It was built and made available in a form of Python SDK for Rackspace cloud. Under the hood it is a wrapper and integrator of various python libraries that exists to interact with Openstack systems(cloud servers, files, networks, databases ...). As an example it uses python-novaclient library communicate and interact with Nova (Openstack Compute).

From developer point of view you can write a Python program to interact with Rackspace cloud using any of them. Both should work fine.

Working with any of these libraries you are going to face these challenges very soon:

where is the latest API documentation

how well are function documented

for a function what arguments it accepts and what it returns

In comparison to other statically typed languages like Java you quickly realize that Python definition of a function doesn't' fully answer the above questions. Below are couple of tricks to help you start with to play with them although.

Problem 1

How to start interactive Python session with loaded pyrax module for testing

We are going to use bpython that has a nice feature allowing it to show the available functions and variables a Python objects implements (for these who are interested how this works you can read about introspectionhere and there)

root@server:~# bpython -i bpython-pyrax.py
the pyrax module has been loaded, try typing one of the commands below to see if it works.
#example 1: whow all cloud servers under you cloud account
l=cs.servers.list()
print(l)
# example 2: show list of images
pprint(cs.images.list())
>>>

Test how it works

Problem 2

How to start interactive Python session with loaded python-novaclient for testing

root@manage2:~# bpython -i bpython-novaclient.py
the novaclient module has been loaded and INITIATED, try typing one of the commands below to see if it works.
#example 1: whow all cloud servers under you cloud account
l=cs.servers.list()
print(l)
# example 2: show list of images
pprint(cs.images.list())
>>>

Last posts

About Me

Linux enthusiast

Profile:Curious systems engineer interested in many of the IT technologies but especially in cloud systems and network engineering. A quick learner who likes to tinker and who often spent time researching and trying new technologies for personal and business benefit.

Please note that the code available here is only for demonstration purposes. If you want to be serious, you'll have to make it more robust and integrate it. Also, the description is by no means a definitive reference on any of the subjects, but rather the result of my experimentation. Feel free to report any bugs or errors you find in the code or otherwise in the articles. Thanks