Class: Rhapr::Interface
- Inherits:
-
Object
- Object
- Rhapr::Interface
- Includes:
- Environment
- Defined in:
- lib/rhapr/interface.rb
Constant Summary collapse
- EMPTY =
"\n"
Instance Attribute Summary
Attributes included from Environment
#config, #config_path, #exec, #haproxy_pid, #socket_path
Instance Method Summary collapse
-
#clear_counters ⇒ true, false
(also: #clear)
Whether or not the ‘clear counters’ command was successful.
-
#disable(backend, server) ⇒ Object
@todo: Implement.
-
#enable(backend, server) ⇒ Object
@todo: Implement.
-
#get_weight(backend, server) ⇒ Array<Fixnum, Fixnum>
@todo: Allow the numeric id to be used as a parameter?.
-
#send(message) ⇒ Object
return [Array<String>] All of the output from HAProxy, read in.
-
#set_weight(backend, server, weight) ⇒ Object
@todo: Implement.
-
#show_errors ⇒ Object
(also: #errors)
@todo: Implement.
-
#show_info ⇒ Hash{String => String}
(also: #info)
The ‘show info’ attributes, from HAProxy, parsed into a Hash.
-
#show_sess(id) ⇒ Object
(also: #session)
@todo: Implement.
-
#show_stat ⇒ Array<Hash{String => String}>
(also: #stat)
The ‘show stat’ response, from HAProxy, parsed into an Array of Hashes.
Methods included from Environment
#check_running, #has_exec?, #pid, #socket
Instance Method Details
#clear_counters ⇒ true, false Also known as: clear
Returns Whether or not the ‘clear counters’ command was successful.
20 21 22 23 |
# File 'lib/rhapr/interface.rb', line 20 def clear_counters resp = send 'clear counters' resp == EMPTY end |
#disable(backend, server) ⇒ Object
@todo: Implement.
84 85 |
# File 'lib/rhapr/interface.rb', line 84 def disable(backend, server) end |
#enable(backend, server) ⇒ Object
@todo: Implement.
88 89 |
# File 'lib/rhapr/interface.rb', line 88 def enable(backend, server) end |
#get_weight(backend, server) ⇒ Array<Fixnum, Fixnum>
@todo: Allow the numeric id to be used as a parameter?
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rhapr/interface.rb', line 67 def get_weight(backend, server) resp = send "get weight #{backend}/#{server}" resp.match /([[:digit:]]+) \(initial ([[:digit:]]+)\)/ weight, initial = $1, $2 return [weight.to_i, initial.to_i] if weight and initial raise ArgumentError.new("HAProxy did not recognize the specified Backend/Server. Response from HAProxy: #{resp}") end |
#send(message) ⇒ Object
return [Array<String>] All of the output from HAProxy, read in.
12 13 14 15 16 17 |
# File 'lib/rhapr/interface.rb', line 12 def send() sock = socket write(sock, ) read_full(sock) end |
#set_weight(backend, server, weight) ⇒ Object
@todo: Implement. @todo: Allow the numeric id to be used as a parameter?
80 81 |
# File 'lib/rhapr/interface.rb', line 80 def set_weight(backend, server, weight) end |
#show_errors ⇒ Object Also known as: errors
@todo: Implement. I do not know the possible errors that may be present, nor how HAProxy will render them.
56 57 |
# File 'lib/rhapr/interface.rb', line 56 def show_errors end |
#show_info ⇒ Hash{String => String} Also known as: info
Returns The ‘show info’ attributes, from HAProxy, parsed into a Hash.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rhapr/interface.rb', line 27 def show_info resp = send 'show info' attrs = resp.split("\n") attrs.map! {|line| _attr, *_val = line.split(/: /) [ _attr, _val.join ] } Hash[ attrs ] end |
#show_sess(id) ⇒ Object Also known as: session
@todo: Implement. Not sure how this should look. It’s likely that I will want to ‘interpret’ the data that is spit out.
61 62 |
# File 'lib/rhapr/interface.rb', line 61 def show_sess(id) end |
#show_stat ⇒ Array<Hash{String => String}> Also known as: stat
Returns The ‘show stat’ response, from HAProxy, parsed into an Array of Hashes.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rhapr/interface.rb', line 42 def show_stat resp = send 'show stat' resp.gsub!(/^# /, '') csv = CSV.parse(resp, :headers => true) out = csv.map(&:to_a) out.map!{|row| Hash[ row ]} return(out) end |