Class: Rhapr::Interface

Inherits:
Object
  • Object
show all
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

Methods included from Environment

#check_running, #has_exec?, #pid, #socket

Instance Method Details

#clear_counterstrue, false Also known as: clear

Returns Whether or not the ‘clear counters’ command was successful.

Returns:

  • (true, false)

    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?

Returns:

  • (Array<Fixnum, Fixnum>)

    An Array with Two Elements: the Current Weight and the Initial Weight.

Raises:

  • (ArgumentError)


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.

Parameters:

  • message (String, #to_s)

    The message to be sent to HAProxy

See Also:

  • Rhapr::Interface#read_full


12
13
14
15
16
17
# File 'lib/rhapr/interface.rb', line 12

def send(message)
  sock = socket

  write(sock, message)
  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_errorsObject 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_infoHash{String => String} Also known as: info

Returns The ‘show info’ attributes, from HAProxy, parsed into a Hash.

Returns:

  • (Hash{String => String})

    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_statArray<Hash{String => String}> Also known as: stat

Returns The ‘show stat’ response, from HAProxy, parsed into an Array of Hashes.

Returns:

  • (Array<Hash{String => String}>)

    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