class Etoro::Utility::MCollective::HAProxy

Public Instance Methods

check_run_status() click to toggle source
# File lib/etoro/utility/mcollective/haproxy.rb, line 47
def check_run_status
  @logger.info("Checking HAProxy for completion")

  begin
    timeout(@config[:timeout]) do
      if @haproxy_status.length == 0
        @logger.error('No HAProxy or HAProxy Entry Found')
        raise 'No HAProxy or HAProxy Entry Found'
      end
      until @haproxy_status == {}
        @haproxy_status.each do |host, status|
          run = rpcclient(self.class.name.downcase.split('::').last, :chomp => true)
          run.identity_filter host
          run.progress = false
          results = run.status
          results.each do |result|
            if result[:data][:msg] == @state
              @logger.info("#{host} - HAProxy: #{result[:data][:msg]}")
              @haproxy_status.delete(host)
            else
              @logger.info("#{host} - HAProxy action not complete")
            end
          end
        end
        sleep @config[:wait_between_checks]
      end
    end
    rescue Timeout::Error
      @logger.error("HAProxy run timed out. Took more than #{@config[:timeout]} seconds")
  end
end
execute() click to toggle source
# File lib/etoro/utility/mcollective/haproxy.rb, line 16
def execute
  @state = ''
  case @config[:action]
    when 'enable'
      @state = 'UP'
    when 'maintenance'
      @state = 'DOWN'
  end
  @logger.info("HAProxy - Bringing #{@state}")
  @mc.send @config[:action]
  sleep @config[:wait_for_status]
  self.check_run_status
end
hosts() click to toggle source
# File lib/etoro/utility/mcollective/haproxy.rb, line 39
def hosts
  hosts = []
  @haproxy_status.each_key do |host|
    hosts.push host
  end
  hosts
end
status() click to toggle source
# File lib/etoro/utility/mcollective/haproxy.rb, line 30
def status
  @haproxy_status = {}
  @logger.info("Getting HAProxy status")
  @mc.status.each do |result|
    @haproxy_status[result[:sender]] = result[:data][:msg]
    @logger.info("#{result[:sender]} - HAProxy #{result[:data][:msg]}")
  end
end
validate(config) click to toggle source
# File lib/etoro/utility/mcollective/haproxy.rb, line 6
def validate(config)
  super
  unless config.has_key?(:action)
    raise RuntimeError, "config[:action] must be defined"
  end
  unless ['enable','maintenance'].include? config[:action]
    raise RuntimeError, "Haproxy service value must be either enable or maintenance"
  end
end