Class: Sunzi::DNS::Route53

Inherits:
Base
  • Object
show all
Defined in:
lib/sunzi/dns/route53.rb

Instance Method Summary collapse

Methods included from Utility

#abort_with, #exit_with, #say

Constructor Details

#initialize(config, cloud) ⇒ Route53

Returns a new instance of Route53.



6
7
8
9
10
11
# File 'lib/sunzi/dns/route53.rb', line 6

def initialize(config, cloud)
  @api = ::Route53::Connection.new(config['route53']['key'], config['route53']['secret'])
  zone = config['fqdn']['zone']
  @route53_zone = @api.get_zones.find{|i| i.name.sub(/\.$/,'') == zone }
  abort_with "zone for #{zone} was not found on Route 53!" unless @route53_zone
end

Instance Method Details

#add(fqdn, ip) ⇒ Object



13
14
15
16
# File 'lib/sunzi/dns/route53.rb', line 13

def add(fqdn, ip)
  say 'adding the public IP to Route 53...'
  ::Route53::DNSRecord.new(fqdn, "A", "300", [ip], @route53_zone).create
end

#delete(ip) ⇒ Object



18
19
20
21
22
# File 'lib/sunzi/dns/route53.rb', line 18

def delete(ip)
  say 'deleting the public IP from Route 53...'
  record = @route53_zone.get_records.find{|i| i.values.first == ip }
  record.delete if record
end