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
TODO: Optionally force refresh.
- #dry_run? ⇒ Boolean
-
#enable_host(host) ⇒ Object
Enables a host in the balancer.
-
#enabled_hosts ⇒ Object
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.
Constructor Details
#initialize(balancer_manager_url, dry_run = false) ⇒ BalancerManager
Returns a new instance of BalancerManager.
4 5 6 7 8 9 10 11 12 13 14 |
# 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 if !balancer_manager_url.match("127.0.0.1") && !dry_run @dry_run = true log_error log_error "Not running on localhost: Performing dry-run" log_error end end |
Instance Method Details
#balancer_manager_url ⇒ Object
Returns the url of the BalancerManager page.
53 54 55 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 53 def balancer_manager_url @balancer_manager_url end |
#balancer_name ⇒ Object
Returns the name of the balancer on the BalancerManager page.
48 49 50 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 48 def balancer_name @balancer_name ||= (get_doc/'a').select{|a_tag| a_tag.inner_text =~ /^balancer:/}.map{|a_tag| a_tag.inner_text}[0].sub('balancer://', '') end |
#disable_host(host) ⇒ Object
Disables a host from the balancer.
17 18 19 20 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 17 def disable_host(host) # TODO: Check Status toggle_host(host, 'Disable') end |
#disabled_hosts ⇒ Object
TODO: Optionally force refresh
41 42 43 44 45 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 41 def disabled_hosts hosts_array = [] hosts_with_status.select{|host,state| state != 'Ok'}.each{|host| hosts_array << host} hosts_array end |
#dry_run? ⇒ Boolean
67 68 69 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 67 def dry_run? @dry_run end |
#enable_host(host) ⇒ Object
Enables a host in the balancer
23 24 25 26 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 23 def enable_host(host) # TODO: Check Status toggle_host(host, 'Enable') end |
#enabled_hosts ⇒ Object
TODO: Optionally force refresh
34 35 36 37 38 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 34 def enabled_hosts hosts_array = [] hosts_with_status.select{|host,state| state == 'Ok'}.each{|host| hosts_array << host} hosts_array end |
#host_disabled?(host) ⇒ Boolean
TODO: Optionally force refresh
63 64 65 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 63 def host_disabled?(host) !enabled_hosts.include?(host) end |
#host_enabled?(host) ⇒ Boolean
TODO: Optionally force refresh
58 59 60 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 58 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.
29 30 31 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 29 def hosts @hosts ||= (get_doc/'a').select{|a_tag| a_tag.inner_text =~ /^http:/}.map{|a_tag| a_tag.inner_text} end |
#hosts_with_status ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/amphibian/balancerManagerDocument.rb', line 71 def hosts_with_status host_to_status = {} (get_doc/'a').select{|a_tag| a_tag.inner_text =~ /^http:/}.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 |