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'  

IBM_USERNAME = 'YOUR_SMARTCLOUD_USERNAME'  
IBM_PASSWORD = 'YOUR_SMARTCLOUD_PASSOWRD'  

compute = Fog::Compute.new(  
        :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 = image.supported_instance_types.select{|instance_type| instance_type.id == server.instance_type}.first  
  price_per_month = instance_type.price['rate'].to_f*24*30.4  
  puts "#{location.location},#{server.name},#{server.primary_ip['ip']},#{instance_type.id},$#{price_per_month}"  
end

Here is a sample run of the script:

us-co-dc1,instance_1,0.0.0.0,COP32.1/2048/60,$54.72  
us-co-dc1,instance_2,0.0.0.0,COP64.2/4096/60,$182.4  
RTP,instance_3,0.0.0.0,BRZ32.1/2048/60*175,$83.904

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.