Class: Fog::HP::LB::Real
- Inherits:
-
Object
- Object
- Fog::HP::LB::Real
- Defined in:
- lib/monkey/hp/lb.rb,
lib/monkey/hp/requests/lb/get_version.rb,
lib/monkey/hp/requests/lb/list_limits.rb,
lib/monkey/hp/requests/lb/list_versions.rb,
lib/monkey/hp/requests/lb/list_protocols.rb,
lib/monkey/hp/requests/lb/get_virtual_ips.rb,
lib/monkey/hp/requests/lb/list_algorithms.rb,
lib/monkey/hp/requests/lb/get_load_balancer.rb,
lib/monkey/hp/requests/lb/list_load_balancers.rb,
lib/monkey/hp/requests/lb/create_load_balancer.rb,
lib/monkey/hp/requests/lb/delete_load_balancer.rb,
lib/monkey/hp/requests/lb/update_load_balancer.rb,
lib/monkey/hp/requests/lb/get_load_balancer_node.rb,
lib/monkey/hp/requests/lb/list_load_balancer_nodes.rb,
lib/monkey/hp/requests/lb/create_load_balancer_node.rb,
lib/monkey/hp/requests/lb/delete_load_balancer_node.rb,
lib/monkey/hp/requests/lb/update_load_balancer_node.rb,
lib/monkey/hp/requests/lb/list_load_balancer_virtual_ips.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
Instance Method Summary collapse
- #create_load_balancer(name, nodes, options = {}) ⇒ Object
- #create_load_balancer_node(load_balancer_id, options = {}) ⇒ Object
- #delete_load_balancer(instance_id) ⇒ Object
- #delete_load_balancer_node(instance_id, node_id) ⇒ Object
- #get_load_balancer(load_balancer_id) ⇒ Object
- #get_load_balancer_node(load_balancer_id, node_id) ⇒ Object
-
#get_version(version_id) ⇒ Object
Get details for existing database flavor instance.
- #get_virtual_ips(load_balancer_id) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_algorithms ⇒ Object
- #list_limits ⇒ Object
- #list_load_balancer_nodes(load_balancer_id) ⇒ Object
- #list_load_balancer_virtual_ips(load_balancer_id) ⇒ Object
- #list_load_balancers ⇒ Object
- #list_protocols ⇒ Object
- #list_versions ⇒ Object
- #reload ⇒ Object
- #request(params, parse_json = true, &block) ⇒ Object
- #update_load_balancer(load_balancer_id, options = ()) ⇒ Object
- #update_load_balancer_node(load_balancer_id, node_id, condition) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/monkey/hp/lb.rb', line 112 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 @hp_secret_key = [:hp_secret_key] @hp_auth_uri = [:hp_auth_uri] @connection_options = [:connection_options] || {} ### Set an option to use the style of authentication desired; :v1 or :v2 (default) auth_version = [:hp_auth_version] || :v2 ### Pass the service name for object storage to the authentication call [:hp_service_type] = "Load Balancer" @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 block storage endpoint @hp_block_uri = credentials[:endpoint_url] else # Call the legacy v1.0/v1.1 authentication credentials = Fog::HP.authenticate_v1(, @connection_options) # the user sends in the block storage endpoint @hp_block_uri = [:hp_auth_uri] end @auth_token = credentials[:auth_token] @persistent = [: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 |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
109 110 111 |
# File 'lib/monkey/hp/lb.rb', line 109 def credentials @credentials end |
Instance Method Details
#create_load_balancer(name, nodes, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/monkey/hp/requests/lb/create_load_balancer.rb', line 26 def create_load_balancer(name, nodes, ={}) data = { "name" => name, "nodes" => nodes } = Hash[.map{ |k, v| [k.to_s, v] }] data['port'] = ['port'] if ['port'] data['protocol'] = ['protocol'] if ['protocol'] data['algorithm'] = ['algorithm'] if ['algorithm'] unless ['virtualIps'].nil? unless ['virtualIps'].empty? data['virtualIps'] = [] for vip in ['virtualIps'] data['virtualIps'] << vip end end end response = request( :body => Fog::JSON.encode(data), :expects => 202, :method => 'POST', :path => "loadbalancers" ) response end |
#create_load_balancer_node(load_balancer_id, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/monkey/hp/requests/lb/create_load_balancer_node.rb', line 26 def create_load_balancer_node(load_balancer_id, ={}) data = {} if ['nodes'] data['nodes'] = [] for node in ['nodes'] hsh = node.dup hsh.delete(:load_balancer_id) data['nodes'] << hsh end end response = request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'POST', :path => "loadbalancers/#{load_balancer_id}/nodes" ) end |
#delete_load_balancer(instance_id) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/monkey/hp/requests/lb/delete_load_balancer.rb', line 27 def delete_load_balancer(instance_id) response = request( :expects => 202, :method => 'DELETE', :path => "loadbalancers/#{instance_id}" ) response end |
#delete_load_balancer_node(instance_id, node_id) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/monkey/hp/requests/lb/delete_load_balancer_node.rb', line 27 def delete_load_balancer_node(instance_id, node_id) response = request( :expects => [204,202], :method => 'DELETE', :path => "loadbalancers/#{instance_id}/nodes/#{node_id}" ) response end |
#get_load_balancer(load_balancer_id) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/monkey/hp/requests/lb/get_load_balancer.rb', line 26 def get_load_balancer(load_balancer_id) response = request( :expects => 200, :method => 'GET', :path => "loadbalancers/#{load_balancer_id}" ) response end |
#get_load_balancer_node(load_balancer_id, node_id) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/monkey/hp/requests/lb/get_load_balancer_node.rb', line 26 def get_load_balancer_node(load_balancer_id, node_id) response = request( :expects => 200, :method => 'GET', :path => "loadbalancers/#{load_balancer_id}/nodes/#{node_id}" ) response end |
#get_version(version_id) ⇒ Object
Get details for existing database flavor instance
Parameters
-
flavor_id<~Integer> - Id of the flavor to get
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
TBD
-
37 38 39 40 41 42 43 44 45 |
# File 'lib/monkey/hp/requests/lb/get_version.rb', line 37 def get_version(version_id) response = request( :expects => 200, :method => 'GET', :path => "/#{version_id}/", :version => true ) response end |
#get_virtual_ips(load_balancer_id) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/monkey/hp/requests/lb/get_virtual_ips.rb', line 26 def get_virtual_ips(load_balancer_id) response = request( :expects => 200, :method => 'GET', :path => "loadbalancers/#{load_balancer_id}/virtualips" ) response end |
#list_algorithms ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/monkey/hp/requests/lb/list_algorithms.rb', line 26 def list_algorithms response = request( :expects => 200, :method => 'GET', :path => 'algorithms' ) response end |
#list_limits ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/monkey/hp/requests/lb/list_limits.rb', line 27 def list_limits response = request( :expects => 200, :method => 'GET', :path => 'limits' ) response end |
#list_load_balancer_nodes(load_balancer_id) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/monkey/hp/requests/lb/list_load_balancer_nodes.rb', line 26 def list_load_balancer_nodes(load_balancer_id) response = request( :expects => 200, :method => 'GET', :path => "loadbalancers/#{load_balancer_id}/nodes" ) response end |
#list_load_balancer_virtual_ips(load_balancer_id) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/monkey/hp/requests/lb/list_load_balancer_virtual_ips.rb', line 26 def list_load_balancer_virtual_ips(load_balancer_id) response = request( :expects => 200, :method => 'GET', :path => "loadbalancers/#{load_balancer_id}/virtualips" ) response end |
#list_load_balancers ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/monkey/hp/requests/lb/list_load_balancers.rb', line 26 def list_load_balancers response = request( :expects => 200, :method => 'GET', :path => 'loadbalancers' ) response end |
#list_protocols ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/monkey/hp/requests/lb/list_protocols.rb', line 26 def list_protocols response = request( :expects => 200, :method => 'GET', :path => 'protocols' ) response end |
#list_versions ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/monkey/hp/requests/lb/list_versions.rb', line 27 def list_versions request( :expects => [200, 204], :method => 'GET', :path => "" ) end |
#reload ⇒ Object
157 158 159 |
# File 'lib/monkey/hp/lb.rb', line 157 def reload @connection.reset end |
#request(params, parse_json = true, &block) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/monkey/hp/lb.rb', line 161 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] || {}), :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 |
#update_load_balancer(load_balancer_id, options = ()) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/monkey/hp/requests/lb/update_load_balancer.rb', line 26 def update_load_balancer(load_balancer_id, =()) request( :body => Fog::JSON.encode(), :expects => [202,200], :method => 'PUT', :path => "loadbalancers/#{load_balancer_id}" ) end |
#update_load_balancer_node(load_balancer_id, node_id, condition) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/monkey/hp/requests/lb/update_load_balancer_node.rb', line 26 def update_load_balancer_node(load_balancer_id, node_id, condition) data = { #ENABLED | DISABLED "condition" => condition } request( :body => Fog::JSON.encode(data), :expects => [202,204], :method => 'PUT', :path => "loadbalancers/#{load_balancer_id}/nodes/#{node_id}" ) end |