Driver for the IBM Smart Business Cloud (SBC).
31 January 2011
Creates an instance
# File lib/deltacloud/drivers/sbc/sbc_driver.rb, line 73 def create_instance(credentials, image_id, opts={}) sbc_client = new_client(credentials) # Copy opts to body; keywords are mapped later body = opts.dup body.delete('image_id') body.delete('hwp_id') body.delete('realm_id') # Lookup image if nil; tries to avoids extra lookup if @last_image.nil? || @last_image['id'] != opts[:image_id] @last_image = sbc_client.list_images(image_id).map[0] end # Map DeltaCloud keywords to SBC body['imageID'] = opts[:image_id] body['location'] = opts[:realm_id] || @last_image['location'] body['instanceType'] = opts[:hwp_id].gsub('-', '/') || @last_image['supportedInstanceTypes'][0]['id'] if not body['name'] body['name'] = Time.now.to_i.to_s end # Submit instance, parse response convert_instance(sbc_client.create_instance(body).map[0]) end
Destroys an instance
# File lib/deltacloud/drivers/sbc/sbc_driver.rb, line 120 def destroy_instance(credentials, instance_id) sbc_client = new_client(credentials) sbc_client.delete_instance(instance_id) instance(credentials, instance_id) end
Retrieves images
# File lib/deltacloud/drivers/sbc/sbc_driver.rb, line 32 def images(credentials, opts={}) sbc_client = new_client(credentials) opts ||= {} images = [] images = sbc_client.list_images(opts[:id]).map do |image| # Cache image for create_instance; hwp is image-specific. In the # current flow of the server, images is always called before a # create_instance, making this caching profitable @last_image = image convert_image(image) end images = filter_on(images, :architecture, opts) images = filter_on(images, :owner_id, opts) images end
Retrieves instances
# File lib/deltacloud/drivers/sbc/sbc_driver.rb, line 61 def instances(credentials, opts={}) sbc_client = new_client(credentials) opts ||= {} instances = [] instances = sbc_client.list_instances(opts[:id]).map do |instance| convert_instance(instance) end end
Retrieves realms
# File lib/deltacloud/drivers/sbc/sbc_driver.rb, line 51 def realms(credentials, opts={}) sbc_client = new_client(credentials) doc = sbc_client.list_locations realms = doc.xpath('ns2:DescribeLocationsResponse/Location').map { |loc| convert_location(loc) } realms = filter_on(realms, :id, opts) end
Reboots an instance
# File lib/deltacloud/drivers/sbc/sbc_driver.rb, line 103 def reboot_instance(credentials, instance_id) sbc_client = new_client(credentials) sbc_client.reboot_instance(instance_id) instance(credentials, instance_id) end
Generated with the Darkfish Rdoc Generator 2.