Class: SportNginAwsAuditor::Scripts::Inspect

Inherits:
Object
  • Object
show all
Extended by:
AWSWrapper, OpsWorksWrapper
Defined in:
lib/sport_ngin_aws_auditor/scripts/inspect.rb

Instance Attribute Summary

Attributes included from AWSWrapper

#account_id, #aws

Attributes included from OpsWorksWrapper

#opsworks

Class Method Summary collapse

Methods included from AWSWrapper

get_account_id

Class Method Details

.execute(environment, options = nil, global_options = nil) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/sport_ngin_aws_auditor/scripts/inspect.rb', line 7

def self.execute(environment, options=nil, global_options=nil)
  aws(environment, global_options[:aws_roles])
  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) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/sport_ngin_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) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/sport_ngin_aws_auditor/scripts/inspect.rb', line 15

def self.output(class_type)
  klass = SportNginAwsAuditor.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) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/sport_ngin_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