class AwsAuditor::Stack

Attributes

instances[RW]
stacks[RW]
id[RW]
instances[RW]
name[RW]

Public Class Methods

all() click to toggle source
# File lib/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() click to toggle source
# File lib/aws_auditor/stack.rb, line 49
def self.all_instances
  @all_instances ||= EC2Instance.instance_hash
end
instances_without_stack() click to toggle source
# File lib/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
new(aws_stack) click to toggle source
# File lib/aws_auditor/stack.rb, line 13
def initialize(aws_stack)
  @id = aws_stack[:stack_id]
  @name = aws_stack[:name]
  @instances = get_instances.compact
end

Public Instance Methods

get_instances() click to toggle source
# File lib/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() click to toggle source
# File lib/aws_auditor/stack.rb, line 34
def pretty_print
  puts "----------------------------------"
  puts "#{@name}"
  puts "----------------------------------"
  print_instances
  puts "\n"
end
print_instances() click to toggle source