Class: AwsAuditor::EC2Instance

Inherits:
Object
  • Object
show all
Extended by:
EC2Wrapper, InstanceHelper
Defined in:
lib/aws_auditor/ec2_instance.rb

Instance Attribute Summary collapse

Attributes included from EC2Wrapper

#ec2

Class Method Summary collapse

Instance Method Summary collapse

Methods included from InstanceHelper

compare, instance_count_hash, instance_hash

Constructor Details

#initialize(ec2_instance, count = 1) ⇒ EC2Instance

Returns a new instance of EC2Instance.



9
10
11
12
13
14
15
# File 'lib/aws_auditor/ec2_instance.rb', line 9

def initialize(ec2_instance, count=1)
  @id = ec2_instance.id
  @platform = platform_helper(ec2_instance)
  @availability_zone = ec2_instance.availability_zone
  @instance_type = ec2_instance.instance_type
  @count = count
end

Instance Attribute Details

#availability_zoneObject

Returns the value of attribute availability_zone.



8
9
10
# File 'lib/aws_auditor/ec2_instance.rb', line 8

def availability_zone
  @availability_zone
end

#countObject

Returns the value of attribute count.



8
9
10
# File 'lib/aws_auditor/ec2_instance.rb', line 8

def count
  @count
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/aws_auditor/ec2_instance.rb', line 8

def id
  @id
end

#instance_typeObject

Returns the value of attribute instance_type.



8
9
10
# File 'lib/aws_auditor/ec2_instance.rb', line 8

def instance_type
  @instance_type
end

#platformObject

Returns the value of attribute platform.



8
9
10
# File 'lib/aws_auditor/ec2_instance.rb', line 8

def platform
  @platform
end

Class Method Details

.get_instancesObject



45
46
47
48
49
50
51
# File 'lib/aws_auditor/ec2_instance.rb', line 45

def self.get_instances
  instances = ec2.instances
  instances.map do |instance|
    next unless instance.status.to_s == 'running'
    new(instance)
  end if instances
end

.get_reserved_instancesObject



53
54
55
56
57
58
59
# File 'lib/aws_auditor/ec2_instance.rb', line 53

def self.get_reserved_instances
  reserved_instances = ec2.reserved_instances
  reserved_instances.map do |ri|
    next unless ri.state == 'active'
    new(ri, ri.instance_count)
  end if reserved_instances
end

Instance Method Details

#platform_helper(ec2_instance) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aws_auditor/ec2_instance.rb', line 21

def platform_helper(ec2_instance)
  if ec2_instance.class.to_s == 'AWS::EC2::Instance'
    if ec2_instance.vpc? 
      return 'VPC'
    elsif ec2_instance.platform
      if ec2_instance.platform.downcase.include? 'windows' 
        return 'Windows'
      else
        return 'Linux'
      end
    else
      return 'Linux'
    end
  elsif ec2_instance.class.to_s == 'AWS::EC2::ReservedInstances'
    if ec2_instance.product_description.downcase.include? 'vpc' 
      return 'VPC'
    elsif ec2_instance.product_description.downcase.include? 'windows'
      return 'Windows'
    else
      return 'Linux'
    end
  end
end

#to_sObject



17
18
19
# File 'lib/aws_auditor/ec2_instance.rb', line 17

def to_s
  "#{@platform} #{@availability_zone} #{@instance_type}"
end