Class: Fog::Storage::HP::Real
- Inherits:
-
Object
- Object
- Fog::Storage::HP::Real
- Includes:
- Utils
- Defined in:
- lib/fog/hp/storage.rb,
lib/fog/hp/requests/storage/get_object.rb,
lib/fog/hp/requests/storage/put_object.rb,
lib/fog/hp/requests/storage/head_object.rb,
lib/fog/hp/requests/storage/post_object.rb,
lib/fog/hp/requests/storage/delete_object.rb,
lib/fog/hp/requests/storage/get_container.rb,
lib/fog/hp/requests/storage/put_container.rb,
lib/fog/hp/requests/storage/get_containers.rb,
lib/fog/hp/requests/storage/head_container.rb,
lib/fog/hp/requests/storage/post_container.rb,
lib/fog/hp/requests/storage/head_containers.rb,
lib/fog/hp/requests/storage/delete_container.rb,
lib/fog/hp/requests/storage/get_shared_object.rb,
lib/fog/hp/requests/storage/put_shared_object.rb,
lib/fog/hp/requests/storage/head_shared_object.rb,
lib/fog/hp/requests/storage/get_object_temp_url.rb,
lib/fog/hp/requests/storage/delete_shared_object.rb,
lib/fog/hp/requests/storage/get_shared_container.rb,
lib/fog/hp/requests/storage/head_shared_container.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#hp_cdn_ssl ⇒ Object
readonly
Returns the value of attribute hp_cdn_ssl.
Instance Method Summary collapse
-
#delete_container(name) ⇒ Object
Delete an existing container.
-
#delete_object(container, object) ⇒ Object
Delete an existing object.
-
#delete_shared_object(shared_object_url) ⇒ Object
Delete a shared object.
-
#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, options = {}, &block) ⇒ Object
Get details for an object.
-
#get_object_temp_url(container, object, expires, method) ⇒ Object
Generate a temporary url for an object.
-
#get_shared_container(shared_container_url, options = {}) ⇒ Object
Get details for a shared container.
-
#get_shared_object(shared_object_url, &block) ⇒ Object
Get details for a shared 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.
-
#head_shared_container(shared_container_url) ⇒ Object
List number of objects and total bytes stored for a shared container.
-
#head_shared_object(shared_object_url) ⇒ Object
Get headers for shared object.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#post_container(container, headers = {}) ⇒ Object
Create or update metadata for an existing container.
-
#post_object(container, object, headers = {}) ⇒ Object
Create or update metadata for an existing object.
-
#put_container(name, options = {}) ⇒ Object
Create a new container.
-
#put_object(container, object, data, options = {}, &block) ⇒ Object
Create a new object.
-
#put_shared_object(shared_container_url, object_name, data, options = {}, &block) ⇒ Object
Create a new object in a shared container.
- #reload ⇒ Object
- #request(params, parse_json = true, &block) ⇒ Object
-
#shared_request(params, parse_json = true, &block) ⇒ Object
this request is used only for get_shared_container and get_shared_object calls.
Methods included from Utils
#cdn, #create_temp_url, #generate_object_temp_url, #get_object_http_url, #get_object_https_url, #header_to_perm_acl, #perm_acl_to_header, #perm_to_acl, #public_url, #url
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 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 359 |
# File 'lib/fog/hp/storage.rb', line 305 def initialize(={}) # deprecate hp_account_id if [:hp_account_id] Fog::Logger.deprecation(":hp_account_id is deprecated, please use :hp_access_key instead.") [:hp_access_key] = .delete(:hp_account_id) end @hp_access_key = [:hp_access_key] unless @hp_access_key raise ArgumentError.new("Missing required arguments: hp_access_key. :hp_account_id is deprecated, please use :hp_access_key instead.") end if [:os_account_meta_temp_url_key] Fog::Logger.deprecation(":os_account_meta_temp_url_key is deprecated, and will be removed in a future release. please use the :openstack provider instead.") @os_account_meta_temp_url_key = .delete(:os_account_meta_temp_url_key) end @hp_secret_key = [:hp_secret_key] @hp_auth_uri = [:hp_auth_uri] @hp_cdn_ssl = [:hp_cdn_ssl] @connection_options = [:connection_options] || {} ### Set an option to use the style of authentication desired; :v1 or :v2 (default) ### A symbol is required, we should ensure that the value is loaded as a symbol auth_version = [:hp_auth_version] || :v2 auth_version = auth_version.to_s.downcase.to_sym ### Pass the service name for object storage to the authentication call [:hp_service_type] ||= "object-store" @hp_tenant_id = [:hp_tenant_id] @hp_avl_zone = [:hp_avl_zone] ### Make the authentication call if (auth_version == :v2) # Call the control services authentication credentials = Fog::HP.authenticate_v2(, @connection_options) # the CS service catalog returns the cdn endpoint @hp_storage_uri = credentials[:endpoint_url] @hp_cdn_uri = credentials[:cdn_endpoint_url] @credentials = credentials else # Call the legacy v1.0/v1.1 authentication credentials = Fog::HP.authenticate_v1(, @connection_options) # the user sends in the cdn endpoint @hp_storage_uri = [:hp_auth_uri] @hp_cdn_uri = [:hp_cdn_uri] end @auth_token = credentials[:auth_token] uri = URI.parse(@hp_storage_uri) @host = uri.host @path = uri.path @persistent = [:persistent] || false @port = uri.port @scheme = uri.scheme @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
302 303 304 |
# File 'lib/fog/hp/storage.rb', line 302 def credentials @credentials end |
#hp_cdn_ssl ⇒ Object (readonly)
Returns the value of attribute hp_cdn_ssl.
303 304 305 |
# File 'lib/fog/hp/storage.rb', line 303 def hp_cdn_ssl @hp_cdn_ssl end |
Instance Method Details
#delete_container(name) ⇒ Object
Delete an existing container
Parameters
-
name<~String> - Name of container to delete
10 11 12 13 14 15 16 17 |
# File 'lib/fog/hp/requests/storage/delete_container.rb', line 10 def delete_container(name) response = request( :expects => 204, :method => 'DELETE', :path => Fog::HP.escape(name) ) response end |
#delete_object(container, object) ⇒ Object
Delete an existing object
Parameters
-
container<~String> - Name of container to delete
-
object<~String> - Name of object to delete
11 12 13 14 15 16 17 18 |
# File 'lib/fog/hp/requests/storage/delete_object.rb', line 11 def delete_object(container, object) response = request( :expects => 204, :method => 'DELETE', :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" ) response end |
#delete_shared_object(shared_object_url) ⇒ Object
Delete a shared object
Parameters
-
shared_object_url<~String> - Url of the shared object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fog/hp/requests/storage/delete_shared_object.rb', line 10 def delete_shared_object(shared_object_url) # split up the shared object url uri = URI.parse(shared_object_url) path = uri.path response = shared_request( :expects => 204, :method => 'DELETE', :path => path ) response 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
-
-
-
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/hp/requests/storage/get_container.rb', line 30 def get_container(container, = {}) = .reject {|key, value| value.nil?} response = request( :expects => 200, :method => 'GET', :path => Fog::HP.escape(container), :query => {'format' => 'json'}.merge!() ) response 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
-
-
-
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/hp/requests/storage/get_containers.rb', line 19 def get_containers( = {}) = .reject {|key, value| value.nil?} response = request( :expects => [200, 204], :method => 'GET', :path => '', :query => {'format' => 'json'}.merge!() ) response end |
#get_object(container, object, options = {}, &block) ⇒ Object
Get details for an object
Parameters
-
container<~String> - Name of container to look in
-
object<~String> - Name of object to look for
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fog/hp/requests/storage/get_object.rb', line 11 def get_object(container, object, = {}, &block) if block_given? response = request( :response_block => block, :expects => [200, 206], :headers => , :method => 'GET', :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" ) else response = request({ :expects => [200, 206], :headers => , :method => 'GET', :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" }, false, &block) end response end |
#get_object_temp_url(container, object, expires, method) ⇒ Object
Generate a temporary url for an object
Parameters
-
container<~String> - Name of container
-
object<~String> - Name of object
-
expires<~Integer> - Time the temporary url expire in secs.
-
method<~String> - Allowed HTTP method GET, PUT, HEAD only
12 13 14 |
# File 'lib/fog/hp/requests/storage/get_object_temp_url.rb', line 12 def get_object_temp_url(container, object, expires, method) generate_object_temp_url(container, object, expires, method) end |
#get_shared_container(shared_container_url, options = {}) ⇒ Object
Get details for a shared container
Parameters
-
shared_container_url<~String> - Url of the shared container
-
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-Container-Object-Count’<~String> - Count of objects in container
-
‘X-Container-Bytes-Used’<~String> - Bytes used
-
‘X-Trans-Id’<~String> - Trans Id
-
-
body<~Array>:
-
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
-
-
-
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/hp/requests/storage/get_shared_container.rb', line 28 def get_shared_container(shared_container_url, = {}) = .reject {|key, value| value.nil?} # split up the shared container url uri = URI.parse(shared_container_url) path = uri.path response = shared_request( :expects => 200, :method => 'GET', :path => path, :query => {'format' => 'json'}.merge!() ) response end |
#get_shared_object(shared_object_url, &block) ⇒ Object
Get details for a shared object
Parameters
-
shared_object_url<~String> - Url of the shared object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fog/hp/requests/storage/get_shared_object.rb', line 10 def get_shared_object(shared_object_url, &block) # split up the shared object url uri = URI.parse(shared_object_url) path = uri.path if block_given? response = shared_request( :response_block => block, :expects => 200, :method => 'GET', :path => path ) else response = shared_request({ :expects => 200, :method => 'GET', :path => path }, false, &block) end response 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
-
-
15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/hp/requests/storage/head_container.rb', line 15 def head_container(container) response = request( :expects => 204, :method => 'HEAD', :path => Fog::HP.escape(container), :query => {'format' => 'json'} ) response 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
-
-
12 13 14 15 16 17 18 19 20 |
# File 'lib/fog/hp/requests/storage/head_containers.rb', line 12 def head_containers response = request( :expects => 204, :method => 'HEAD', :path => '', :query => {'format' => 'json'} ) response 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
11 12 13 14 15 16 17 18 |
# File 'lib/fog/hp/requests/storage/head_object.rb', line 11 def head_object(container, object) response = request({ :expects => 200, :method => 'HEAD', :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" }, false) response end |
#head_shared_container(shared_container_url) ⇒ Object
List number of objects and total bytes stored for a shared container
Parameters
-
shared_container_url<~String> - Url of the shared container
Returns
-
response<~Excon::Response>:
-
headers<~Hash>:
-
‘X-Container-Object-Count’<~String> - Count of containers
-
‘X-Container-Bytes-Used’<~String> - Bytes used
-
-
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/hp/requests/storage/head_shared_container.rb', line 15 def head_shared_container(shared_container_url) # split up the shared container url uri = URI.parse(shared_container_url) path = uri.path response = shared_request( :expects => 204, :method => 'HEAD', :path => path, :query => {'format' => 'json'} ) response end |
#head_shared_object(shared_object_url) ⇒ Object
Get headers for shared object
Parameters
-
shared_object_url<~String> - Url of the shared object
-
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fog/hp/requests/storage/head_shared_object.rb', line 10 def head_shared_object(shared_object_url) # split up the shared object url uri = URI.parse(shared_object_url) path = uri.path response = shared_request({ :expects => 200, :method => 'HEAD', :path => path }, false) response end |
#post_container(container, headers = {}) ⇒ Object
Create or update metadata for an existing container
Parameters
-
container<~String> - Name for existing container, should be < 256 bytes and must not contain ‘/’
-
headers<~Hash> - Hash of metadata name/value pairs
10 11 12 13 14 15 16 17 18 |
# File 'lib/fog/hp/requests/storage/post_container.rb', line 10 def post_container(container, headers = {}) response = request( :expects => 204, :headers => headers, :method => 'POST', :path => Fog::HP.escape(container) ) response end |
#post_object(container, object, headers = {}) ⇒ Object
Create or update metadata for an existing object
Parameters
-
container<~String> - Name of the existing container, should be < 256 bytes and must not contain ‘/’
-
object<~String> - Name of the existing object
-
headers<~Hash> - Hash of metadata name/value pairs
11 12 13 14 15 16 17 18 19 |
# File 'lib/fog/hp/requests/storage/post_object.rb', line 11 def post_object(container, object, headers = {}) response = request( :expects => 202, :headers => headers, :method => 'POST', :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" ) response end |
#put_container(name, options = {}) ⇒ Object
Create a new container
Parameters
-
name<~String> - Name for container, should be < 256 bytes and must not contain ‘/’
10 11 12 13 14 15 16 17 18 |
# File 'lib/fog/hp/requests/storage/put_container.rb', line 10 def put_container(name, = {}) response = request( :expects => [201, 202], :headers => , :method => 'PUT', :path => Fog::HP.escape(name) ) response end |
#put_object(container, object, data, options = {}, &block) ⇒ Object
Create a new object
Parameters
-
container<~String> - Name for container, should be < 256 bytes and must not contain ‘/’
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fog/hp/requests/storage/put_object.rb', line 10 def put_object(container, object, data, = {}, &block) data = Fog::Storage.parse_data(data) headers = data[:headers].merge!() if block_given? headers['Transfer-Encoding'] = 'chunked' headers.delete('Content-Length') return request( :request_block => block, :expects => 201, :headers => headers, :method => 'PUT', :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" ) end if headers.key?('Transfer-Encoding') headers.delete('Content-Length') end response = request( :body => data[:body], :expects => 201, :headers => headers, :method => 'PUT', :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" ) response end |
#put_shared_object(shared_container_url, object_name, data, options = {}, &block) ⇒ Object
Create a new object in a shared container
Parameters
-
shared_container_url<~String> - Shared url for the container
-
object<~String> - Name of the object
-
options<~Hash> - header options
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/hp/requests/storage/put_shared_object.rb', line 12 def put_shared_object(shared_container_url, object_name, data, = {}, &block) # split up the shared object url uri = URI.parse(shared_container_url) path = uri.path data = Fog::Storage.parse_data(data) headers = data[:headers].merge!() if block_given? headers['Transfer-Encoding'] = 'chunked' headers.delete('Content-Length') return shared_request( :request_block => block, :expects => 201, :headers => headers, :method => 'PUT', :path => "#{path}/#{Fog::HP.escape(object_name)}" ) end if headers.key?('Transfer-Encoding') headers.delete('Content-Length') end response = shared_request( :body => data[:body], :expects => 201, :headers => headers, :method => 'PUT', :path => "#{path}/#{Fog::HP.escape(object_name)}" ) response end |
#reload ⇒ Object
361 362 363 |
# File 'lib/fog/hp/storage.rb', line 361 def reload @connection.reset end |
#request(params, parse_json = true, &block) ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/fog/hp/storage.rb', line 365 def request(params, parse_json = true, &block) begin response = @connection.request(params.merge!({ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :path => "#{@path}/#{params[:path]}", }), &block) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Storage::HP::NotFound.slurp(error) else error end end if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json} response.body = Fog::JSON.decode(response.body) end response end |
#shared_request(params, parse_json = true, &block) ⇒ Object
this request is used only for get_shared_container and get_shared_object calls
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/fog/hp/storage.rb', line 390 def shared_request(params, parse_json = true, &block) begin response = @connection.request(params.merge!({ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :path => "#{params[:path]}", }), &block) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Storage::HP::NotFound.slurp(error) when Excon::Errors::Forbidden Fog::HP::Errors::Forbidden.slurp(error) else error end end if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json} response.body = Fog::JSON.decode(response.body) end response end |