Sha256: 0886a8e798b8af559f9ba7051badfff8628992ae822151e38c53a22f3974ea1e

Contents?: true

Size: 705 Bytes

Versions: 1

Compression:

Stored size: 705 Bytes

Contents

require 'oscar'
require 'ipaddress'

class Oscar::Networking

  def initialize(yaml_config)

    range       = yaml_config["pool"]
    @domainname = yaml_config["domainname"]
    @network = IPAddress.parse(range)

    @pool  = []
    @nodes = {}

    @network.each_host { |h| @pool << h }
    @iterator = @pool.each

  end

  def register(node)
    next_addr = @iterator.next.to_s

    node.networking = self
    node.address    = next_addr

    @nodes[next_addr] = node
  end

  def hosts_for(node)
    arr = []

    arr << ['127.0.0.1', ['localhost']]
    arr << ['127.0.1.1', [node.name]]

    @nodes.each_pair { |address, n| arr << [address, [n.name, "#{n.name}.#{@domainname}"]] }

    arr
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oscar-0.2.0alpha4 lib/oscar/networking.rb