Class: AwsAuditor::Scripts::Export

Inherits:
Object
  • Object
show all
Extended by:
AWSWrapper, GoogleWrapper
Defined in:
lib/aws_auditor/scripts/export.rb

Instance Attribute Summary

Attributes included from GoogleWrapper

#google

Attributes included from AWSWrapper

#aws

Class Method Summary collapse

Class Method Details

.cache_instancesObject



92
93
94
# File 'lib/aws_auditor/scripts/export.rb', line 92

def self.cache_instances
	@cache_instances ||= CacheInstance.get_instances
end

.execute(environment, options = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/aws_auditor/scripts/export.rb', line 9

def self.execute(environment, options = nil)
	aws(environment)
	file = GoogleSheet.new(Google.file[:name], Google.file[:path], environment)
	file.write_header(get_all_keys)
	write_opsworks_stacks(file)
	write_rds(file)
	write_cache(file)
	write_totals(file)
	`open #{file.sheet.human_url}`
end

.get_all_instance_countsObject



63
64
65
66
67
68
# File 'lib/aws_auditor/scripts/export.rb', line 63

def self.get_all_instance_counts
	ec2 = EC2Instance.instance_count_hash(EC2Instance.get_instances)
	rds = RDSInstance.instance_count_hash(RDSInstance.get_instances)
	cache = CacheInstance.instance_count_hash(CacheInstance.get_instances)
	ec2.merge(rds).merge(cache)
end

.get_all_keysObject



56
57
58
59
60
61
# File 'lib/aws_auditor/scripts/export.rb', line 56

def self.get_all_keys
	ec2 = EC2Instance.instance_hash.values.map{ |x| x.to_s }.uniq.sort! { |a,b| a.downcase <=> b.downcase }
	rds = RDSInstance.instance_hash.values.map{ |x| x.to_s }.uniq.sort! { |a,b| a.downcase <=> b.downcase }
	cache = CacheInstance.instance_hash.values.map{ |x| x.to_s }.uniq.sort! { |a,b| a.downcase <=> b.downcase }
	ec2.concat(rds).concat(cache).compact
end

.get_all_reserved_countsObject



70
71
72
73
74
75
# File 'lib/aws_auditor/scripts/export.rb', line 70

def self.get_all_reserved_counts
	ec2 = EC2Instance.instance_count_hash(EC2Instance.get_reserved_instances)
	rds = RDSInstance.instance_count_hash(RDSInstance.get_reserved_instances)
	cache = CacheInstance.instance_count_hash(CacheInstance.get_reserved_instances)
	ec2.merge(rds).merge(cache)
end

.get_difference_countsObject



77
78
79
80
81
82
# File 'lib/aws_auditor/scripts/export.rb', line 77

def self.get_difference_counts
	ec2 = EC2Instance.compare
	rds = RDSInstance.compare
	cache = CacheInstance.compare
	ec2.merge(rds).merge(cache)
end

.opsworks_stacksObject



84
85
86
# File 'lib/aws_auditor/scripts/export.rb', line 84

def self.opsworks_stacks
	@opsworks_stacks ||= Stack.all
end

.rds_instancesObject



88
89
90
# File 'lib/aws_auditor/scripts/export.rb', line 88

def self.rds_instances
	@rds_instances ||= RDSInstance.get_instances
end

.write_cache(file) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/aws_auditor/scripts/export.rb', line 38

def self.write_cache(file)
	file.write_row({name: "CACHE"})
	cache_instances.each do |cache|
		value_hash = Hash({:name => cache.name, :"#{cache.to_s}" => '1'})
	 	file.write_row(value_hash)
	end
end

.write_opsworks_stacks(file) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/aws_auditor/scripts/export.rb', line 20

def self.write_opsworks_stacks(file)
	file.write_row({name: "EC2"})
	opsworks_stacks.each do |stack|
		next if stack.instances.empty?
		value_hash = EC2Instance.instance_count_hash(stack.instances)
		value_hash[:name] = stack.name
		file.write_row(value_hash)
	end
end

.write_rds(file) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/aws_auditor/scripts/export.rb', line 30

def self.write_rds(file)
	file.write_row({name: "RDS"})
	rds_instances.each do |db|
		value_hash = Hash({:name => db.name, :"#{db.to_s}" => '1'})
		file.write_row(value_hash)
	end
end

.write_totals(file) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/aws_auditor/scripts/export.rb', line 46

def self.write_totals(file)
	file.write_row({name: "TOTALS"})
	instance_counts = get_all_instance_counts.merge({name: "Running Instances"})
	file.write_row(instance_counts)
	reserved_counts = get_all_reserved_counts.merge({name: "Reserved Instances"})
	file.write_row(reserved_counts)
	differences = get_difference_counts.merge({name: "Differences"})
	file.write_row(differences)
end