Class: Slugforge::HostGroup
- Inherits:
-
Object
- Object
- Slugforge::HostGroup
show all
- Defined in:
- lib/slugforge/models/host_group.rb,
lib/slugforge/models/host_group/aws_tag_group.rb,
lib/slugforge/models/host_group/hostname_group.rb,
lib/slugforge/models/host_group/ip_address_group.rb,
lib/slugforge/models/host_group/ec2_instance_group.rb,
lib/slugforge/models/host_group/security_group_group.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(pattern, compute) ⇒ HostGroup
Returns a new instance of HostGroup.
23
24
25
|
# File 'lib/slugforge/models/host_group.rb', line 23
def initialize(pattern, compute)
@name = pattern
end
|
Instance Attribute Details
#hosts ⇒ Object
Returns the value of attribute hosts.
9
10
11
|
# File 'lib/slugforge/models/host_group.rb', line 9
def hosts
@hosts
end
|
#name ⇒ Object
Returns the value of attribute name.
9
10
11
|
# File 'lib/slugforge/models/host_group.rb', line 9
def name
@name
end
|
Class Method Details
.detect(pattern, compute) ⇒ Object
59
60
61
62
63
|
# 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) ⇒ Object
Instance Method Details
#hosts_for_action(action) ⇒ Object
55
56
57
|
# File 'lib/slugforge/models/host_group.rb', line 55
def hosts_for_action(action)
@hosts.select { |host| host.has_action?(action) }
end
|
#install_all ⇒ Object
27
28
29
30
|
# 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) ⇒ Object
38
39
40
41
42
|
# 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) ⇒ Object
32
33
34
35
36
|
# 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 ⇒ Object
44
45
46
47
48
49
|
# File 'lib/slugforge/models/host_group.rb', line 44
def sorted_hosts
@hosts.sort_by { |host| host.ip }
end
|
#success? ⇒ Boolean
51
52
53
|
# File 'lib/slugforge/models/host_group.rb', line 51
def success?
@hosts.all?(&:success?)
end
|