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

Instance Method Summary collapse

Constructor Details

#initialize(aws_stack) ⇒ Stack

Returns a new instance of Stack.



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

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.



6
7
8
# File 'lib/aws_auditor/stack.rb', line 6

def id
  @id
end

#instancesObject

Returns the value of attribute instances.



6
7
8
# File 'lib/aws_auditor/stack.rb', line 6

def instances
  @instances
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/aws_auditor/stack.rb', line 6

def name
  @name
end

Instance Method Details

#all_instancesObject



31
32
33
# File 'lib/aws_auditor/stack.rb', line 31

def all_instances
  @all_instances ||= Instance.instance_hash
end

#get_instancesObject



13
14
15
16
17
18
19
# File 'lib/aws_auditor/stack.rb', line 13

def get_instances
  instances = self.class.opsworks.describe_instances({stack_id: id})[:instances]
  instances.map do |instance|
    next unless instance[:status].to_s == 'online'
    all_instances[instance[:ec2_instance_id]].to_s
  end
end

#pretty_printObject



21
22
23
24
25
26
27
28
29
# File 'lib/aws_auditor/stack.rb', line 21

def pretty_print
  puts "----------------------------------"
  puts "#{@name}"
  puts "----------------------------------"
  instances.each do |instance|
    puts instance.to_s
  end
  puts "\n"
end