Class: SportNginAwsAuditor::Stack
- Inherits:
-
Object
- Object
- SportNginAwsAuditor::Stack
- Extended by:
- EC2Wrapper, OpsWorksWrapper
- Defined in:
- lib/sport_ngin_aws_auditor/stack.rb
Class Attribute Summary collapse
-
.instances ⇒ Object
Returns the value of attribute instances.
-
.stacks ⇒ Object
Returns the value of attribute stacks.
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#instances ⇒ Object
Returns the value of attribute instances.
-
#name ⇒ Object
Returns the value of attribute name.
Attributes included from OpsWorksWrapper
Attributes included from EC2Wrapper
Class Method Summary collapse
Instance Method Summary collapse
- #get_instances ⇒ Object
-
#initialize(aws_stack) ⇒ Stack
constructor
A new instance of Stack.
- #pretty_print ⇒ Object
- #print_instances ⇒ Object
Constructor Details
#initialize(aws_stack) ⇒ Stack
Returns a new instance of Stack.
13 14 15 16 17 |
# File 'lib/sport_ngin_aws_auditor/stack.rb', line 13 def initialize(aws_stack) @id = aws_stack[:stack_id] @name = aws_stack[:name] @instances = get_instances.compact end |
Class Attribute Details
.instances ⇒ Object
Returns the value of attribute instances.
9 10 11 |
# File 'lib/sport_ngin_aws_auditor/stack.rb', line 9 def instances @instances end |
.stacks ⇒ Object
Returns the value of attribute stacks.
9 10 11 |
# File 'lib/sport_ngin_aws_auditor/stack.rb', line 9 def stacks @stacks end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
12 13 14 |
# File 'lib/sport_ngin_aws_auditor/stack.rb', line 12 def id @id end |
#instances ⇒ Object
Returns the value of attribute instances.
12 13 14 |
# File 'lib/sport_ngin_aws_auditor/stack.rb', line 12 def instances @instances end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/sport_ngin_aws_auditor/stack.rb', line 12 def name @name end |
Class Method Details
.all ⇒ Object
42 43 44 45 46 47 |
# File 'lib/sport_ngin_aws_auditor/stack.rb', line 42 def self.all return @stacks if @stacks @stacks = opsworks.describe_stacks.data[:stacks].map do |stack| new(stack) end.sort! { |a,b| a.name.downcase <=> b.name.downcase } end |
.all_instances ⇒ Object
49 50 51 |
# File 'lib/sport_ngin_aws_auditor/stack.rb', line 49 def self.all_instances @all_instances ||= EC2Instance.instance_hash end |
.instances_without_stack ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/sport_ngin_aws_auditor/stack.rb', line 53 def self.instances_without_stack all #simply getting all stacks to make sure instance stack_ids is set all_instances.map do |id, instance| next if instance.stack_id instance end.compact end |
Instance Method Details
#get_instances ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/sport_ngin_aws_auditor/stack.rb', line 19 def get_instances return @instances if @instances @instances = self.class.opsworks.describe_instances({stack_id: id})[:instances].map do |instance| next unless instance[:status].to_s == 'online' self.class.all_instances[instance[:ec2_instance_id]].stack_id = id self.class.all_instances[instance[:ec2_instance_id]] end end |
#pretty_print ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/sport_ngin_aws_auditor/stack.rb', line 34 def pretty_print puts "----------------------------------" puts "#{@name}" puts "----------------------------------" print_instances puts "\n" end |
#print_instances ⇒ Object
28 29 30 31 32 |
# File 'lib/sport_ngin_aws_auditor/stack.rb', line 28 def print_instances EC2Instance.instance_count_hash(self.instances).each do |key,value| say "<%= color('#{key}: #{value}', :white) %>" end end |