# File lib/fog/hp/storage.rb, line 236 def initialize(options={}) require 'mime/types' # deprecate hp_account_id if options[:hp_account_id] Fog::Logger.deprecation(":hp_account_id is deprecated, please use :hp_access_key instead.") options[:hp_access_key] = options.delete(:hp_account_id) end @hp_access_key = options[: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 @hp_secret_key = options[:hp_secret_key] @hp_auth_uri = options[:hp_auth_uri] @hp_cdn_ssl = options[:hp_cdn_ssl] @connection_options = options[:connection_options] || {} ### Set an option to use the style of authentication desired; :v1 or :v2 (default) auth_version = options[:hp_auth_version] || :v2 ### Pass the service name for object storage to the authentication call options[:hp_service_type] = "Object Storage" @hp_tenant_id = options[:hp_tenant_id] @hp_avl_zone = options[:hp_avl_zone] ### Make the authentication call if (auth_version == :v2) # Call the control services authentication credentials = Fog::HP.authenticate_v2(options, @connection_options) # the CS service catalog returns the cdn endpoint @hp_storage_uri = credentials[:endpoint_url] @hp_cdn_uri = credentials[:cdn_endpoint_url] else # Call the legacy v1.0/v1.1 authentication credentials = Fog::HP.authenticate_v1(options, @connection_options) # the user sends in the cdn endpoint @hp_storage_uri = options[:hp_auth_uri] @hp_cdn_uri = options[:hp_cdn_uri] end @auth_token = credentials[:auth_token] uri = URI.parse(@hp_storage_uri) @host = uri.host @path = uri.path @persistent = options[:persistent] || false @port = uri.port @scheme = uri.scheme @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end
Delete an existing container
name<~String> - Name of container to delete
# File lib/fog/hp/requests/storage/delete_container.rb, line 11 def delete_container(name) response = request( :expects => 204, :method => 'DELETE', :path => Fog::HP.escape(name) ) response end
Delete an existing object
container<~String> - Name of container to delete
object<~String> - Name of object to delete
# File lib/fog/hp/requests/storage/delete_object.rb, line 12 def delete_object(container, object) response = request( :expects => 204, :method => 'DELETE', :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" ) response end
Get details for container and total bytes stored
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
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
# File lib/fog/hp/requests/storage/get_container.rb, line 31 def get_container(container, options = {}) options = options.reject {|key, value| value.nil?} response = request( :expects => 200, :method => 'GET', :path => Fog::HP.escape(container), :query => {'format' => 'json'}.merge!(options) ) response end
List existing storage containers
options<~Hash>:
'limit'<~Integer> - Upper limit to number of results returned
'marker'<~String> - Only return objects with name greater than this value
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
# File lib/fog/hp/requests/storage/get_containers.rb, line 20 def get_containers(options = {}) options = options.reject {|key, value| value.nil?} response = request( :expects => [200, 204], :method => 'GET', :path => '', :query => {'format' => 'json'}.merge!(options) ) response end
Get details for an object
container<~String> - Name of container to look in
object<~String> - Name of object to look for
# File lib/fog/hp/requests/storage/get_object.rb, line 12 def get_object(container, object, &block) if block_given? response = request( :response_block => block, :expects => 200, :method => 'GET', :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" ) else response = request({ :expects => 200, :method => 'GET', :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" }, false, &block) end response end
Generate a temporary url for an object
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
# File lib/fog/hp/requests/storage/get_object_temp_url.rb, line 14 def get_object_temp_url(container, object, expires, method) generate_object_temp_url(container, object, expires, method) end
List number of objects and total bytes stored
container<~String> - Name of container to retrieve info for
response<~Excon::Response>:
headers<~Hash>:
'X-Container-Object-Count'<~String> - Count of containers
'X-Container-Bytes-Used'<~String> - Bytes used
# File lib/fog/hp/requests/storage/head_container.rb, line 16 def head_container(container) response = request( :expects => 204, :method => 'HEAD', :path => Fog::HP.escape(container), :query => {'format' => 'json'} ) response end
List number of containers and total bytes stored
response<~Excon::Response>:
headers<~Hash>:
'X-Account-Container-Count'<~String> - Count of containers
'X-Account-Bytes-Used'<~String> - Bytes used
# File lib/fog/hp/requests/storage/head_containers.rb, line 13 def head_containers response = request( :expects => 204, :method => 'HEAD', :path => '', :query => {'format' => 'json'} ) response end
Get headers for object
container<~String> - Name of container to look in
object<~String> - Name of object to look for
# File lib/fog/hp/requests/storage/head_object.rb, line 12 def head_object(container, object) response = request({ :expects => 200, :method => 'HEAD', :path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" }, false) response end
Create a new container
name<~String> - Name for container, should be < 256 bytes and must not contain '/'
# File lib/fog/hp/requests/storage/put_container.rb, line 11 def put_container(name, options = {}) response = request( :expects => [201, 202], :headers => options, :method => 'PUT', :path => Fog::HP.escape(name) ) response end
Create a new object
container<~String> - Name for container, should be < 256 bytes and must not contain '/'
# File lib/fog/hp/requests/storage/put_object.rb, line 11 def put_object(container, object, data, options = {}, &block) data = Fog::Storage.parse_data(data) headers = data[:headers].merge!(options) 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.has_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
# File lib/fog/hp/storage.rb, line 285 def reload @connection.reset end
# File lib/fog/hp/storage.rb, line 289 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] || {}), :host => @host, :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'] =~ %{application/json} response.body = Fog::JSON.decode(response.body) end response end
Generated with the Darkfish Rdoc Generator 2.