Module: Capistrano::DataPlaneApi::ShowState
- Defined in:
- lib/capistrano/data_plane_api/show_state.rb
Overview
Creates a human readable summary of the state of HAProxy backends and servers to stdout.
Class Method Summary collapse
Class Method Details
.call ⇒ String
14 15 16 17 18 19 20 21 22 23 24 25 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/capistrano/data_plane_api/show_state.rb', line 14 def call # rubocop:disable Metrics/MethodLength pastel = ::Pastel.new result = ::String.new result << pastel.blue.bold('HAProxy State') result << "\n" result << pastel.bold.yellow(::Time.now.to_s) result << "\n\n" config = ::DataPlaneApi::Configuration.new.tap do |c| c.logger = ::Logger.new($stdout) c.logger.level = ::Logger::FATAL c.timeout = 2 end ::Capistrano::DataPlaneApi.configuration.backends.each do |backend| result << ::TTY::Box.frame(title: { top_left: backend_name(backend) }) do b = ::String.new servers = ::Capistrano::DataPlaneApi.get_backend_servers_settings(backend.name, config: config).body servers.each do |server| operational_state = operational_state(server) admin_state = admin_state(server) b << ::TTY::Box.frame(title: { top_left: server_name(server) }, border: :thick) do s = ::String.new s << " admin_state: #{admin_state}\n" s << "operational_state: #{operational_state}\n" s end end b rescue Error, ::Faraday::ConnectionFailed, ::Faraday::TimeoutError b << pastel.bold.bright_red('Unavailable!') b << "\n" b end end result end |