Introducing chube: Object-oriented bindings for Linode API

I've been scripting with the Linode API a lot for my employer Exosite, and although tjfontaine's linode-python package does a great job of transliterating the API spec into Python territory, I've been longing for the object-orientedness of something like Fog. That's why I wrote

Chube!

It adds an abstraction layer on top of tjfontaine's bindings, and also gives you a nifty little command-line app called chuber.py that lets you mess with the API objects in a Python interpreter.

I think the best way to show you how it works is with an example chuber.py session:

you@localhost:~$ chuber
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
>>> Linode.search()
[<linode api_id="13971," label="foo-01">, <linode api_id="20401," label="bar-04">, <linode api_id="13972," label="foo-02">]
>>>
>>> nodes = Linode.search(label_begins='foo-')
[<linode api_id="13971," label="foo-01">, <linode api_id="13972," label="foo-02">]
>>>
>>> for node in nodes:
...     print node.ipaddresses[0].address
...
192.168.13.148
192.168.8.218
>>>
>>> plan = Plan.find(label="Linode 1024")
>>> plan
 <plan label="Linode 1024">>>> datacenter = Datacenter.find(location_begins="dallas")
>>> datacenter
 <datacenter location="Dallas, TX, USA">>>>
>>> new_node = Linode.create(plan=plan, datacenter=datacenter, payment_term=1)
>>> new_node
 <linode api_id="345768," label="linode345768">>>> new_node.label = "web-14"
>>> new_node.save()
>>> Linode.find(label="web-14")
 <linode api_id="345768," label="web-14">>>>
>>> distro = Distribution.find(label="Debian 7")
>>> disk = new_node.create_disk(distribution=distro, label="foo_disk", size=2000, root_pass="secret123")
>>> new_node.pending_jobs
[<job api_id="12310126," label="Disk Create From Distribution - Debian 7">, <job api_id="12310127," label="Linode Initial Configuration">]
>>> new_node.pending_jobs[0].wait()
>>>
>>> job = new_node.boot()
>>> job.wait()
>>>
>>> new_node.destroy()</job></job></linode></linode></datacenter></plan></linode></linode></linode></linode></linode>

You can install it with

pip install chube

And there's a to-do list.

Play around with it, let me know what you think, and fork the crap out of it!

4 Replies

Always happy to see people working with the library, and fwiw I did a rudimentary OOP interface

https://github.com/tjfontaine/linode-py … ode/oop.py">https://github.com/tjfontaine/linode-python/blob/master/linode/oop.py

and briefly "documented" at http://atxconsulting.com/LinodeOOPBindings/

This thing now supports all the Linode and Stackscript functionality of the API. Next stop: DNS.

Also, I beefed up the docs: https://github.com/exosite/chube/blob/master/README.md

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct