class Slugforge::HostGroup

Attributes

hosts[R]
name[R]

Public Class Methods

detect(pattern, compute) click to toggle source
# File lib/slugforge/models/host_group.rb, line 59
def self.detect(pattern, compute)
  return nil unless pattern =~ self.matcher
  group = self.new(pattern, compute)
  group.hosts.empty? ? nil : group
end
discover(patterns, compute) click to toggle source
# File lib/slugforge/models/host_group.rb, line 11
def self.discover(patterns, compute)
  patterns.map do |pattern|
    IpAddressGroup.detect(pattern, compute) ||
    Ec2InstanceGroup.detect(pattern, compute) ||
    HostnameGroup.detect(pattern, compute) ||
    AwsTagGroup.detect(pattern, compute) ||
    SecurityGroupGroup.detect(pattern, compute) ||
    # If nothing detected, return a "null" group
    HostGroup.new(pattern, compute)
  end
end
new(pattern, compute) click to toggle source
# File lib/slugforge/models/host_group.rb, line 23
def initialize(pattern, compute)
  @name = pattern
end

Public Instance Methods

hosts_for_action(action) click to toggle source
# File lib/slugforge/models/host_group.rb, line 55
def hosts_for_action(action)
  @hosts.select { |host| host.has_action?(action) }
end
install_all() click to toggle source
# File lib/slugforge/models/host_group.rb, line 27
def install_all
  return if @hosts.nil?
  @hosts.each { |host| host.add_action(:install) }
end
install_number_of_hosts(value) click to toggle source
# File lib/slugforge/models/host_group.rb, line 38
def install_number_of_hosts(value)
  return if @hosts.nil?
  count = [@hosts.count, value].min
  sorted_hosts[0...count].each { |host| host.add_action(:install) }
end
install_percent_of_hosts(value) click to toggle source
# File lib/slugforge/models/host_group.rb, line 32
def install_percent_of_hosts(value)
  return if @hosts.nil?
  count = (@hosts.count * value / 100.0).ceil
  sorted_hosts[0...count].each { |host| host.add_action(:install) }
end
sorted_hosts() click to toggle source
# File lib/slugforge/models/host_group.rb, line 44
def sorted_hosts
  # We sort the hosts by IP to make the order deterministic before we filter
  # by number or percent. That way when we move from 5% to 10% we end up at
  # 10% of the hosts, not some value between 10% and 15%.
  @hosts.sort_by { |host| host.ip }
end
success?() click to toggle source
# File lib/slugforge/models/host_group.rb, line 51
def success?
  @hosts.all?(&:success?)
end