Class: Deltacloud::Drivers::Rackspace::RackspaceDriver
- Inherits:
-
BaseDriver
- Object
- BaseDriver
- Deltacloud::Drivers::Rackspace::RackspaceDriver
- Defined in:
- lib/deltacloud/drivers/rackspace/rackspace_driver.rb
Constant Summary
Constants inherited from BaseDriver
BaseDriver::MEMBER_SHOW_METHODS, BaseDriver::STATE_MACHINE_OPTS
Instance Method Summary collapse
-
#blob_data(credentials, bucket_id, blob_id, opts = {}) ⇒ Object
-
Blob data -.
-
-
#blob_metadata(credentials, opts = {}) ⇒ Object
-
Blob Metadada -.
-
-
#blob_stream_connection(params) ⇒ Object
params: :user,:password,:bucket,:blob,:content_type,:content_length,:metadata.
-
#blobs(credentials, opts = {}) ⇒ Object
– Blobs –.
-
#buckets(credentials, opts = {}) ⇒ Object
– Buckets –.
-
#create_blob(credentials, bucket_id, blob_id, blob_data, opts = {}) ⇒ Object
– Create Blob –.
-
#create_bucket(credentials, name, opts = {}) ⇒ Object
– Create Bucket –.
- #create_image(credentials, opts = {}) ⇒ Object
-
#create_instance(credentials, image_id, opts) ⇒ Object
create instance.
-
#delete_blob(credentials, bucket_id, blob_id, opts = {}) ⇒ Object
– Delete Blob –.
-
#delete_bucket(credentials, name, opts = {}) ⇒ Object
– Delete Bucket –.
- #destroy_image(credentials, image_id) ⇒ Object
- #destroy_instance(credentials, instance_id) ⇒ Object (also: #stop_instance)
- #hardware_profiles(credentials, opts = {}) ⇒ Object
- #images(credentials, opts = nil) ⇒ Object
-
#instances(credentials, opts = {}) ⇒ Object
Instances.
-
#realms(credentials, opts = nil) ⇒ Object
rackspace does not at this stage have realms…
- #reboot_instance(credentials, instance_id) ⇒ Object
- #run_on_instance(credentials, opts = {}) ⇒ Object
-
#update_blob_metadata(credentials, opts = {}) ⇒ Object
-
Update Blob Metahash -.
-
- #valid_credentials?(credentials) ⇒ Boolean
Methods inherited from BaseDriver
#address, #api_provider, #blob, #bucket, #catched_exceptions_list, #configured_providers, constraints, define_hardware_profile, define_instance_states, driver_name, feature, features, #filter_hardware_profiles, #filter_on, #find_hardware_profile, #firewall, #hardware_profile, hardware_profiles, #has_capability?, #has_feature?, has_feature?, #image, #instance, #instance_actions_for, instance_state_machine, #instance_state_machine, #key, #name, #realm, #storage_snapshot, #storage_volume, #supported_collections
Methods included from Exceptions
exception_from_status, exceptions, included, logger, #safely
Instance Method Details
#blob_data(credentials, bucket_id, blob_id, opts = {}) ⇒ Object
- Blob data -
263 264 265 266 267 268 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 263 def blob_data(credentials, bucket_id, blob_id, opts = {}) cf = cloudfiles_client(credentials) cf.container(bucket_id).object(blob_id).data_stream do |chunk| yield chunk end end |
#blob_metadata(credentials, opts = {}) ⇒ Object
- Blob Metadada -
309 310 311 312 313 314 315 316 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 309 def (credentials, opts = {}) cf = cloudfiles_client(credentials) = {} safely do = cf.container(opts['bucket']).object(opts[:id]). end end |
#blob_stream_connection(params) ⇒ Object
params: :user,:password,:bucket,:blob,:content_type,:content_length,:metadata
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 333 def blob_stream_connection(params) #create a cloudfiles connection object to get the authtoken cf, cf_host, cf_path, cf_authtoken = nil safely do cf = CloudFiles::Connection.new(:username => params[:user], :api_key => params[:password]) cf_authtoken = cf.authtoken cf_host = cf.storagehost cf_path = cf.storagepath end provider = "https://#{cf_host}" uri = URI.parse(provider) http = Net::HTTP.new(uri.host, uri.port ) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Put.new("#{cf_path}/#{params[:bucket]}/#{params[:blob]}") request['Host'] = "#{cf_host}" request['X-Auth-Token'] = "#{cf_authtoken}" request['Content-Type'] = params[:content_type] request['Content-Length'] = params[:content_length] request['Expect'] = "100-continue" = params[:metadata] || {} BlobHelper::(, 'X-Object-Meta-') .each{|k,v| request[k] = v} return http, request end |
#blobs(credentials, opts = {}) ⇒ Object
– Blobs –
247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 247 def blobs(credentials, opts = {}) cf = cloudfiles_client(credentials) blobs = [] safely do cf_container = cf.container(opts['bucket']) cf_container.objects.each do |object_name| blobs << convert_object(cf_container.object(object_name)) end end blobs = filter_on(blobs, :id, opts) blobs end |
#buckets(credentials, opts = {}) ⇒ Object
– Buckets –
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 205 def buckets(credentials, opts = {}) bucket_list = [] cf = cloudfiles_client(credentials) safely do unless (opts[:id].nil?) bucket = cf.container(opts[:id]) bucket_list << convert_container(bucket) else cf.containers.each do |container_name| bucket_list << Bucket.new({:id => container_name, :name => container_name}) end #containers.each end #unless end #safely filter_on(bucket_list, :id, opts) end |
#create_blob(credentials, bucket_id, blob_id, blob_data, opts = {}) ⇒ Object
– Create Blob –
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 273 def create_blob(credentials, bucket_id, blob_id, blob_data, opts={}) cf = cloudfiles_client(credentials) #insert ec2-specific header for user metadata ... X-Object-Meta-KEY = VALUE BlobHelper::(opts, "X-Object-Meta-") opts['Content-Type'] = blob_data[:type] object = nil safely do #must first create the object using cloudfiles_client.create_object #then can write using object.write(data) object = cf.container(bucket_id).create_object(blob_id) #blob_data is a construct with data in .tempfile and content-type in {:type} res = object.write(blob_data[:tempfile], opts) end Blob.new( { :id => object.name, :bucket => object.container.name, :content_length => blob_data[:tempfile].length, :content_type => blob_data[:type], :last_modified => '', :user_metadata => opts.select{|k,v| k.match(/^X-Object-Meta-/i)} } ) end |
#create_bucket(credentials, name, opts = {}) ⇒ Object
– Create Bucket –
224 225 226 227 228 229 230 231 232 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 224 def create_bucket(credentials, name, opts = {}) bucket = nil cf = cloudfiles_client(credentials) safely do new_bucket = cf.create_container(name) bucket = convert_container(new_bucket) end bucket end |
#create_image(credentials, opts = {}) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 97 def create_image(credentials, opts={}) rs = new_client(credentials) safely do server = rs.get_server(opts[:id].to_i) image = server.create_image(opts[:name]) Image.new( :id => image.id.to_s, :name => opts[:name] || image.name, :description => opts[:description] || image.description, :owner_id => credentials.user, :state => image.status, :architecture => 'x86_64' ) end end |
#create_instance(credentials, image_id, opts) ⇒ Object
create instance. Default to flavor 1 - really need a name though… In rackspace, all flavors work with all images.
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 83 def create_instance(credentials, image_id, opts) rs = new_client( credentials ) result = nil params = extract_personality(opts) params[:name] = opts[:name] || Time.now.to_s params[:imageId] = image_id.to_i params[:flavorId] = (opts[:hwp_id] && opts[:hwp_id].length>0) ? opts[:hwp_id].to_i : 1 safely do server = rs.create_server(params) result = convert_instance_after_create(server, credentials.user, server.adminPass) end result end |
#delete_blob(credentials, bucket_id, blob_id, opts = {}) ⇒ Object
– Delete Blob –
299 300 301 302 303 304 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 299 def delete_blob(credentials, bucket_id, blob_id, opts={}) cf = cloudfiles_client(credentials) safely do cf.container(bucket_id).delete_object(blob_id) end end |
#delete_bucket(credentials, name, opts = {}) ⇒ Object
– Delete Bucket –
237 238 239 240 241 242 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 237 def delete_bucket(credentials, name, opts = {}) cf = cloudfiles_client(credentials) safely do cf.delete_container(name) end end |
#destroy_image(credentials, image_id) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 113 def destroy_image(credentials, image_id) rax_client = new_client(credentials) safely do image = rax_client.get_image(image_id.to_i) unless image.delete! raise "ERROR: Cannot delete image with ID:#{image_id}" end end end |
#destroy_instance(credentials, instance_id) ⇒ Object Also known as: stop_instance
146 147 148 149 150 151 152 153 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 146 def destroy_instance(credentials, instance_id) rs = new_client(credentials) safely do server = rs.get_server(instance_id.to_i) server.delete! convert_instance_after_create(server, credentials.user) end end |
#hardware_profiles(credentials, opts = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 35 def hardware_profiles(credentials, opts = {}) rs = new_client( credentials ) results = [] safely do results = rs.list_flavors.collect do |f| HardwareProfile.new(f[:id].to_s) do architecture 'x86_64' memory f[:ram].to_i storage f[:disk].to_i end end end filter_hardware_profiles(results, opts) end |
#images(credentials, opts = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 50 def images(credentials, opts=nil) rs = new_client(credentials) results = [] safely do results = rs.list_images.collect do |img| Image.new( :id => img[:id].to_s, :name => img[:name], :description => img[:name], :owner_id => credentials.user, :state => img[:status], :architecture => 'x86_64' ) end end profiles = hardware_profiles(credentials) results.each { |img| img.hardware_profiles = profiles } filter_on( results, :id, opts ) end |
#instances(credentials, opts = {}) ⇒ Object
Instances
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 160 def instances(credentials, opts={}) rs = new_client(credentials) insts = [] safely do begin if opts[:id] server = rs.get_server(opts[:id].to_i) insts << convert_instance_after_create(server, credentials.user) else insts = rs.list_servers_detail.collect do |server| convert_instance(server, credentials.user) end end rescue CloudServers::Exception::ItemNotFound end end insts = filter_on( insts, :id, opts ) insts = filter_on( insts, :state, opts ) insts end |
#realms(credentials, opts = nil) ⇒ Object
rackspace does not at this stage have realms… its all US/TX, all the time (at least at time of writing)
71 72 73 74 75 76 77 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 71 def realms(credentials, opts=nil) [Realm.new( { :id=>"us", :name=>"United States", :state=> "AVAILABLE" } )] end |
#reboot_instance(credentials, instance_id) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 137 def reboot_instance(credentials, instance_id) rs = new_client(credentials) safely do server = rs.get_server(instance_id.to_i) server.reboot! convert_instance_after_create(server, credentials.user) end end |
#run_on_instance(credentials, opts = {}) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 123 def run_on_instance(credentials, opts={}) target = instance(credentials, :id => opts[:id]) param = {} param[:credentials] = { :username => 'root', :password => opts[:password] } param[:port] = opts[:port] || '22' param[:ip] = opts[:ip] || target.public_addresses.first.address safely do Deltacloud::Runner.execute(opts[:cmd], param) end end |
#update_blob_metadata(credentials, opts = {}) ⇒ Object
- Update Blob Metahash -
321 322 323 324 325 326 327 328 329 330 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 321 def (credentials, opts={}) cf = cloudfiles_client(credentials) = opts['meta_hash'] #the set_metadata method actually places the 'X-Object-Meta-' prefix for us: BlobHelper::(, '') safely do blob = cf.container(opts['bucket']).object(opts[:id]) blob.() end end |
#valid_credentials?(credentials) ⇒ Boolean
184 185 186 187 188 189 190 191 |
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 184 def valid_credentials?(credentials) begin new_client(credentials) rescue return false end true end |