Class: SportNginAwsAuditor::CacheInstance

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes included from CacheWrapper

#cache

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(cache_instance, account_id = nil, tag_name = nil, cache = nil) ⇒ CacheInstance

Returns a new instance of CacheInstance.



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/cache_instance.rb', line 14

def initialize(cache_instance, =nil, tag_name=nil, cache=nil)
  if cache_instance.class.to_s == "Aws::ElastiCache::Types::ReservedCacheNode"
    self.id = cache_instance.reserved_cache_node_id
    self.name = cache_instance.reserved_cache_node_id
    self.instance_type = cache_instance.cache_node_type
    self.engine = cache_instance.product_description
    self.count = cache_instance.cache_node_count
  elsif cache_instance.class.to_s == "Aws::ElastiCache::Types::CacheCluster"
    self.id = cache_instance.cache_cluster_id
    self.name = cache_instance.cache_cluster_id
    self.instance_type = cache_instance.cache_node_type
    self.engine = cache_instance.engine
    self.count = cache_instance.num_cache_nodes

    if tag_name
      region = cache_instance.preferred_availability_zone.split(//).first(9).join
      region = "us-east-1" if region == "Multiple"
      arn = "arn:aws:elasticache:#{region}:#{}:cluster:#{self.id}"

       # go through to see if the tag we're looking for is one of them
      cache.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/cache_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/cache_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/cache_instance.rb', line 13

def count
  @count
end

#engineObject

Returns the value of attribute engine.



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

def engine
  @engine
end

#idObject

Returns the value of attribute id.



13
14
15
# File 'lib/sport_ngin_aws_auditor/cache_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/cache_instance.rb', line 13

def instance_type
  @instance_type
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/sport_ngin_aws_auditor/cache_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/cache_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/cache_instance.rb', line 47

def self.get_instances(tag_name=nil)
  return @instances if @instances
   = 
  @instances = cache.describe_cache_clusters.cache_clusters.map do |instance|
    next unless instance.cache_cluster_status.to_s == 'available'
    new(instance, , tag_name, cache)
  end.compact
end

.get_reserved_instancesObject



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

def self.get_reserved_instances
  return @reserved_instances if @reserved_instances
  @reserved_instances = cache.describe_reserved_cache_nodes.reserved_cache_nodes.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/cache_instance.rb', line 64

def no_reserved_instance_tag_value
  @tag_value
end

#to_sObject



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

def to_s
  "#{engine.capitalize} #{instance_type}"
end