Class: SportNginAwsAuditor::RDSInstance

Inherits:
Object
  • Object
show all
Extended by:
AWSWrapper, InstanceHelper, RDSWrapper
Defined in:
lib/sport_ngin_aws_auditor/rds_instance.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes included from RDSWrapper

#rds

Attributes included from AWSWrapper

#account_id, #aws

Class Method Summary collapse

Instance Method Summary collapse

Methods included from InstanceHelper

add_instances_with_tag_to_hash, compare, filter_instance_without_tags, filter_instances_with_tags, gather_instance_tag_date, instance_count_hash, instance_hash, reserved_instance_hash

Methods included from AWSWrapper

get_account_id

Constructor Details

#initialize(rds_instance, account_id = nil, tag_name = nil, rds = nil) ⇒ RDSInstance

Returns a new instance of RDSInstance.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 14

def initialize(rds_instance, =nil, tag_name=nil, rds=nil)
  if rds_instance.class.to_s == "Aws::RDS::Types::ReservedDBInstance"
    self.id = rds_instance.reserved_db_instances_offering_id
    self.multi_az = rds_instance.multi_az ? "Multi-AZ" : "Single-AZ"
    self.instance_type = rds_instance.db_instance_class
    self.engine = engine_helper(rds_instance.product_description)
    self.count = 1
  elsif rds_instance.class.to_s == "Aws::RDS::Types::DBInstance"
    self.id = rds_instance.db_instance_identifier
    self.multi_az = rds_instance.multi_az ? "Multi-AZ" : "Single-AZ"
    self.instance_type = rds_instance.db_instance_class
    self.engine = engine_helper(rds_instance.engine)
    self.count = 1

    if tag_name
      region = rds_instance.availability_zone.split(//).first(9).join
      region = "us-east-1" if region == "Multiple"
      arn = "arn:aws:rds:#{region}:#{}:db:#{self.id}"

       # go through to see if the tag we're looking for is one of them
      rds.list_tags_for_resource(resource_name: arn).tag_list.each do |tag|
        if tag.key == tag_name
          self.tag_value = tag.value
        end
      end
    end
  end
end

Class Attribute Details

.instancesObject

Returns the value of attribute instances.



10
11
12
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 10

def instances
  @instances
end

.reserved_instancesObject

Returns the value of attribute reserved_instances.



10
11
12
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 10

def reserved_instances
  @reserved_instances
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



13
14
15
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 13

def count
  @count
end

#engineObject

Returns the value of attribute engine.



13
14
15
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 13

def engine
  @engine
end

#idObject

Returns the value of attribute id.



13
14
15
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 13

def id
  @id
end

#instance_typeObject

Returns the value of attribute instance_type.



13
14
15
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 13

def instance_type
  @instance_type
end

#multi_azObject

Returns the value of attribute multi_az.



13
14
15
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 13

def multi_az
  @multi_az
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 13

def name
  @name
end

#tag_valueObject

Returns the value of attribute tag_value.



13
14
15
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 13

def tag_value
  @tag_value
end

Class Method Details

.get_instances(tag_name = nil) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 47

def self.get_instances(tag_name=nil)
  return @instances if @instances
   = 
  @instances = rds.describe_db_instances.db_instances.map do |instance|
    next unless instance.db_instance_status.to_s == 'available'
    new(instance, , tag_name, rds)
  end.compact
end

.get_reserved_instancesObject



56
57
58
59
60
61
62
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 56

def self.get_reserved_instances
  return @reserved_instances if @reserved_instances
  @reserved_instances = rds.describe_reserved_db_instances.reserved_db_instances.map do |instance|
    next unless instance.state.to_s == 'active'
    new(instance)
  end.compact
end

Instance Method Details

#no_reserved_instance_tag_valueObject



64
65
66
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 64

def no_reserved_instance_tag_value
  @tag_value
end

#to_sObject



43
44
45
# File 'lib/sport_ngin_aws_auditor/rds_instance.rb', line 43

def to_s
  "#{engine} #{multi_az} #{instance_type}"
end