class Cumulus::Route53::Manager
Constants
- AwsZone
A struct that combines all the data about a hosted zone in AWS
Public Class Methods
new()
click to toggle source
Calls superclass method
Cumulus::Common::Manager::new
# File lib/route53/manager/Manager.rb, line 14 def initialize super() @create_asset = false @route53 = Aws::Route53::Client.new(Configuration.instance.client) end
Public Instance Methods
added_diff(local)
click to toggle source
# File lib/route53/manager/Manager.rb, line 58 def added_diff(local) ZoneDiff.added(local) end
aws_resources()
click to toggle source
# File lib/route53/manager/Manager.rb, line 50 def aws_resources @aws_resources ||= init_aws_resources end
diff_resource(local, aws)
click to toggle source
# File lib/route53/manager/Manager.rb, line 62 def diff_resource(local, aws) local.diff(aws) end
local_resources()
click to toggle source
# File lib/route53/manager/Manager.rb, line 46 def local_resources @local_resources ||= Hash[Loader.zones.map { |local| [local.id, local] }] end
migrate()
click to toggle source
Public: Migrate AWS Route53
configuration to Cumulus
configuration.
# 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_name()
click to toggle source
# File lib/route53/manager/Manager.rb, line 42 def resource_name "Zone" end
unmanaged_diff(aws)
click to toggle source
# File lib/route53/manager/Manager.rb, line 54 def unmanaged_diff(aws) ZoneDiff.unmanaged(aws) end
update(local, diffs)
click to toggle source
# 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
Private Instance Methods
update_comment(id, comment)
click to toggle source
Internal: Update the comment associated with a zone.
id - the id of the zone to update comment - the new comment
# File lib/route53/manager/Manager.rb, line 106 def update_comment(id, comment) @route53.update_hosted_zone_comment({ id: id, comment: comment }) end
update_records(id, records)
click to toggle source
Internal: Update the records associated with a zone.
id - the id of the zone to update records - RecordDiff
objects representing the changes
# File lib/route53/manager/Manager.rb, line 143 def update_records(id, records) puts Colors.blue("\tupdating records...") if !records.empty? changes = records.map do |record| action = nil resource = nil case record.type when RecordChange::CHANGED action = "UPSERT" resource = record.local when RecordChange::ADD action = "CREATE" resource = record.local when RecordChange::UNMANAGED action = "DELETE" resource = record.aws end { action: action, resource_record_set: { name: resource.name.gsub("@", "\\\\100"), type: resource.type, ttl: resource.ttl, resource_records: resource.resource_records, alias_target: if resource.alias_target.nil? then nil else { hosted_zone_id: resource.alias_target.hosted_zone_id, dns_name: resource.alias_target.dns_name, evaluate_target_health: resource.alias_target.evaluate_target_health } end } } end @route53.change_resource_record_sets({ hosted_zone_id: id, change_batch: { changes: changes } }) end end
update_vpc(id, associate, dissociate)
click to toggle source
Internal: Update the VPCs associated with a zone.
id - the id of the zone to update associate - the vpc ids to associate with the zone dissociate - the vpc ids to dissociate from the zone
# File lib/route53/manager/Manager.rb, line 118 def update_vpc(id, associate, dissociate) if !associate.empty? puts Colors.blue("\tassociating VPCs...") associate.each do |vpc| @route53.associate_vpc_with_hosted_zone({ hosted_zone_id: id, vpc: { vpc_id: vpc.id, vpc_region: vpc.region } }) end end if !dissociate.empty? puts Colors.blue("\tdissociating VPCs...") dissociate.each do |vpc| @route53.disassociate_vpc_from_hosted_zone({ hosted_zone_id: id, vpc: { vpc_id: vpc.id, vpc_region: vpc.region } }) end end end