Class: Deltacloud::Drivers::Sbc::SBCClient
- Inherits:
-
Object
- Object
- Deltacloud::Drivers::Sbc::SBCClient
- Defined in:
- lib/deltacloud/drivers/sbc/sbc_client.rb
Overview
Client for the IBM Smart Business Cloud (SBC).
31 January 2011
Constant Summary collapse
- API_URL =
URI.parse('https://www-147.ibm.com/computecloud/enterprise/api/rest/20100331')
Instance Method Summary collapse
-
#create_instance(body) ⇒ Object
Creates an instance.
-
#delete_instance(instance_id) ⇒ Object
Delete an instance.
-
#initialize(username, password) ⇒ SBCClient
constructor
Initialize the client.
-
#list_images(image_id = nil) ⇒ Object
Retrieve images.
-
#list_instances(instance_id = nil) ⇒ Object
Retrieve instances.
-
#list_locations ⇒ Object
Retrieve locations; returns an XML document.
-
#reboot_instance(instance_id) ⇒ Object
Reboot an instance.
Constructor Details
#initialize(username, password) ⇒ SBCClient
Initialize the client
38 39 40 41 42 43 |
# File 'lib/deltacloud/drivers/sbc/sbc_client.rb', line 38 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 |
Instance Method Details
#create_instance(body) ⇒ Object
Creates an instance
body is a name/value hash to configure the instance
97 98 99 100 101 |
# File 'lib/deltacloud/drivers/sbc/sbc_client.rb', line 97 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) ⇒ Object
Delete an instance
68 69 70 |
# File 'lib/deltacloud/drivers/sbc/sbc_client.rb', line 68 def delete_instance(instance_id) delete('/instances/' + instance_id, default_headers) end |
#list_images(image_id = nil) ⇒ Object
Retrieve images
75 76 77 78 79 80 81 |
# File 'lib/deltacloud/drivers/sbc/sbc_client.rb', line 75 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) ⇒ Object
Retrieve instances
48 49 50 51 52 53 54 |
# File 'lib/deltacloud/drivers/sbc/sbc_client.rb', line 48 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 ⇒ Object
Retrieve locations; returns an XML document.
86 87 88 89 90 |
# File 'lib/deltacloud/drivers/sbc/sbc_client.rb', line 86 def list_locations headers = default_headers headers['Accept'] = 'text/xml' # JSON locations not supported Nokogiri.XML(get('/locations', headers)) end |
#reboot_instance(instance_id) ⇒ Object
Reboot an instance
59 60 61 62 63 |
# File 'lib/deltacloud/drivers/sbc/sbc_client.rb', line 59 def reboot_instance(instance_id) headers = default_headers headers['Content-Type'] = 'application/x-www-form-urlencoded' put('/instances/' + instance_id, 'state=restart', headers) end |