Class: SimControl::Hosts

Inherits:
Object
  • Object
show all
Defined in:
lib/SimControl/hosts.rb

Instance Method Summary collapse

Constructor Details

#initializeHosts

Returns a new instance of Hosts.



4
5
6
# File 'lib/SimControl/hosts.rb', line 4

def initialize
  @hosts = {}
end

Instance Method Details

#host_indices(hostname) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/SimControl/hosts.rb', line 23

def host_indices(hostname)
  return 0..0 unless @hosts.include? hostname
  start_index = 0
  @hosts.each do |current_hostname, options|
    cores = options[:cores]
    return (start_index ... (start_index + cores)) if current_hostname == hostname
    start_index += cores
  end
end

#number_of_coresObject



13
14
15
# File 'lib/SimControl/hosts.rb', line 13

def number_of_cores
  @hosts.map { |k, v| v[:cores] }.reduce(0, :+)
end

#partition(all_scenarios, hostname) ⇒ Object



17
18
19
20
21
# File 'lib/SimControl/hosts.rb', line 17

def partition(all_scenarios, hostname)
  return [] if number_of_cores == 0
  scenario_groups = all_scenarios.in_groups(number_of_cores, false)
  scenario_groups[host_indices hostname]
end

#process(&block) ⇒ Object



33
34
35
# File 'lib/SimControl/hosts.rb', line 33

def process(&block)
  instance_eval(&block)
end

#use(host, args = {}) ⇒ Object



8
9
10
11
# File 'lib/SimControl/hosts.rb', line 8

def use(host, args = {})
  args[:cores] = args[:cores] || 1
  @hosts[host] = args
end