Class: InstanceCollection

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/maws/instance_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(members = []) ⇒ InstanceCollection

Returns a new instance of InstanceCollection.



6
7
8
# File 'lib/maws/instance_collection.rb', line 6

def initialize(members = [])
  @members = members.sort_by {|m| [m.region, m.zone.to_s, m.role.to_s, m.index || 1]}
end

Instance Attribute Details

#membersObject

Returns the value of attribute members.



4
5
6
# File 'lib/maws/instance_collection.rb', line 4

def members
  @members
end

Instance Method Details

#*(x) ⇒ Object



26
27
28
# File 'lib/maws/instance_collection.rb', line 26

def *(x)
  @members * x
end

#add(instance) ⇒ Object



10
11
12
# File 'lib/maws/instance_collection.rb', line 10

def add(instance)
  @members << instance
end

#aliveObject



67
68
69
# File 'lib/maws/instance_collection.rb', line 67

def alive
  self.matching(:alive? => true)
end

#awsObject



63
64
65
# File 'lib/maws/instance_collection.rb', line 63

def aws
  self.matching(:groups => 'aws')
end

#eachObject



14
15
16
# File 'lib/maws/instance_collection.rb', line 14

def each
  @members.each {|m| yield m}
end

#ebsObject



91
92
93
# File 'lib/maws/instance_collection.rb', line 91

def ebs
  with_service(:ebs)
end

#empty?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/maws/instance_collection.rb', line 18

def empty?
  @members.empty?
end

#firstObject



22
23
24
# File 'lib/maws/instance_collection.rb', line 22

def first
  @members.first
end

#matching(filters = {}) ⇒ Object



30
31
32
# File 'lib/maws/instance_collection.rb', line 30

def matching(filters = {})
  InstanceCollection.new(self.find_all {|i| i.matches?(filters)})
end

#not_aliveObject



71
72
73
# File 'lib/maws/instance_collection.rb', line 71

def not_alive
  self.matching(:alive? => false)
end

#not_matching(filters) ⇒ Object



34
35
36
# File 'lib/maws/instance_collection.rb', line 34

def not_matching(filters)
  InstanceCollection.new(self.find_all {|i| !i.matches?(filters)})
end

#not_specifiedObject



59
60
61
# File 'lib/maws/instance_collection.rb', line 59

def not_specified
  self.not_matching(:groups => 'specified')
end

#rolesObject



42
43
44
# File 'lib/maws/instance_collection.rb', line 42

def roles
  map{|i| i.role}.uniq
end

#roles_in_order_of(roles_list) ⇒ Object



50
51
52
# File 'lib/maws/instance_collection.rb', line 50

def roles_in_order_of(roles_list)
  roles.sort_by {|r| roles_list.index(r)}
end

#servicesObject



38
39
40
# File 'lib/maws/instance_collection.rb', line 38

def services
  self.map {|i| i.service}.uniq
end

#specifiedObject

scopes



55
56
57
# File 'lib/maws/instance_collection.rb', line 55

def specified
  self.matching(:groups => 'specified')
end

#with_approximate_status(status) ⇒ Object



95
96
97
# File 'lib/maws/instance_collection.rb', line 95

def with_approximate_status(status)
  self.matching(:approximate_status => status)
end

#with_role(role) ⇒ Object



79
80
81
# File 'lib/maws/instance_collection.rb', line 79

def with_role(role)
  self.matching(:role => role)
end

#with_service(service) ⇒ Object



75
76
77
# File 'lib/maws/instance_collection.rb', line 75

def with_service(service)
  self.matching(:service => service.to_sym)
end

#with_zone(zone) ⇒ Object



83
84
85
# File 'lib/maws/instance_collection.rb', line 83

def with_zone(zone)
  self.matching(:zone => zone)
end

#without_role(role) ⇒ Object



87
88
89
# File 'lib/maws/instance_collection.rb', line 87

def without_role(role)
  self.not_matching(:role => role)
end

#zonesObject



46
47
48
# File 'lib/maws/instance_collection.rb', line 46

def zones
  map{|i| i.zone}.uniq
end