Wednesday, July 14, 2010

Power Console for the RightScale Platform

This post introduces the "power console" I use to manage my RightScale account directly from the command-line of my laptop.  If you are a command-line person and manage your cloud servers on the RightScale platform (or want to), then read on...

The tool I use is really just rest_connection running within an irb session -- this turns irb into a sort of "power console" for the RightScale dashboard. Rest_connection is an open-source gem developed by RightScale engineer, Jeremy Deninger.  In this post we will just scratch the surface of what  rest_connection can do. 

If you've had your RightScale account for a while or use the RightScale API to automatically the create deployments, you might have more than a few old deployments hanging around in your RightScale account.  Below walks you through four simple commands to delete a batch of unwanted deployments, stopping any running servers along the way.

If you are not very careful, you might unintentionally delete a deployment you need.  I recommend only performing the following operations in an account that is NOT running ANY production servers. You have been warned!

Setup rest_connection

The source code is found here. But the most stable gem is hosted on gemcutter -- I recommend just installing the gem by running:

> gem install rest_connection

Setup your ~/.rest_connection/rest_api_config.yaml similar to the example config file.  Add your password and username.  Also replace "00000000" with your account id. Dont know your account id?  Login to the dashboard and look at the URL.

Run rest_connection within irb
Start irb at the command-line by typing:

> irb

Load rubygems and rest_connection into your irb session:

>> require 'rubygems'
>> require 'rest_connection'

Grab an array of deployments to cleanup using a regex:

>> d = Deployment.find_by(:nickname) { |n| n =~ /^My Deployment number [0-5]$/ }

This should grab deployments: 
  • My Deployment number 0
  • My Deployment number 1
  • My Deployment number 2
  • My Deployment number 3
  • My Deployment number 4
  • My Deployment number 5
How many did it find?

>> d.size
=> 6

Good! I do this size command as a sanity check -- is that the number I expect?  Yes, so, I continue...

Shutdown servers in all deployments found in previous steps:

>> d.each { |dep| dep.servers.each { |s| s.stop } }

Now delete all deployments too:

>> d.each { |dep| dep.destroy }

Bye bye multiple deployments!!  Keeping your account nice and clean :)

In this example we used the RightScale 'Deployment' and 'Server' objects included in rest_connection.  And while I use this example on a daily basis, it is really just the tip of the iceberg of what you can do from the command-line using rest_connection.

Take a look here at the other RightScale objects you can access by rest_connection.

It's worth digging in to the source code. 


No comments: