Class: Centurion::DockerServerGroup

Inherits:
Object
  • Object
show all
Includes:
Logging, Enumerable
Defined in:
lib/centurion/docker_server_group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #info, #warn

Constructor Details

#initialize(hosts, docker_path, tls_params = {}) ⇒ DockerServerGroup

Returns a new instance of DockerServerGroup.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
# File 'lib/centurion/docker_server_group.rb', line 12

def initialize(hosts, docker_path, tls_params = {})
  raise ArgumentError.new('Bad Host list!') if hosts.nil? || hosts.empty?
  @hosts = hosts.map do |hostname|
    Centurion::DockerServer.new(hostname, docker_path, tls_params)
  end
end

Instance Attribute Details

#hostsObject (readonly)

Returns the value of attribute hosts.



10
11
12
# File 'lib/centurion/docker_server_group.rb', line 10

def hosts
  @hosts
end

Instance Method Details

#each(&block) ⇒ Object



19
20
21
22
23
24
# File 'lib/centurion/docker_server_group.rb', line 19

def each(&block)
  @hosts.each do |host|
    info "----- Connecting to Docker on #{host.hostname} -----"
    block.call(host)
  end
end

#each_in_parallel(&block) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/centurion/docker_server_group.rb', line 26

def each_in_parallel(&block)
  threads = @hosts.map do |host|
    Thread.new { block.call(host) }
  end

  threads.each { |t| t.join }
end