Class: Cumulus::Route53::Manager

Inherits:
Common::Manager show all
Defined in:
lib/route53/manager/Manager.rb

Defined Under Namespace

Classes: AwsZone

Instance Method Summary collapse

Methods inherited from Common::Manager

#diff, #diff_one, #filter_local, #list, #sync, #sync_one

Constructor Details

#initializeManager

Returns a new instance of Manager.



14
15
16
17
18
# File 'lib/route53/manager/Manager.rb', line 14

def initialize
  super()
  @create_asset = false
  @route53 = Aws::Route53::Client.new(Configuration.instance.client)
end

Instance Method Details

#added_diff(local) ⇒ Object



58
59
60
# File 'lib/route53/manager/Manager.rb', line 58

def added_diff(local)
  ZoneDiff.added(local)
end

#aws_resourcesObject



50
51
52
# File 'lib/route53/manager/Manager.rb', line 50

def aws_resources
  @aws_resources ||= init_aws_resources
end

#diff_resource(local, aws) ⇒ Object



62
63
64
# File 'lib/route53/manager/Manager.rb', line 62

def diff_resource(local, aws)
  local.diff(aws)
end

#local_resourcesObject



46
47
48
# File 'lib/route53/manager/Manager.rb', line 46

def local_resources
  @local_resources ||= Hash[Loader.zones.map { |local| [local.id, local] }]
end

#migrateObject

Public: Migrate AWS Route53 configuration to Cumulus configuration.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/route53/manager/Manager.rb', line 21

def migrate
  zones_dir = "#{@migration_root}/zones"

  if !Dir.exists?(@migration_root)
    Dir.mkdir(@migration_root)
  end
  if !Dir.exists?(zones_dir)
    Dir.mkdir(zones_dir)
  end

  aws_resources.each_value do |resource|
    puts "Processing #{resource.name}..."
    config = ZoneConfig.new(resource.name)
    config.populate(resource)

    puts "Writing #{resource.name} configuration to file"
    filename = if config.private then "#{config.name}-private" else config.name end
    File.open("#{zones_dir}/#{filename.sub(".", "-")}.json", "w") { |f| f.write(config.pretty_json) }
  end
end

#resource_nameObject



42
43
44
# File 'lib/route53/manager/Manager.rb', line 42

def resource_name
  "Zone"
end

#unmanaged_diff(aws) ⇒ Object



54
55
56
# File 'lib/route53/manager/Manager.rb', line 54

def unmanaged_diff(aws)
  ZoneDiff.unmanaged(aws)
end

#update(local, diffs) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/route53/manager/Manager.rb', line 66

def update(local, diffs)
  diffs.each do |diff|
    case diff.type
    when ZoneChange::COMMENT
      puts Colors.blue("\tupdating comment...")
      update_comment(local.id, local.comment)
    when ZoneChange::DOMAIN
      puts "\tAWS doesn't allow you to change the domain for a zone."
    when ZoneChange::PRIVATE
      puts "\tAWS doesn't allow you to change whether a zone is private."
    when ZoneChange::VPC
      update_vpc(local.id, diff.added_vpc_ids, diff.removed_vpc_ids)
    when ZoneChange::RECORD
      update_records(
        local.id,
        diff.changed_records.reject do |r|
          r.type == RecordChange::IGNORED or r.type == RecordChange::DEFAULT
        end
      )

      ignored = diff.changed_records.select { |r| r.type == RecordChange::IGNORED }
      if Configuration.instance.route53.print_all_ignored
        ignored.each do |record_diff|
          puts "\tIgnoring record #{record_diff.aws_name}"
        end
      else
        if ignored.size > 0
          puts "\tYour blacklist ignored #{ignored.size} records."
        end
      end
    end
  end
end