Class: Zool::ServerPool

Inherits:
Array
  • Object
show all
Defined in:
lib/zool/server_pool.rb

Constant Summary collapse

IP_FORMAT =
/^(?:25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)(?:\.(?:25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)){3}$|^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[a-z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)$/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_hostfile(hostsfile, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/zool/server_pool.rb', line 5

def self.from_hostfile(hostsfile, options = {})
  hosts = hostsfile.to_a.map { |host| host.split[0] }
  hosts.uniq!
  invalid_hosts = %w(127.0.0.1 255.255.255.255)
  hosts.reject! { |host| host !~ IP_FORMAT }
  hosts.reject! { |host| invalid_hosts.include?(host) }
  pool = self.new

  hosts.each do |host|
    # puts host
    server = Server.new(host, options)
    # puts server.hostname
    pool << server
  end
  pool
end

Instance Method Details

#<<(object) ⇒ Object Also known as: add



37
38
39
40
# File 'lib/zool/server_pool.rb', line 37

def <<(object)
  raise TypeError.new 'Invalid Argument' unless object.instance_of?(Server)
  super
end

#dump_keyfilesObject



43
44
45
46
47
48
# File 'lib/zool/server_pool.rb', line 43

def dump_keyfiles
  writer = KeyfileWriter.new
  keys.each do |key|
    writer.write(key)
  end
end

#fetch_keysObject



28
29
30
31
# File 'lib/zool/server_pool.rb', line 28

def fetch_keys
  call_for_pool(:fetch_keys)
  @keys_proxy = nil
end

#inspectObject



50
51
52
# File 'lib/zool/server_pool.rb', line 50

def inspect
  "#<Zool::ServerPool @servers=[#{servers.join(', ')}]>"
end

#keysObject



24
25
26
# File 'lib/zool/server_pool.rb', line 24

def keys
  @keys_proxy ||= KeysProxy.new(self)
end

#upload_keysObject



33
34
35
# File 'lib/zool/server_pool.rb', line 33

def upload_keys
  call_for_pool(:upload_keys)
end