Ruby interface for the SUSE Studio API
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore Move to bundler May 4, 2011
Gemfile Update Sep 24, 2012
VERSION release new version Nov 5, 2012
rubygem-studio_api.changes release new version Nov 5, 2012
studio_api.gemspec fix gemspec Sep 26, 2012

Studio API: Wrapper to STUDIO API


Studio API library is intended to easier access to Studio API from ruby, but keep it easily extensible and easy maintanable, so it not need rewritting when new attributes introduced to Studio. It leads also that user need to know API documentation, which specify what options you need to use (see ). It has also feature which allows using in multiuser system (like server).


Example usage ( more in class documentation ). Example show how to clone appliance, upload own rpm, select it, find new software and add it, run new build and then print information about appliance. Note: All error handling is for simplicity removed. It is same as for ActiveResource so if you want see him, search for ActiveResource error handling.

require 'rubygems'
# If you want use it from git adapt LOAD_PATH
# you can load just required parts if you need, but Util loaded all classes to properly set it
require 'studio_api'

# Fill up Studio credentials (user name, API key, API URL)
# See if you are using SUSE Studio online
connection ='user', 'pwd', '')
# Setup the connection for all ActiveResource based class
StudioApi::Util.configure_studio_connection connection

# Find template with KDE4 for SLE11SP1
templates = StudioApi::TemplateSet.find(:all).find {|s| == "default" }.template
template = templates.find { |t| == "SLED 11 SP1, KDE 4 desktop" }
# clone template to new appliance
appliance = StudioApi::Appliance.clone template.appliance_id, :name => "New cool appliance", :arch => "i686" 
puts "Created appliance #{appliance.inspect}"

#add own rpm built agains SLED11_SP1"/home/jreidinger/rpms/kezboard-1.0-1.60.noarch.rpm") do |file|
  StudioApi::Rpm.upload file, "SLED11_SP1"
# and choose it in appliance ( and of course add repository with own rpms)
appliance.add_package "kezboard", :version => "1.0-1.60"

# find samba package and if it is not found in repositories in appliance, try it in all repos
result = appliance.search_software("samba").find { |s| == "samba" }
unless result #it is not found in available repos
  result = appliance.search_software("samba", :all_repos => "true").find { |s| == "samba" }
  # add repo which contain samba
  appliance.add_repository result.repository_id
appliance.add_package "samba"

#check if appliance is OK
if appliance.status.state != "ok"
  raise "appliance is not OK - #{appliance.status.issues.inspect}"
build = =>, :image_type => "xen")
while build.state != "finished"
  puts "building (#{build.state}) - #{build.percent}%"
  sleep 5

final_build = StudioApi::Build.find
puts final_build.inspect

# to clear after playing with appliance if you keep same name, clean remove appliances with:
# appliances = StudioApi::Appliance.find :all
#{ |a| =~ /cool/i }.each{ |a| a.destroy }

Second example contain how to easy mock calling studio stuff without mock server. Using mocha

require 'mocha'
require 'studio_api'

APPLIANCE_UUID = "68c91080-ccca-4270-a1d3-10e714ddd1c6"
BUILD_ID = "180420"
APPLIANCE_1 = :id => APPLIANCE_STUDIO_ID, :name => "Test", :arch => 'i386',
                          :last_edited => "2010-10-08 14:46:07 UTC", :estimated_raw_size => "390 MB", :estimated_compressed_size => "140 MB",
                          :edit_url => "", :icon_url => "",
                          :basesystem => "SLES11_SP1", :uuid => APPLIANCE_UUID, :parent => {:id => "202443", :name => "SLES 11 SP1, Just enough OS (JeOS)"},
                          :builds => [{:id =>BUILD_ID,:version => APPLIANCE_VERSION, :image_type => "vmx", :image_size => "695",
                          :compressed_image_size => "121",
                          :download_url => ""}] 

#real mocking