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

[...]

> 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.

[...]

Hello.

I see two independent matters in this case and each has to be treated
differently. First, getting basic information about stuff in RackTables
database is much easier after the release of 0.17.0. Let me cite
inc/functions.php:

// Return list of records in the given realm, which conform to
// the given RackCode expression. If the realm is unknown or text
// doesn't validate as a RackCode expression, return NULL.
// Otherwise (successful scan) return a list of all matched
// records, even if the list is empty (array() !== NULL). If the
// text is an empty string, return all found records in the given
// realm.
function scanRealmByText ($realm = NULL, $ftext = '')

IOW, to print the list of all objects, one could write:
foreach (scanRealmByText ('object') as $object)
        echo $object['dname'] . '<br>';

The items returned by this function are internally called "cells" and
are usual PHP arrays with nested data. The best thing about it is that
is speaks RackCode in plain text:

$networks = scanRealmByText ('ipv4net',
'({server network} or {desktop network}) and not {special network}');

$techlibrary = scanRealmByText ('file',
'{operation guide} or {user manual}');

There is another function, amplifyCell(), which loads each record with
detailed information about it. However, to be honest, the "attributes"
(or "stickers") aren't yet handled by this function due to some internal
justification not completed. Most other data can be retrieved from
the DB with a combination of scanRealmByText() and amplifyCell()
without knowledge of underlying SQL schema.

scanRealmByText() is currently the best function to base your custom
"reports" onto, and when RackTables API spec is written, it will be the
first function on it.

Now on to the Python code. It would be interesting to have a mean to
access (read-only at least) existing data from another language
programs. That said, I didn't learn Python, although I knew it existed.
IOW, I can't help you on the language part of this work. But if you
really decide to go on with your idea, I can outline the set of
functions you need to re-implement in Python to get scanRealmByText()
function (or method?) available to users of your library. That way
RackTables API would be language-independent. If you decide to take this
way, it is possible to put your code into project's SVN under its own
name. It's all up to you however.

Other related posts: