Sha256: 34551697983e06756b2ab3a9a0e5e67e1a5ca9eaccf30ad2ab1e8e1979611c7a

Contents?: true

Size: 830 Bytes

Versions: 6

Compression:

Stored size: 830 Bytes

Contents

require "active_support/all"

class SimControl::Hosts
  def initialize
    @hosts = {}
  end

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

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

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

  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

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

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
SimControl-0.1.5 lib/SimControl/hosts.rb
SimControl-0.1.4 lib/SimControl/hosts.rb
SimControl-0.1.3 lib/SimControl/hosts.rb
SimControl-0.1.2 lib/SimControl/hosts.rb
SimControl-0.1.1 lib/SimControl/hosts.rb
SimControl-0.1.0 lib/SimControl/hosts.rb