Class: Mappru::Exporter

Inherits:
Object
  • Object
show all
Includes:
Logger::Helper, Utils::Helper
Defined in:
lib/mappru/exporter.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Helper

#diff, #matched?

Methods included from Logger::Helper

#log

Constructor Details

#initialize(client, options = {}) ⇒ Exporter

Returns a new instance of Exporter.



9
10
11
12
13
# File 'lib/mappru/exporter.rb', line 9

def initialize(client, options = {})
  @client = client
  @resource = Aws::EC2::Resource.new(client: @client)
  @options = options
end

Class Method Details

.export(client, options = {}) ⇒ Object



5
6
7
# File 'lib/mappru/exporter.rb', line 5

def self.export(client, options = {})
  self.new(client, options).export
end

Instance Method Details

#exportObject



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
42
43
44
45
# File 'lib/mappru/exporter.rb', line 15

def export
  result = {}
  @resource

  route_tables = @resource.route_tables

  route_tables.each do |rt|
    vpc_id = rt.vpc_id
    name_tag = rt.tags.find {|i| i.key == 'Name' } || {}
    name = name_tag[:value]

    next unless matched?(vpc_id, @options[:vpc_id])

    unless name
      log(:warn, "Cannot manage the nameless Route Table: #{vpc_id}", color: :yellow)
      next
    end

    next unless matched?(name, @options[:rt_name])

    result[vpc_id] ||= {}

    if result[vpc_id][name]
      raise "Duplication Subnet found: #{vpc_id}: #{name}"
    end

    result[vpc_id][name] = export_route_table(rt)
  end

  result
end