Search This Blog

Sunday, April 28, 2013

How to use pyrax and ipython together to test and learn the library api

When testing pyrax module using interactive ipython session I find myself often trying to inspect a single list value. In practice as my lists usually were build out of the same objects what I wanted is to inspect a single object from the list to discover its attributes and functions.

To overcome the ipython object limitation when it comes to introspection or reflection features I use this little helper script described here Custom magic function in IPython session. Below is an example session howto use in practice (in line you press TAB to let the ipython introspect the object)

ipython -i
In [1]: cs.images.list()                                                                                                            19:51:28
[<Image: Ubuntu 13.04 (Raring Ringtail)>,
 <Image: Gentoo 13.1>,
 <Image: Fedora 18 (Spherical Cow)>,
truncated ...

In [2]: rl
------> rl()
created variable l0 = <Image: Ubuntu 13.04 (Raring Ringtail)>
created variable l1 = <Image: Gentoo 13.1>
created variable l2 = <Image: Fedora 18 (Spherical Cow)>
created variable l3 = <Image: FreeBSD 9.1>
created variable l4 = <Image: Ubuntu 12.10 (Quantal Quetzal)>
created variable l5 = <Image: Ubuntu 12.04 LTS (Precise Pangolin)>
created variable l6 = <Image: Ubuntu 10.04 LTS (Lucid Lynx)>
created variable l7 = <Image: Red Hat Enterprise Linux 6.3>
list cs.images.list() has 45 elements but only 7 was printed

In [3]: l0. 
l0.HUMAN_ID              l0.created                         l0.metadata              l0.progress
l0.NAME_ATTR             l0.delete                l0.is_loaded             l0.minDisk               l0.set_loaded
l0.OS-DCF:diskConfig     l0.get                   l0.links                 l0.minRam                l0.status
l0.OS-EXT-IMG-SIZE:size  l0.human_id              l0.manager                       l0.updated

In [5]:
Out[5]: u'Ubuntu 13.04 (Raring Ringtail)'

No comments:

Post a Comment