Using libcloud with RimuHosting


Libcloud.org has merged our RimuHosting driver into their Python library.  All of our api functionality isn’t included in that driver, but there are a number of handy things that you can do via just a smattering of python code.  I’m going to write a few articles on this topic to demonstrate some of the cool things that you may find useful (dynamically adding webheads to handle an increasing load when you need it).  :)

Let’s dive in and get our feet wet first and see how to make this thing go.   I’m working from a Debian 5 box here so there may be some differences in the setup bits, but the python code itself would be identical.

The library is dependent on a couple things that aren’t installed by default.  You’ll need the zope3 package and the simplejson python package (unless you’re on python 2.6 already):

apt-get install zope3
wget http://pypi.python.org/packages/source/s/simplejson/simplejson-2.0.9.tar.gz#md5=af5e67a39ca3408563411d357e6d5e47
tar xfz simplejson-2.0.9.tar.gz
cd simplejson-2.0.9
python setup.py install

Then you can install the libcloud driver and then we’re ready to get cracking:

git clone git://github.com/cloudkick/libcloud.git
cd libcloud
python setup.py install

You’re going to need to fetch your RimuHosting api key.  You can get that here:

http://rimuhosting.com/cp/apikeys.jsp

All of the hard stuff is done; the rest is quite simple.  Here is a working example (provided you have a valid api key) to list all of your running nodes:

from libcloud.drivers.rimuhosting import RimuHostingNodeDriver
r = RimuHostingNodeDriver(‘4d5e3b5b1d6784jwisu&iwla4c46ba04’)

#get nodes
all_nodes = r.list_nodes()
print all_nodes

You’ll get something back like a listing of all active VPS.  You can see whether or not the VPSs are up/down and some basic information about them from.  Let’s say that you wanted to reboot a particular instance programatically.  You’d do something like this to reboot your VPS named example.com:

from libcloud.drivers.rimuhosting import RimuHostingNodeDriver
r = RimuHostingNodeDriver(‘4d5e3b5b1d6784jwisu&iwla4c46ba04′)

#get nodes
all_nodes = r.list_nodes()

#reboot VPS
r.reboot_node(filter(lambda x: x.name==’example.com’, all_nodes)[0])

You can place an order for a new VPS (fresh install or clone an existing VPS).  To setup a new VPS, you’ll need to have a valid image (distro) and size (plan) selected.  Those can be printed via the following:

from libcloud.drivers.rimuhosting import RimuHostingNodeDriver
r = RimuHostingNodeDriver(‘4d5e3b5b1d6784jwisu&iwla4c46ba04′)

#get available images
all_distros = r.list_images()

#get available sizes
all_sizes = r.list_sizes()

#to setup a MiroVPS1 plan with lenny, you’d use:

#create clean VPS
size = filter(lambda x: x.id==’MIRO1′, all_sizes)[0]
distro = filter(lambda x: x.id==’lenny’, all_distros)[0]
r.create_node(“testnode.com”,distro,size)

#to destroy that later, you’d use:

#destroy VPS

all_nodes = r.list_nodes()
r.destroy_node(filter(lambda x: x.name==’testnode.com’, all_nodes)[0])

Billing is handled automatically and you need to have an active server with us in order to place orders via the api.  Shutdowns are run immediately and your account will be credited with any unused hosting time at the time of the shutdown.

The above snippets should be enough to help you get started.  The next step is putting this all together to create a platform which can scale up automatically when the going gets rough.


2 responses to “Using libcloud with RimuHosting”

  1. Technically if somebody was Savvy, they would easily resell our VPS as their own. Just order a VPS, write their own web interface which worked with that, and presto.