2012-07-05 13:05:50 -04:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'hp'))
|
|
|
|
require 'fog/block_storage'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module BlockStorage
|
|
|
|
class HP < Fog::Service
|
|
|
|
|
|
|
|
requires :hp_secret_key, :hp_account_id, :hp_tenant_id, :hp_avl_zone
|
2012-08-13 13:07:39 -04:00
|
|
|
recognizes :hp_auth_uri, :persistent, :connection_options, :hp_use_upass_auth_style, :hp_auth_version, :user_agent
|
2012-07-05 13:05:50 -04:00
|
|
|
|
2012-07-11 16:59:54 -04:00
|
|
|
model_path 'fog/hp/models/block_storage'
|
|
|
|
model :volume
|
|
|
|
collection :volumes
|
2012-07-05 13:05:50 -04:00
|
|
|
|
2012-08-09 16:44:59 -04:00
|
|
|
model :snapshot
|
|
|
|
collection :snapshots
|
|
|
|
|
2012-07-05 13:05:50 -04:00
|
|
|
request_path 'fog/hp/requests/block_storage'
|
2012-07-09 11:53:23 -04:00
|
|
|
request :create_volume
|
2012-07-05 17:03:14 -04:00
|
|
|
request :delete_volume
|
2012-07-05 16:41:24 -04:00
|
|
|
request :get_volume_details
|
2012-07-05 13:05:50 -04:00
|
|
|
request :list_volumes
|
|
|
|
|
2012-08-02 18:01:18 -04:00
|
|
|
request :create_snapshot
|
2012-08-02 19:12:54 -04:00
|
|
|
request :delete_snapshot
|
2012-08-02 14:33:03 -04:00
|
|
|
request :list_snapshots
|
2012-08-02 19:03:37 -04:00
|
|
|
request :get_snapshot_details
|
2012-08-02 14:33:03 -04:00
|
|
|
|
2012-07-05 13:05:50 -04:00
|
|
|
module Utils
|
|
|
|
|
2012-07-11 19:20:53 -04:00
|
|
|
def compute
|
|
|
|
@compute ||= Fog::Compute.new(
|
|
|
|
:provider => 'HP',
|
|
|
|
:hp_account_id => @hp_account_id,
|
|
|
|
:hp_secret_key => @hp_secret_key,
|
|
|
|
:hp_auth_uri => @hp_auth_uri,
|
|
|
|
:hp_tenant_id => @hp_tenant_id,
|
|
|
|
:hp_avl_zone => @hp_avl_zone,
|
|
|
|
:connection_options => @connection_options
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2012-07-05 13:05:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
include Utils
|
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {
|
2012-08-02 14:33:03 -04:00
|
|
|
:volumes => {},
|
|
|
|
:snapshots => {}
|
2012-07-05 13:05:50 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
@hp_account_id = options[:hp_account_id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.class.data[@hp_account_id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data.delete(@hp_account_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
include Utils
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
require 'multi_json'
|
|
|
|
@hp_secret_key = options[:hp_secret_key]
|
|
|
|
@hp_account_id = options[:hp_account_id]
|
2012-07-18 14:23:01 -04:00
|
|
|
@hp_auth_uri = options[:hp_auth_uri]
|
2012-07-05 13:05:50 -04:00
|
|
|
@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] = "Block 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 block storage endpoint
|
|
|
|
@hp_block_uri = credentials[:endpoint_url]
|
|
|
|
else
|
|
|
|
# Call the legacy v1.0/v1.1 authentication
|
|
|
|
credentials = Fog::HP.authenticate_v1(options, @connection_options)
|
|
|
|
# the user sends in the block storage endpoint
|
|
|
|
@hp_block_uri = options[:hp_auth_uri]
|
|
|
|
end
|
|
|
|
|
|
|
|
@auth_token = credentials[:auth_token]
|
|
|
|
@persistent = options[:persistent] || false
|
|
|
|
|
|
|
|
uri = URI.parse(@hp_block_uri)
|
|
|
|
@host = uri.host
|
|
|
|
@path = uri.path
|
|
|
|
@port = uri.port
|
|
|
|
@scheme = uri.scheme
|
|
|
|
|
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
|
|
|
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::BlockStorage::HP::NotFound.slurp(error)
|
|
|
|
else
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json}
|
|
|
|
response.body = MultiJson.decode(response.body)
|
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|