Class: Interferon::HostSources::AwsElasticache

Inherits:
Object
  • Object
show all
Defined in:
lib/interferon/host_sources/aws_elasticache.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AwsElasticache

Returns a new instance of AwsElasticache.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/interferon/host_sources/aws_elasticache.rb', line 5

def initialize(options)
  missing = %w(access_key_id secret_access_key).reject { |r| options.key?(r) }

  AWS.config(access_key_id: options['access_key_id'],
             secret_access_key: options['secret_access_key']) if missing.empty?

  # initialize a list of regions to check
  @regions = if options['regions'] && !options['regions'].empty?
               options['regions']
             else
               AWS.regions.map(&:name)
             end
end

Instance Method Details

#list_hostsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/interferon/host_sources/aws_elasticache.rb', line 19

def list_hosts
  hosts = []

  @regions.each do |region|
    clusters = []
    client = AWS::ElastiCache.new(region: region).client

    AWS.memoize do
      # read the list of cache clusters; we have to do our own pagination
      clusters = []
      options = { show_cache_node_info: true }
      loop do
        r = client.describe_cache_clusters(options)
        clusters += r.data[:cache_clusters]

        break unless r.data[:marker]
        options[:marker] = r.data[:marker]
      end

      # iterate over the nodes in each cluster and add each one to hosts
      clusters.each do |cluster|
        cluster[:cache_nodes].each do |node|
          hosts << {
            source: 'aws_elasticache',
            region: region,

            cluster_id: cluster[:cache_cluster_id],
            cluster_status: cluster[:cache_cluster_status],
            node_type: cluster[:cache_node_type],
            peer_nodes: cluster[:num_cache_nodes],

            node_status: node[:cache_node_status],

            # elasticache does not support tagging
            owners: [],
            owner_groups: [],
          }
        end
      end
    end
  end

  hosts
end