mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
beginnings for LB adapter
This commit is contained in:
parent
608e81e0d9
commit
708822b6d9
17 changed files with 406 additions and 0 deletions
|
@ -60,6 +60,7 @@ module Fog
|
|||
service(:storage, 'hp/storage', 'Storage')
|
||||
service(:block_storage, 'hp/block_storage', 'BlockStorage')
|
||||
service(:dns, 'hp/dns', 'DNS')
|
||||
service(:lb, 'hp/lb',"LB")
|
||||
|
||||
# legacy swauth 1.0/1.1 style authentication
|
||||
def self.authenticate_v1(options, connection_options = {})
|
||||
|
|
149
lib/fog/hp/lb.rb
Normal file
149
lib/fog/hp/lb.rb
Normal file
|
@ -0,0 +1,149 @@
|
|||
require 'fog/hp'
|
||||
|
||||
module Fog
|
||||
module HP
|
||||
class LB < Fog::Service
|
||||
|
||||
requires :hp_secret_key, :hp_tenant_id, :hp_avl_zone
|
||||
recognizes :hp_auth_uri
|
||||
recognizes :persistent, :connection_options
|
||||
recognizes :hp_use_upass_auth_style, :hp_auth_version, :user_agent
|
||||
recognizes :hp_access_key, :hp_account_id # :hp_account_id is deprecated use hp_access_key instead
|
||||
|
||||
secrets :hp_secret_key
|
||||
|
||||
model_path 'fog/hp/models/lb'
|
||||
model :algorithm
|
||||
collection :algorithms
|
||||
model :limit
|
||||
collection :limits
|
||||
model :load_balancer
|
||||
collection :load_balancers
|
||||
model :node
|
||||
collection :nodes
|
||||
model :protocol
|
||||
collection :protocols
|
||||
model :version
|
||||
model :versions
|
||||
model :virtual_id
|
||||
model :virtual_ips
|
||||
|
||||
class Mock
|
||||
include Utils
|
||||
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {
|
||||
:volumes => {},
|
||||
:snapshots => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@data = nil
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
# deprecate hp_account_id
|
||||
if options[:hp_account_id]
|
||||
Fog::Logger.deprecation(":hp_account_id is deprecated, please use :hp_access_key instead.")
|
||||
@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
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data[@hp_access_key]
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.data.delete(@hp_access_key)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Real
|
||||
include Utils
|
||||
|
||||
def initialize(options={})
|
||||
# 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]
|
||||
@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] = "Load Balancer"
|
||||
@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::HP::BlockStorage::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
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
14
lib/fog/hp/requests/lb/create_load_balancer.rb
Normal file
14
lib/fog/hp/requests/lb/create_load_balancer.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
|
||||
end
|
||||
class Mock
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/fog/hp/requests/lb/create_load_balancer_node.rb
Normal file
14
lib/fog/hp/requests/lb/create_load_balancer_node.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
|
||||
end
|
||||
class Mock
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/fog/hp/requests/lb/delete_load_balancer.rb
Normal file
14
lib/fog/hp/requests/lb/delete_load_balancer.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
|
||||
end
|
||||
class Mock
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/fog/hp/requests/lb/delete_node_balancer_node.rb
Normal file
14
lib/fog/hp/requests/lb/delete_node_balancer_node.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
|
||||
end
|
||||
class Mock
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/fog/hp/requests/lb/get_load_balancer.rb
Normal file
14
lib/fog/hp/requests/lb/get_load_balancer.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
|
||||
end
|
||||
class Mock
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/fog/hp/requests/lb/get_load_balancer_node.rb
Normal file
14
lib/fog/hp/requests/lb/get_load_balancer_node.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
|
||||
end
|
||||
class Mock
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/fog/hp/requests/lb/get_version.rb
Normal file
14
lib/fog/hp/requests/lb/get_version.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
|
||||
end
|
||||
class Mock
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/fog/hp/requests/lb/get_virtual_ips.rb
Normal file
14
lib/fog/hp/requests/lb/get_virtual_ips.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
|
||||
end
|
||||
class Mock
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/hp/requests/lb/list_algorithms.rb
Normal file
26
lib/fog/hp/requests/lb/list_algorithms.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
def list_algorithms
|
||||
response = request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'algorithms'
|
||||
)
|
||||
response
|
||||
end
|
||||
end
|
||||
class Mock
|
||||
def list_algorithms
|
||||
response = Excon::Response.new
|
||||
|
||||
response
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
lib/fog/hp/requests/lb/list_limits.rb
Normal file
28
lib/fog/hp/requests/lb/list_limits.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
|
||||
def list_limits
|
||||
response = request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'limits'
|
||||
)
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
class Mock
|
||||
def list_limits
|
||||
response = Excon::Response.new
|
||||
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
lib/fog/hp/requests/lb/list_load_balancers.rb
Normal file
19
lib/fog/hp/requests/lb/list_load_balancers.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
def list_load_balancers
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
class Mock
|
||||
def list_load_balancers
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/hp/requests/lb/list_protocols.rb
Normal file
25
lib/fog/hp/requests/lb/list_protocols.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
def list_protocols
|
||||
response = request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'protocols'
|
||||
)
|
||||
response
|
||||
end
|
||||
end
|
||||
class Mock
|
||||
def list_protocols
|
||||
response = Excon::Response.new
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
lib/fog/hp/requests/lb/list_versions.rb
Normal file
18
lib/fog/hp/requests/lb/list_versions.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
def list_versions
|
||||
|
||||
end
|
||||
end
|
||||
class Mock
|
||||
def list_versions
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/fog/hp/requests/lb/update_load_balancer.rb
Normal file
14
lib/fog/hp/requests/lb/update_load_balancer.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
|
||||
end
|
||||
class Mock
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/fog/hp/requests/lb/update_load_balancer_node.rb
Normal file
14
lib/fog/hp/requests/lb/update_load_balancer_node.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module HP
|
||||
class BlockStorage
|
||||
class LB
|
||||
class Real
|
||||
|
||||
end
|
||||
class Mock
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue