Class: AwsAuditor::Stack
- Inherits:
-
Object
- Object
- AwsAuditor::Stack
- Extended by:
- EC2Wrapper, OpsWorksWrapper
- Defined in:
- lib/aws_auditor/stack.rb
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.
9 10 11 12 13 |
# File 'lib/aws_auditor/stack.rb', line 9 def initialize(aws_stack) @id = aws_stack[:stack_id] @name = aws_stack[:name] @instances = get_instances.compact end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/aws_auditor/stack.rb', line 8 def id @id end |
#instances ⇒ Object
Returns the value of attribute instances.
8 9 10 |
# File 'lib/aws_auditor/stack.rb', line 8 def instances @instances end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/aws_auditor/stack.rb', line 8 def name @name end |
Class Method Details
.all ⇒ Object
37 38 39 40 41 42 |
# File 'lib/aws_auditor/stack.rb', line 37 def self.all stacks = opsworks.describe_stacks stacks.data[:stacks].map do |stack| new(stack) end.sort! { |a,b| a.name.downcase <=> b.name.downcase } if stacks end |
.all_instances ⇒ Object
44 45 46 |
# File 'lib/aws_auditor/stack.rb', line 44 def self.all_instances @all_instances ||= EC2Instance.instance_hash end |
Instance Method Details
#get_instances ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/aws_auditor/stack.rb', line 15 def get_instances instances = self.class.opsworks.describe_instances({stack_id: id})[:instances] instances.map do |instance| next unless instance[:status].to_s == 'online' self.class.all_instances[instance[:ec2_instance_id]] end end |
#pretty_print ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/aws_auditor/stack.rb', line 29 def pretty_print puts "----------------------------------" puts "#{@name}" puts "----------------------------------" print_instances puts "\n" end |
#print_instances ⇒ Object
23 24 25 26 27 |
# File 'lib/aws_auditor/stack.rb', line 23 def print_instances EC2Instance.instance_count_hash(self.instances).each do |key,value| say "<%= color('#{key}: #{value}', :white) %>" end end |