Class: AwsAuditor::Scripts::Audit

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

Instance Attribute Summary

Attributes included from AWSWrapper

#aws

Attributes included from EC2Wrapper

#ec2

Class Method Summary collapse

Class Method Details

.compareObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/aws_auditor/scripts/audit.rb', line 23

def self.compare
  differences = Hash.new()
  instances = create_instance_hash(Instance.get_instances)
  ris = create_instance_hash(Instance.get_reserved_instances)
  instances.keys.concat(ris.keys).uniq.each do |key|
    instance_count = instances.has_key?(key) ? instances[key] : 0
    ris_count = ris.has_key?(key) ? ris[key] : 0
    differences[key] = ris_count - instance_count
  end
  differences
end

.create_instance_hash(instance_type) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/aws_auditor/scripts/audit.rb', line 14

def self.create_instance_hash(instance_type)
  instance_hash = Hash.new()
  instance_type.each do |instance|
    next if instance.nil?
    instance_hash[instance.to_s] = instance_hash.has_key?(instance.to_s) ? instance_hash[instance.to_s] + instance.count : instance.count
  end
  instance_hash
end

.execute(environment) ⇒ Object



7
8
9
10
11
12
# File 'lib/aws_auditor/scripts/audit.rb', line 7

def self.execute(environment)
  aws(environment)
  compare.each do |key,value|
    puts "#{key}: #{value}"
  end
end