Class: AwsAuditor::Stack

Inherits:
Object
  • Object
show all
Extended by:
EC2Wrapper, OpsWorksWrapper
Defined in:
lib/aws_auditor/stack.rb

Instance Attribute Summary collapse

Attributes included from OpsWorksWrapper

#opsworks

Attributes included from EC2Wrapper

#ec2

Class Method Summary collapse

Instance Method Summary collapse

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

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/aws_auditor/stack.rb', line 8

def id
  @id
end

#instancesObject

Returns the value of attribute instances.



8
9
10
# File 'lib/aws_auditor/stack.rb', line 8

def instances
  @instances
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/aws_auditor/stack.rb', line 8

def name
  @name
end

Class Method Details

.allObject



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_instancesObject



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_instancesObject



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_printObject



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


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