Class: EC2Launcher::Route53
- Inherits:
-
Object
- Object
- EC2Launcher::Route53
- Defined in:
- lib/ec2launcher/route53.rb
Instance Method Summary collapse
-
#create_record(name, value, type = "A", ttl = 300) ⇒ Object
Creates a new DNS record in Route53.
-
#delete_record(name, type, ttl, value, log_errors = true) ⇒ Object
Deletes a DNS record from Route53.
-
#delete_record_by_name(hostname, record_type = "A", log_errors = true) ⇒ Object
Deletes a record by hostname, if it exists.
-
#find_record(name, type = 'A') ⇒ EC2Launcher::Route53Record
Searches for a record with the specified name and type.
-
#initialize(route53, hosted_zone_id, logger = nil) ⇒ Route53
constructor
A new instance of Route53.
Constructor Details
#initialize(route53, hosted_zone_id, logger = nil) ⇒ Route53
Returns a new instance of Route53.
25 26 27 28 29 30 |
# File 'lib/ec2launcher/route53.rb', line 25 def initialize(route53, hosted_zone_id, logger = nil) @log = logger @route53 = route53 @hosted_zone_id = hosted_zone_id end |
Instance Method Details
#create_record(name, value, type = "A", ttl = 300) ⇒ Object
Creates a new DNS record in Route53. Deletes any existing record with the same name and record type.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ec2launcher/route53.rb', line 39 def create_record(name, value, type = "A", ttl = 300) # Delete existing record because you can't update records delete_record_by_name(name, type, false) # Create new record begin @route53.client.change_resource_record_sets({ :hosted_zone_id => @hosted_zone_id, :change_batch => { :changes => [ { :action => "CREATE", :resource_record_set => { :name => name, :type => type, :ttl => ttl, :resource_records => [ { :value => value } ] } } ] } }) rescue StandardError => bang @log.error "Error creating A record from Route53: #{bang}" end end |
#delete_record(name, type, ttl, value, log_errors = true) ⇒ Object
Deletes a DNS record from Route53.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ec2launcher/route53.rb', line 90 def delete_record(name, type, ttl, value, log_errors = true) begin @route53.client.change_resource_record_sets({ :hosted_zone_id => @hosted_zone_id, :change_batch => { :changes => [ { :action => "DELETE", :resource_record_set => { :name => name, :type => type, :ttl => ttl, :resource_records => [ { :value => value } ] } } ] } }) rescue StandardError => bang @log.error "Error deleting A record from Route53: #{bang}" if log_errors end end |
#delete_record_by_name(hostname, record_type = "A", log_errors = true) ⇒ Object
Deletes a record by hostname, if it exists.
72 73 74 75 76 77 78 79 80 |
# File 'lib/ec2launcher/route53.rb', line 72 def delete_record_by_name(hostname, record_type = "A", log_errors = true) # Search for the record record = find_record(hostname, record_type) if record delete_record(record.name, record.type, record.ttl, record.value, log_errors) else @log.warn "Route53 '#{record_type}' record for '#{hostname}' not found!" if log_errors end end |
#find_record(name, type = 'A') ⇒ EC2Launcher::Route53Record
Searches for a record with the specified name and type.
required information about a Route53 entry or nil if not found.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/ec2launcher/route53.rb', line 120 def find_record(name, type = 'A') # Find the record response = @route53.client.list_resource_record_sets({ :hosted_zone_id => @hosted_zone_id, :start_record_name => name, :start_record_type => type, :max_items => 1 }) record = nil if response && response.data if response.data[:resource_record_sets] && response.data[:resource_record_sets].size > 0 response_record = response.data[:resource_record_sets][0] if (response_record[:name] == name || response_record[:name] == "#{name}.") && response_record[:type] == type record = Route53Record.new(response_record[:name], response_record[:type], response_record[:ttl], response_record[:resource_records][0][:value]) end end end record end |