Class: Amphibian::BalancerManager
- Inherits:
-
Object
- Object
- Amphibian::BalancerManager
- Defined in:
- lib/amphibian/balancerManagerDocument.rb
Instance Method Summary collapse
-
#balancer_manager_url ⇒ Object
Returns the url of the BalancerManager page.
-
#balancer_name ⇒ Object
Returns the name of the balancer on the BalancerManager page.
-
#disable_host(host) ⇒ Object
Disables a host from the balancer.
-
#disabled_hosts ⇒ Object
Get an array of hosts that are not in ‘Ok’ state — TODO: Optionally force refresh +++.
- #dry_run? ⇒ Boolean
-
#enable_host(host) ⇒ Object
Enables a host in the balancer.
-
#enabled_hosts ⇒ Object
Get an array of hosts that are in ‘Ok’ state — TODO: Optionally force refresh +++.
-
#host_disabled?(host) ⇒ Boolean
TODO: Optionally force refresh.
-
#host_enabled?(host) ⇒ Boolean
TODO: Optionally force refresh.
-
#hosts ⇒ Object
Returns an array of strings indicated the balancer members parsed out of the BalancerManager page.
- #hosts_with_status ⇒ Object
-
#initialize(balancer_manager_url, dry_run = false) ⇒ BalancerManager
constructor
A new instance of BalancerManager.
- #nonce ⇒ Object
Constructor Details
#initialize(balancer_manager_url, dry_run = false) ⇒ BalancerManager
Returns a new instance of BalancerManager.
4 5 6 7 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 4 def initialize(balancer_manager_url, dry_run = false) @balancer_manager_url = balancer_manager_url @dry_run = dry_run end |
Instance Method Details
#balancer_manager_url ⇒ Object
Returns the url of the BalancerManager page.
55 56 57 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 55 def balancer_manager_url @balancer_manager_url end |
#balancer_name ⇒ Object
Returns the name of the balancer on the BalancerManager page.
47 48 49 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 47 def balancer_name @balancer_name ||= get_doc2().css('h3').to_s.scan(/\/\/([^"]*)</)[0][0] end |
#disable_host(host) ⇒ Object
Disables a host from the balancer.
10 11 12 13 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 10 def disable_host(host) # TODO: Check Status toggle_host(host, 'Disable') end |
#disabled_hosts ⇒ Object
Get an array of hosts that are not in ‘Ok’ state
TODO: Optionally force refresh +++
40 41 42 43 44 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 40 def disabled_hosts hosts_array = [] hosts_with_status.select{|host,state| state != 'Ok'}.each{|host, state| hosts_array << host} hosts_array end |
#dry_run? ⇒ Boolean
69 70 71 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 69 def dry_run? @dry_run end |
#enable_host(host) ⇒ Object
Enables a host in the balancer
16 17 18 19 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 16 def enable_host(host) # TODO: Check Status toggle_host(host, 'Enable') end |
#enabled_hosts ⇒ Object
Get an array of hosts that are in ‘Ok’ state
TODO: Optionally force refresh +++
30 31 32 33 34 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 30 def enabled_hosts hosts_array = [] hosts_with_status.select{|host,state| state == 'Ok'}.each{|host, state| hosts_array << host} hosts_array end |
#host_disabled?(host) ⇒ Boolean
TODO: Optionally force refresh
65 66 67 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 65 def host_disabled?(host) !enabled_hosts.include?(host) end |
#host_enabled?(host) ⇒ Boolean
TODO: Optionally force refresh
60 61 62 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 60 def host_enabled?(host) enabled_hosts.include?(host) end |
#hosts ⇒ Object
Returns an array of strings indicated the balancer members parsed out of the BalancerManager page.
22 23 24 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 22 def hosts @hosts ||= (get_doc/'a').select{|a_tag| a_tag.inner_text =~ /^http[s]?:/}.map{|a_tag| a_tag.inner_text} end |
#hosts_with_status ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 73 def hosts_with_status host_to_status = {} (get_doc/'a').select{|a_tag| a_tag.inner_text =~ /^http[s]?:/}.each do |a_tag| host_to_status[a_tag.inner_text] = (a_tag.parent.parent.children[6].inner_text.strip) end host_to_status end |
#nonce ⇒ Object
51 52 53 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 51 def nonce @nonce ||= get_doc2().css('a').first.to_s.scan(/nonce=([^"]*)">/)[0][0] end |