Client for the IBM Smart Business Cloud (SBC).
31 January 2011
Initialize the client
# File lib/deltacloud/drivers/sbc/sbc_client.rb, line 39 def initialize(username, password) @username, @password = username, password @rest_base = '/computecloud/enterprise/api/rest/20100331' @service = Net::HTTP.new(API_URL.host, API_URL.port) @service.use_ssl = true end
Creates an instance
body is a name/value hash to configure the instance
# File lib/deltacloud/drivers/sbc/sbc_client.rb, line 98 def create_instance(body) headers = default_headers headers['Content-Type'] = 'application/x-www-form-urlencoded' JSON.parse(post('/instances', urlencode(body), headers))['instances'] end
Delete an instance
# File lib/deltacloud/drivers/sbc/sbc_client.rb, line 69 def delete_instance(instance_id) delete('/instances/' + instance_id, default_headers) end
Retrieve images
# File lib/deltacloud/drivers/sbc/sbc_client.rb, line 76 def list_images(image_id=nil) if image_id.nil? JSON.parse(get('/offerings/image', default_headers))['images'] else [ JSON.parse(get('/offerings/image/' + image_id, default_headers)) ] end end
Retrieve instances
# File lib/deltacloud/drivers/sbc/sbc_client.rb, line 49 def list_instances(instance_id=nil) if instance_id.nil? JSON.parse(get('/instances', default_headers))['instances'] else [ JSON.parse(get('/instances/' + instance_id, default_headers)) ] end end
Retrieve locations; returns an XML document.
# File lib/deltacloud/drivers/sbc/sbc_client.rb, line 87 def list_locations headers = default_headers headers['Accept'] = 'text/xml' # JSON locations not supported Nokogiri.XML(get('/locations', headers)) end
Reboot an instance
# File lib/deltacloud/drivers/sbc/sbc_client.rb, line 60 def reboot_instance(instance_id) headers = default_headers headers['Content-Type'] = 'application/x-www-form-urlencoded' put('/instances/' + instance_id, 'state=restart', headers) end
Generated with the Darkfish Rdoc Generator 2.