Class: AWSCarb::Services::Route53
- Inherits:
-
Object
- Object
- AWSCarb::Services::Route53
- Includes:
- Singleton
- Defined in:
- lib/aws-carb/services/route53.rb
Instance Method Summary collapse
- #check_hostname_and_domain_availability ⇒ Object
- #client(config) ⇒ Object
- #create_records(ec2) ⇒ Object
Instance Method Details
#check_hostname_and_domain_availability ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/aws-carb/services/route53.rb', line 25 def check_hostname_and_domain_availability ShellSpinner "# checking to see if hostname and domain have been configured", false do if @config[:route53].andand[:new_dns_records] else debug "# skipping route53 check since either hostname or domain wasn't found:" debug "hostname not found" if hostname.nil? debug "domain not found" if domain.nil? debug end end puts return unless @config[:route53].andand[:new_dns_records] ShellSpinner "# checking to see if record exists", false do begin record_sets = @client.hosted_zones[@config[:route53][:zone]].resource_record_sets @config[:route53][:new_dns_records].each_value do |record| die "error: record already exists: #{record[:alias]}" if record_sets[record[:alias], 'CNAME'].exists? end rescue => e puts "# could not check to see if DNS records exist:" die e end end puts end |
#client(config) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/aws-carb/services/route53.rb', line 10 def client(config) @config = config begin ShellSpinner "# configuring route53 session", false do @client = ::AWS::Route53.new(@config[:route53]) end puts rescue => e puts "error: failed to create route53 session" die e end end |
#create_records(ec2) ⇒ Object
59 60 61 62 63 64 65 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 |
# File 'lib/aws-carb/services/route53.rb', line 59 def create_records(ec2) if @config[:route53][:new_dns_records].nil? debug "# skipping creation of new records on route53" debug return end ShellSpinner "# updating route53 with new CNAMES for host", false do @config[:route53][:new_dns_records][:public][:target] = ec2.instance.public_dns_name @config[:route53][:new_dns_records][:private][:target] = ec2.instance.private_dns_name record_sets = @client.hosted_zones[@config[:route53][:zone]].resource_record_sets @config[:route53][:new_dns_records].each do |record_scope, record| new_record = record_sets[record[:alias], 'CNAME'] raise "error: '#{record_scope}' record already exists: #{record[:alias]}" if new_record.exists? # this could be blank if we're adding to a vpc and the instance has no external IP next if record[:target].nil? new_record = { :name => record[:alias], :type => 'CNAME', :options => { :ttl => @config[:route53][:ttl], :resource_records => [{ :value => record[:target] }] } } record_sets.create(new_record[:name], new_record[:type], new_record[:options]) end end puts end |