Parent

Class/Module Index [+]

Quicksearch

Deltacloud::Drivers::SBC::SBCClient

Client for the IBM Smart Business Cloud (SBC).

31 January 2011

Constants

API_URL

Public Class Methods

new(username, password) click to toggle source

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

Public Instance Methods

create_instance(body) click to toggle source

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_instance(instance_id) click to toggle source

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
list_images(image_id=nil) click to toggle source

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
list_instances(instance_id=nil) click to toggle source

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
list_locations() click to toggle source

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_instance(instance_id) click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.