Using Ruby on the IBM SmartCloud

If you use Ruby and the cloud, you are likely familiar with the Fog gem. Fog provides an easy to use library that delivers a client abstraction for most cloud services. Thanks to the recent work of Decklin Foster, the new 1.3.0 version of the gem supports the IBM SmartCloud. One of my favorite features of the 2.0 SmartCloud REST API is its integrated support for retrieving pricing for images. The below example provides an IBM corollary to my Programmatically Retrieving AWS Pricing post.

The fog gem can be retrieved as follows:

$ gem install fog  
Successfully installed fog-1.3.0  
1 gem installed  
Installing ri documentation for fog-1.3.0...  
Building YARD (yri) index for fog-1.3.0...  
Installing RDoc documentation for fog-1.3.0...

We have written a simple script that retrieves the on-demand price per month for all of your SmartCloud instances and exports it in CSV format.

#!/usr/bin/env ruby  

require 'rubygems'  
require 'fog'  


compute =  
        :provider           => 'IBM',  
        :ibm_username  => IBM_USERNAME,  
        :ibm_password => IBM_PASSWORD  

puts "Region,Instance Id,Instance IP,Instance Type,On-Demand Price Per Month"  
compute.servers.each do |server|  
  image = compute.images.get(server.image_id)  
  location = compute.locations.get(server.location_id)  
  instance_type ={|instance_type| == server.instance_type}.first  
  price_per_month = instance_type.price['rate'].to_f*24*30.4  
  puts "#{location.location},#{},#{server.primary_ip['ip']},#{},$#{price_per_month}"  

Here is a sample run of the script:


We are currently using this gem in an internal cloud asset management tool at Sonian, where it is integrated to retrieve and historically retain instances and their pricing. We are hoping a future version of the SmartCloud API will allow us to retrieve the full price list in order to provide real-time comparison of different pricing options, such as reserved versus on-demand instances.

For additional information on the IBM SmartCloud, you can follow the Thoughts on Cloud blog or @SmartCloud on Twitter.