Class: CloudLB::ConnectionThrottle
- Inherits:
-
Object
- Object
- CloudLB::ConnectionThrottle
- Defined in:
- lib/cloudlb/connection_throttle.rb
Instance Attribute Summary collapse
-
#max_connection_rate ⇒ Object
Returns the value of attribute max_connection_rate.
-
#max_connections ⇒ Object
Returns the value of attribute max_connections.
-
#min_connections ⇒ Object
Returns the value of attribute min_connections.
-
#rate_interval ⇒ Object
Returns the value of attribute rate_interval.
Instance Method Summary collapse
-
#destroy! ⇒ Object
Removes the current health monitor.
-
#enabled? ⇒ Boolean
Returns true if the connection throttle is defined and has data, returns false if not.
-
#initialize(load_balancer) ⇒ ConnectionThrottle
constructor
Initializes a new CloudLB::ConnectionThrottle object with the current values.
- #populate ⇒ Object (also: #refresh)
-
#update(options = {}) ⇒ Object
Updates (or creates) the connection throttle with the supplied arguments.
Constructor Details
#initialize(load_balancer) ⇒ ConnectionThrottle
Initializes a new CloudLB::ConnectionThrottle object with the current values. If there is no connection throttle currently defined, the enabled? method returns false.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cloudlb/connection_throttle.rb', line 11 def initialize(load_balancer) @connection = load_balancer.connection @load_balancer = load_balancer @lbmgmthost = @connection.lbmgmthost @lbmgmtpath = @connection.lbmgmtpath @lbmgmtport = @connection.lbmgmtport @lbmgmtscheme = @connection.lbmgmtscheme populate return self end |
Instance Attribute Details
#max_connection_rate ⇒ Object
Returns the value of attribute max_connection_rate.
6 7 8 |
# File 'lib/cloudlb/connection_throttle.rb', line 6 def max_connection_rate @max_connection_rate end |
#max_connections ⇒ Object
Returns the value of attribute max_connections.
5 6 7 |
# File 'lib/cloudlb/connection_throttle.rb', line 5 def max_connections @max_connections end |
#min_connections ⇒ Object
Returns the value of attribute min_connections.
4 5 6 |
# File 'lib/cloudlb/connection_throttle.rb', line 4 def min_connections @min_connections end |
#rate_interval ⇒ Object
Returns the value of attribute rate_interval.
7 8 9 |
# File 'lib/cloudlb/connection_throttle.rb', line 7 def rate_interval @rate_interval end |
Instance Method Details
#destroy! ⇒ Object
Removes the current health monitor. Returns true if successful, exception otherwise.
>> monitor.destroy!
=> true
98 99 100 101 102 103 |
# File 'lib/cloudlb/connection_throttle.rb', line 98 def destroy! response = @connection.lbreq("DELETE",@lbmgmthost,"#{@lbmgmtpath}/loadbalancers/#{CloudLB.escape(@load_balancer.id.to_s)}/connectionthrottle",@lbmgmtport,@lbmgmtscheme) CloudLB::Exception.raise_exception(response) unless response.code.to_s.match(/^20.$/) @enabled = false true end |
#enabled? ⇒ Boolean
Returns true if the connection throttle is defined and has data, returns false if not.
37 38 39 |
# File 'lib/cloudlb/connection_throttle.rb', line 37 def enabled? @enabled end |
#populate ⇒ Object Also known as: refresh
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cloudlb/connection_throttle.rb', line 22 def populate response = @connection.lbreq("GET",@lbmgmthost,"#{@lbmgmtpath}/loadbalancers/#{CloudLB.escape(@load_balancer.id.to_s)}/connectionthrottle",@lbmgmtport,@lbmgmtscheme) CloudLB::Exception.raise_exception(response) unless response.code.to_s.match(/^20.$/) data = JSON.parse(response.body)['connectionThrottle'] @enabled = data == {} ? false : true return nil unless @enabled @min_connections = data["minConnections"] @max_connections = data["maxConnections"] @max_connection_rate = data["maxConnectionRate"] @rate_interval = data["rateInterval"] true end |
#update(options = {}) ⇒ Object
Updates (or creates) the connection throttle with the supplied arguments
To create a health monitor for the first time, you must supply all required options. However, to modify an existing monitor, you need only supply the the value that you want to change.
Options include:
* :max_connections - Maximum number of connection to allow for a single IP address. *required*
* :min_connections - Allow at least this number of connections per IP address before applying throttling restrictions. *required*
* :max_connection_rate - Maximum number of connections allowed from a single IP address in the defined :rate_interval. *required*
* :rate_interval - Frequency (in seconds) at which the maxConnectionRate is assessed. For example, a :max_connection_rate of 30
with a :rate_interval of 60 would allow a maximum of 30 connections per minute for a single IP address. *required*
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cloudlb/connection_throttle.rb', line 53 def update(={}) data = Hash.new data['maxConnections'] = [:max_connections] if [:max_connections] data['minConnections'] = [:min_connections] if [:min_connections] data['maxConnectionRate'] = [:max_connection_rate] if [:max_connection_rate] data['rateInterval'] = [:rate_interval] if [:rate_interval] response = @connection.lbreq("PUT",@lbmgmthost,"#{@lbmgmtpath}/loadbalancers/#{CloudLB.escape(@load_balancer.id.to_s)}/connectionthrottle",@lbmgmtport,@lbmgmtscheme,{},data.to_json) CloudLB::Exception.raise_exception(response) unless response.code.to_s.match(/^20.$/) populate true end |