2011-06-15 02:13:18 -04:00
|
|
|
module Fog
|
|
|
|
module HP
|
|
|
|
class Storage < Fog::Service
|
|
|
|
|
|
|
|
requires :hp_password, :hp_username
|
2011-06-17 14:49:19 -04:00
|
|
|
recognizes :hp_host, :hp_port, :hp_auth_path, :hp_servicenet, :hp_cdn_ssl, :persistent
|
2011-06-15 02:13:18 -04:00
|
|
|
recognizes :provider # remove post deprecation
|
|
|
|
|
2011-06-16 00:36:38 -04:00
|
|
|
model_path 'fog/storage/models/hp'
|
|
|
|
model :directory
|
|
|
|
collection :directories
|
|
|
|
model :file
|
|
|
|
collection :files
|
2011-06-15 02:13:18 -04:00
|
|
|
|
|
|
|
request_path 'fog/storage/requests/hp'
|
|
|
|
request :delete_container
|
2011-06-15 17:59:06 -04:00
|
|
|
request :delete_object
|
2011-06-15 02:13:18 -04:00
|
|
|
request :get_container
|
|
|
|
request :get_containers
|
2011-06-15 17:59:06 -04:00
|
|
|
request :get_object
|
2011-06-15 14:33:26 -04:00
|
|
|
request :head_container
|
|
|
|
request :head_containers
|
2011-06-15 17:59:06 -04:00
|
|
|
request :head_object
|
2011-06-15 02:13:18 -04:00
|
|
|
request :put_container
|
2011-06-15 17:59:06 -04:00
|
|
|
request :put_object
|
2011-06-15 02:13:18 -04:00
|
|
|
|
|
|
|
module Utils
|
|
|
|
|
|
|
|
def cdn
|
2011-06-16 00:36:38 -04:00
|
|
|
# @cdn ||= Fog::CDN.new(
|
|
|
|
# :provider => 'HP',
|
|
|
|
# :hp_password => @hp_password,
|
|
|
|
# :hp_username => @hp_username
|
|
|
|
# )
|
|
|
|
nil
|
2011-06-15 02:13:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
include Utils
|
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
unless options.delete(:provider)
|
|
|
|
location = caller.first
|
|
|
|
warning = "[yellow][WARN] Fog::HP::Storage.new is deprecated, use Fog::Storage.new(:provider => 'HP') instead[/]"
|
|
|
|
warning << " [light_black](" << location << ")[/] "
|
|
|
|
Formatador.display_line(warning)
|
|
|
|
end
|
|
|
|
|
|
|
|
require 'mime/types'
|
|
|
|
@hp_password = options[:hp_password]
|
|
|
|
@hp_username = options[:hp_username]
|
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.class.data[@hp_username]
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data.delete(@hp_username)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
include Utils
|
|
|
|
attr_reader :hp_cdn_ssl
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
unless options.delete(:provider)
|
|
|
|
location = caller.first
|
|
|
|
warning = "[yellow][WARN] Fog::HP::Storage.new is deprecated, use Fog::Storage.new(:provider => 'HP') instead[/]"
|
|
|
|
warning << " [light_black](" << location << ")[/] "
|
|
|
|
Formatador.display_line(warning)
|
|
|
|
end
|
|
|
|
|
|
|
|
require 'mime/types'
|
|
|
|
require 'json'
|
|
|
|
@hp_password = options[:hp_password]
|
|
|
|
@hp_username = options[:hp_username]
|
|
|
|
@hp_cdn_ssl = options[:hp_cdn_ssl]
|
|
|
|
credentials = Fog::HP.authenticate(options)
|
|
|
|
@auth_token = credentials['X-Auth-Token']
|
|
|
|
|
|
|
|
uri = URI.parse(credentials['X-Storage-Url'])
|
|
|
|
@host = options[:hp_servicenet] == true ? "snet-#{uri.host}" : uri.host
|
|
|
|
@path = uri.path
|
|
|
|
@port = uri.port
|
|
|
|
@scheme = uri.scheme
|
|
|
|
Excon.ssl_verify_peer = false if options[:hp_servicenet] == true
|
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
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::HP::Storage::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
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|