Class: Fog::Storage::Rackspace::Real
- Inherits:
-
Object
- Object
- Fog::Storage::Rackspace::Real
- Includes:
- Utils
- Defined in:
- lib/fog/storage/rackspace.rb,
lib/fog/storage/requests/rackspace/get_object.rb,
lib/fog/storage/requests/rackspace/put_object.rb,
lib/fog/storage/requests/rackspace/head_object.rb,
lib/fog/storage/requests/rackspace/delete_object.rb,
lib/fog/storage/requests/rackspace/get_container.rb,
lib/fog/storage/requests/rackspace/put_container.rb,
lib/fog/storage/requests/rackspace/get_containers.rb,
lib/fog/storage/requests/rackspace/head_container.rb,
lib/fog/storage/requests/rackspace/head_containers.rb,
lib/fog/storage/requests/rackspace/delete_container.rb,
lib/fog/storage/requests/rackspace/put_object_manifest.rb
Instance Attribute Summary collapse
-
#rackspace_cdn_ssl ⇒ Object
readonly
Returns the value of attribute rackspace_cdn_ssl.
Instance Method Summary collapse
-
#delete_container(name) ⇒ Object
Delete an existing container.
-
#delete_object(container, object) ⇒ Object
Delete an existing container.
-
#get_container(container, options = {}) ⇒ Object
Get details for container and total bytes stored.
-
#get_containers(options = {}) ⇒ Object
List existing storage containers.
-
#get_object(container, object, &block) ⇒ Object
Get details for object.
-
#head_container(container) ⇒ Object
List number of objects and total bytes stored.
-
#head_containers ⇒ Object
List number of containers and total bytes stored.
-
#head_object(container, object) ⇒ Object
Get headers for object.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#put_container(name) ⇒ Object
Create a new container.
-
#put_object(container, object, data, options = {}) ⇒ Object
Create a new object.
-
#put_object_manifest(container, object) ⇒ Object
Create a new object.
- #reload ⇒ Object
- #request(params, parse_json = true, &block) ⇒ Object
Methods included from Utils
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fog/storage/rackspace.rb', line 72 def initialize(={}) require 'mime/types' require 'json' @rackspace_api_key = [:rackspace_api_key] @rackspace_username = [:rackspace_username] @rackspace_cdn_ssl = [:rackspace_cdn_ssl] credentials = Fog::Rackspace.authenticate() @auth_token = credentials['X-Auth-Token'] uri = URI.parse(credentials['X-Storage-Url']) @host = [:rackspace_servicenet] == true ? "snet-#{uri.host}" : uri.host @path = uri.path @port = uri.port @scheme = uri.scheme Excon.ssl_verify_peer = false if [:rackspace_servicenet] == true @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", [:persistent]) end |
Instance Attribute Details
#rackspace_cdn_ssl ⇒ Object (readonly)
Returns the value of attribute rackspace_cdn_ssl.
70 71 72 |
# File 'lib/fog/storage/rackspace.rb', line 70 def rackspace_cdn_ssl @rackspace_cdn_ssl end |
Instance Method Details
#delete_container(name) ⇒ Object
Delete an existing container
Parameters
-
name<~String> - Name of container to delete
11 12 13 14 15 16 17 |
# File 'lib/fog/storage/requests/rackspace/delete_container.rb', line 11 def delete_container(name) request( :expects => 204, :method => 'DELETE', :path => URI.escape(name) ) end |
#delete_object(container, object) ⇒ Object
Delete an existing container
Parameters
-
container<~String> - Name of container to delete
-
object<~String> - Name of object to delete
12 13 14 15 16 17 18 |
# File 'lib/fog/storage/requests/rackspace/delete_object.rb', line 12 def delete_object(container, object) request( :expects => 204, :method => 'DELETE', :path => "#{URI.escape(container)}/#{URI.escape(object)}" ) end |
#get_container(container, options = {}) ⇒ Object
Get details for container and total bytes stored
Parameters
-
container<~String> - Name of container to retrieve info for
-
options<~String>:
-
‘limit’<~String> - Maximum number of objects to return
-
‘marker’<~String> - Only return objects whose name is greater than marker
-
‘prefix’<~String> - Limits results to those starting with prefix
-
‘path’<~String> - Return objects nested in the pseudo path
-
Returns
-
response<~Excon::Response>:
-
headers<~Hash>:
-
‘X-Account-Container-Count’<~String> - Count of containers
-
‘X-Account-Bytes-Used’<~String> - Bytes used
-
-
body<~Array>:
-
‘bytes’<~Integer> - Number of bytes used by container
-
‘count’<~Integer> - Number of items in container
-
‘name’<~String> - Name of container
-
item<~Hash>:
-
‘bytes’<~String> - Size of object
-
‘content_type’<~String> Content-Type of object
-
‘hash’<~String> - Hash of object (etag?)
-
‘last_modified’<~String> - Last modified timestamp
-
‘name’<~String> - Name of object
-
-
-
31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/storage/requests/rackspace/get_container.rb', line 31 def get_container(container, = {}) = .reject {|key, value| value.nil?} request( :expects => 200, :method => 'GET', :path => URI.escape(container), :query => {'format' => 'json'}.merge!() ) end |
#get_containers(options = {}) ⇒ Object
List existing storage containers
Parameters
-
options<~Hash>:
-
‘limit’<~Integer> - Upper limit to number of results returned
-
‘marker’<~String> - Only return objects with name greater than this value
-
Returns
-
response<~Excon::Response>:
-
body<~Array>:
-
container<~Hash>:
-
‘bytes’<~Integer>: - Number of bytes used by container
-
‘count’<~Integer>: - Number of items in container
-
‘name’<~String>: - Name of container
-
-
-
20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/storage/requests/rackspace/get_containers.rb', line 20 def get_containers( = {}) = .reject {|key, value| value.nil?} request( :expects => [200, 204], :method => 'GET', :path => '', :query => {'format' => 'json'}.merge!() ) end |
#get_object(container, object, &block) ⇒ Object
Get details for object
Parameters
-
container<~String> - Name of container to look in
-
object<~String> - Name of object to look for
12 13 14 15 16 17 18 19 |
# File 'lib/fog/storage/requests/rackspace/get_object.rb', line 12 def get_object(container, object, &block) request({ :block => block, :expects => 200, :method => 'GET', :path => "#{URI.escape(container)}/#{URI.escape(object)}" }, false, &block) end |
#head_container(container) ⇒ Object
List number of objects and total bytes stored
Parameters
-
container<~String> - Name of container to retrieve info for
Returns
-
response<~Excon::Response>:
-
headers<~Hash>:
-
‘X-Container-Object-Count’<~String> - Count of containers
-
‘X-Container-Bytes-Used’<~String> - Bytes used
-
-
16 17 18 19 20 21 22 23 |
# File 'lib/fog/storage/requests/rackspace/head_container.rb', line 16 def head_container(container) request( :expects => 204, :method => 'HEAD', :path => URI.escape(container), :query => {'format' => 'json'} ) end |
#head_containers ⇒ Object
List number of containers and total bytes stored
Returns
-
response<~Excon::Response>:
-
headers<~Hash>:
-
‘X-Account-Container-Count’<~String> - Count of containers
-
‘X-Account-Bytes-Used’<~String> - Bytes used
-
-
13 14 15 16 17 18 19 20 |
# File 'lib/fog/storage/requests/rackspace/head_containers.rb', line 13 def head_containers request( :expects => 204, :method => 'HEAD', :path => '', :query => {'format' => 'json'} ) end |
#head_object(container, object) ⇒ Object
Get headers for object
Parameters
-
container<~String> - Name of container to look in
-
object<~String> - Name of object to look for
12 13 14 15 16 17 18 |
# File 'lib/fog/storage/requests/rackspace/head_object.rb', line 12 def head_object(container, object) request({ :expects => 200, :method => 'HEAD', :path => "#{URI.escape(container)}/#{URI.escape(object)}" }, false) end |
#put_container(name) ⇒ Object
Create a new container
Parameters
-
name<~String> - Name for container, should be < 256 bytes and must not contain ‘/’
11 12 13 14 15 16 17 |
# File 'lib/fog/storage/requests/rackspace/put_container.rb', line 11 def put_container(name) request( :expects => [201, 202], :method => 'PUT', :path => URI.escape(name) ) end |
#put_object(container, object, data, options = {}) ⇒ Object
Create a new object
Parameters
-
container<~String> - Name for container, should be < 256 bytes and must not contain ‘/’
-
object<~String> - Name for object
-
data<~String|File> - data to upload
-
options<~Hash> - config headers for object. Defaults to {}.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/storage/requests/rackspace/put_object.rb', line 14 def put_object(container, object, data, = {}) data = Fog::Storage.parse_data(data) headers = data[:headers].merge!() request( :body => data[:body], :expects => 201, :headers => headers, :method => 'PUT', :path => "#{URI.escape(container)}/#{URI.escape(object)}" ) end |
#put_object_manifest(container, object) ⇒ Object
Create a new object
Parameters
-
container<~String> - Name for container, should be < 256 bytes and must not contain ‘/’
-
object<~String> - Name for object
12 13 14 15 16 17 18 19 20 |
# File 'lib/fog/storage/requests/rackspace/put_object_manifest.rb', line 12 def put_object_manifest(container, object) path = "#{URI.escape(container)}/#{URI.escape(object)}" request( :expects => 201, :headers => {'X-Object-Manifest' => path}, :method => 'PUT', :path => path ) end |
#reload ⇒ Object
90 91 92 |
# File 'lib/fog/storage/rackspace.rb', line 90 def reload @connection.reset end |
#request(params, parse_json = true, &block) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fog/storage/rackspace.rb', line 94 def request(params, parse_json = true, &block) begin response = @connection.request(params.merge!({ :headers => { 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :host => @host, :path => "#{@path}/#{params[:path]}", }), &block) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Storage::Rackspace::NotFound.slurp(error) else error end end if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json} response.body = JSON.parse(response.body) end response end |