Class: ProxyMgr::Haproxy::Socket
- Inherits:
-
Object
- Object
- ProxyMgr::Haproxy::Socket
- Defined in:
- lib/proxymgr/haproxy/socket.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #disable(backend, host) ⇒ Object
- #enable(backend, host) ⇒ Object
-
#initialize(path) ⇒ Socket
constructor
A new instance of Socket.
- #servers ⇒ Object
- #shutdown(backend, host) ⇒ Object
- #stats ⇒ Object
- #write(cmd) ⇒ Object
Constructor Details
#initialize(path) ⇒ Socket
Returns a new instance of Socket.
8 9 10 |
# File 'lib/proxymgr/haproxy/socket.rb', line 8 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/proxymgr/haproxy/socket.rb', line 6 def path @path end |
Instance Method Details
#connected? ⇒ Boolean
45 46 47 48 49 50 51 52 |
# File 'lib/proxymgr/haproxy/socket.rb', line 45 def connected? begin with do |socket| socket.write "show info" end rescue Errno::ECONNREFUSED end end |
#disable(backend, host) ⇒ Object
23 24 25 |
# File 'lib/proxymgr/haproxy/socket.rb', line 23 def disable(backend, host) write "disable server #{backend}/#{host}" end |
#enable(backend, host) ⇒ Object
19 20 21 |
# File 'lib/proxymgr/haproxy/socket.rb', line 19 def enable(backend, host) write "enable server #{backend}/#{host}" end |
#servers ⇒ Object
31 32 33 34 35 36 |
# File 'lib/proxymgr/haproxy/socket.rb', line 31 def servers stats.each_with_object([]) do |stat, acc| next if %w(FRONTEND BACKEND).include? stat['svname'] acc << Server.new(self, stat) end end |
#shutdown(backend, host) ⇒ Object
27 28 29 |
# File 'lib/proxymgr/haproxy/socket.rb', line 27 def shutdown(backend, host) write "shutdown sessions server #{backend}/#{host}" end |
#stats ⇒ Object
12 13 14 15 16 17 |
# File 'lib/proxymgr/haproxy/socket.rb', line 12 def stats headers, *rest = write('show stat') headers = headers.gsub(/^# /, '').split(',') rest.pop rest.map { |d| Hash[headers.zip(d.split(','))] } end |
#write(cmd) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/proxymgr/haproxy/socket.rb', line 38 def write(cmd) with do |socket| socket.puts(cmd + "\n") socket.readlines.map(&:chomp) end end |