Class: BigBrother::IPVS
- Inherits:
-
Object
- Object
- BigBrother::IPVS
- Defined in:
- lib/big_brother/ipvs.rb
Instance Method Summary collapse
- #_group_by_fwmark(parsed_lines) ⇒ Object
- #edit_node(fwmark, address, weight) ⇒ Object
-
#initialize(executor = ShellExecutor.new) ⇒ IPVS
constructor
A new instance of IPVS.
- #running_configuration ⇒ Object
- #start_cluster(fwmark, scheduler) ⇒ Object
- #start_node(fwmark, address, weight) ⇒ Object
- #stop_cluster(fwmark) ⇒ Object
- #stop_node(fwmark, address) ⇒ Object
Constructor Details
#initialize(executor = ShellExecutor.new) ⇒ IPVS
Returns a new instance of IPVS.
3 4 5 |
# File 'lib/big_brother/ipvs.rb', line 3 def initialize(executor = ShellExecutor.new) @executor = executor end |
Instance Method Details
#_group_by_fwmark(parsed_lines) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/big_brother/ipvs.rb', line 42 def _group_by_fwmark(parsed_lines) parsed_lines.inject({}) do |accum, parsed_line| accum[parsed_line[:fwmark]] ||= [] accum[parsed_line[:fwmark]] << parsed_line[:real_server] accum end end |
#edit_node(fwmark, address, weight) ⇒ Object
15 16 17 |
# File 'lib/big_brother/ipvs.rb', line 15 def edit_node(fwmark, address, weight) @executor.invoke("ipvsadm --edit-server --fwmark-service #{fwmark} --real-server #{address} --ipip --weight #{weight}") end |
#running_configuration ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/big_brother/ipvs.rb', line 27 def running_configuration raw_output, status = @executor.invoke("ipvsadm --save --numeric") parsed_lines = raw_output.split("\n").map do |line| next if line =~ /-A/ { :fwmark => line.slice(/-f (\d+)/, 1), :real_server => line.slice(/-r ([0-9\.]+)/, 1) } end _group_by_fwmark(parsed_lines.compact) end |
#start_cluster(fwmark, scheduler) ⇒ Object
7 8 9 |
# File 'lib/big_brother/ipvs.rb', line 7 def start_cluster(fwmark, scheduler) @executor.invoke("ipvsadm --add-service --fwmark-service #{fwmark} --scheduler #{scheduler}") end |
#start_node(fwmark, address, weight) ⇒ Object
19 20 21 |
# File 'lib/big_brother/ipvs.rb', line 19 def start_node(fwmark, address, weight) @executor.invoke("ipvsadm --add-server --fwmark-service #{fwmark} --real-server #{address} --ipip --weight #{weight}") end |
#stop_cluster(fwmark) ⇒ Object
11 12 13 |
# File 'lib/big_brother/ipvs.rb', line 11 def stop_cluster(fwmark) @executor.invoke("ipvsadm --delete-service --fwmark-service #{fwmark}") end |
#stop_node(fwmark, address) ⇒ Object
23 24 25 |
# File 'lib/big_brother/ipvs.rb', line 23 def stop_node(fwmark, address) @executor.invoke("ipvsadm --delete-server --fwmark-service #{fwmark} --real-server #{address}") end |