class AwsAuditor::Scripts::Inspect

Public Class Methods

execute(environment, options=nil) click to toggle source
# File lib/aws_auditor/scripts/inspect.rb, line 7
def self.execute(environment, options=nil)
  aws(environment)
  no_selection = options.values.uniq == [false]
  output("EC2Instance") if options[:ec2] || no_selection
  output("RDSInstance") if options[:rds] || no_selection 
  output("CacheInstance") if options[:cache] || no_selection
end
header(type, length = 50) click to toggle source
# File lib/aws_auditor/scripts/inspect.rb, line 25
def self.header(type, length = 50)
  type.upcase!.slice! "INSTANCE"
  half_length = (length - type.length)/2.0 - 1
  [
    "*" * length,
    "*" * half_length.floor + " #{type} " + "*" * half_length.ceil,
    "*" * length
  ].join("\n")
end
output(class_type) click to toggle source
# File lib/aws_auditor/scripts/inspect.rb, line 15
def self.output(class_type)
  klass = AwsAuditor.const_get(class_type)
  print "Gathering info, please wait..."; print "\r"
  instances = class_type == "EC2Instance" ? klass.bucketize : klass.instance_hash
  say "<%= color('#{header(class_type)}', :white) %>"
  instances.each do |key, value|
    pretty_print(key, klass.instance_count_hash(Array(value)))
  end
end
pretty_print(title, body) click to toggle source
# File lib/aws_auditor/scripts/inspect.rb, line 35
def self.pretty_print(title, body)
  puts "======================================="
  puts "#{title}"
  puts "======================================="
  body.each{ |key, value| say "<%= color('#{key}: #{value}', :white) %>" }
  puts "\n"
end