Sha256: 29c2b44d8173dc07825f44f350ed55d8d201eda46ac69ca8b4d0470b103a2d3b

Contents?: true

Size: 1.47 KB

Versions: 14

Compression:

Stored size: 1.47 KB

Contents

module BigBrother
  class IPVS
    def initialize(executor = ShellExecutor.new)
      @executor = executor
    end

    def start_cluster(fwmark, scheduler)
      @executor.invoke("ipvsadm --add-service --fwmark-service #{fwmark} --scheduler #{scheduler}")
    end

    def stop_cluster(fwmark)
      @executor.invoke("ipvsadm --delete-service --fwmark-service #{fwmark}")
    end

    def edit_node(fwmark, address, weight)
      @executor.invoke("ipvsadm --edit-server --fwmark-service #{fwmark} --real-server #{address} --ipip --weight #{weight}")
    end

    def start_node(fwmark, address, weight)
      @executor.invoke("ipvsadm --add-server --fwmark-service #{fwmark} --real-server #{address} --ipip --weight #{weight}")
    end

    def stop_node(fwmark, address)
      @executor.invoke("ipvsadm --delete-server --fwmark-service #{fwmark} --real-server #{address}")
    end

    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


    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
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
big_brother-0.8.8.1 lib/big_brother/ipvs.rb
big_brother-0.8.8 lib/big_brother/ipvs.rb
big_brother-0.8.7 lib/big_brother/ipvs.rb
big_brother-0.6.8 lib/big_brother/ipvs.rb
big_brother-0.6.7 lib/big_brother/ipvs.rb
big_brother-0.6.6 lib/big_brother/ipvs.rb
big_brother-0.6.5 lib/big_brother/ipvs.rb
big_brother-0.4.1 lib/big_brother/ipvs.rb
big_brother-0.4.0 lib/big_brother/ipvs.rb
big_brother-0.3.1 lib/big_brother/ipvs.rb
big_brother-0.3.0 lib/big_brother/ipvs.rb
big_brother-0.2.1 lib/big_brother/ipvs.rb
big_brother-0.2.0 lib/big_brother/ipvs.rb
big_brother-0.1.0 lib/big_brother/ipvs.rb