[racktables-users] ANN: Python for Racktables (pyracktables?)

Let me start by saying that I'm not a very good programmer.  I'm an amateur
at best.  But I had a request from a coworker to pull out some arbitrary
data from RackTables for reporting purposes.  "That'll be a nice little
challenge" I said.  I took a look at the SQL, mucked around with MySQL
Architect, and got nowhere.  I just couldn't wrap my head around pulling in
the various tables I needed to extract the data.

But then I remembered that Python had some tools for handling MySQL data.
I'm still learning Python, so the challenges seemed to match up.  Learn a
bit of SQL and Python at the same time.  And if I succeed, hey, maybe
pulling rack location data into python object lists would be of benefit to
someone.

Seasoned coders can probably solve my initial need(objects and serials) in 5
lines of PHP and MySQL code.  But I couldn't.  It hurt my brain.  :)


So, anyway, I've got some groundwork built for pulling RackTables data into
Python.

Right now, I'm pulling data out of RackObject, Rack, RackSpace, and
AttributeValue.  Those were my immediate needs.  Namely, to produce a list
of objects, their location, Asset#, and their "OEM S/N 1" field.  I'm then
producing CSV style output.  Nothing more.

It's just one python file, and two additional library installs.
Get the code from:
http://bitbucket.org/choffman/pyracktables/

Then, if you don't have easy_install:
wget http://peak.telecommunity.com/dist/ez_setup.py
python ez_setup.py

And the two python libraries:
easy_install sqlalchemy
easy_install mysql-python


Change your mysql info at the bottom of the file - right now you have to do
it in three places.  Sorry about that.

The code does not alter any tables, it just runs really complicated SELECT's
on them.

I'll try to add some better inline docs/comments over the next day or three.

Other related posts: