Class: Bosh::Aws::Route53
- Inherits:
-
Object
- Object
- Bosh::Aws::Route53
- Defined in:
- lib/bosh_cli_plugin_aws/route53.rb
Instance Method Summary collapse
- #add_record(host, zone, addresses, options = {}) ⇒ Object
- #create_zone(zone) ⇒ Object
- #delete_all_records(options = {}) ⇒ Object
- #delete_record(host, zone, options = {}) ⇒ Object
- #delete_zone(zone) ⇒ Object
-
#initialize(credentials) ⇒ Route53
constructor
A new instance of Route53.
Constructor Details
#initialize(credentials) ⇒ Route53
Returns a new instance of Route53.
5 6 7 |
# File 'lib/bosh_cli_plugin_aws/route53.rb', line 5 def initialize(credentials) @aws_provider = AwsProvider.new(credentials) end |
Instance Method Details
#add_record(host, zone, addresses, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bosh_cli_plugin_aws/route53.rb', line 21 def add_record(host, zone, addresses, ={}) host = "\\052" if host == "*" zone = "#{zone}." unless zone =~ /\.$/ addresses = [addresses] unless addresses.kind_of?(Array) type = [:type] || "A" ttl = [:ttl] || 3600 aws_route53.client.change_resource_record_sets( hosted_zone_id: get_zone_id(zone), change_batch: { changes: [ { action: "CREATE", resource_record_set: { name: "#{host}.#{zone}", type: type, ttl: ttl, resource_records: addresses.map {|address| { value: address} } } } ] } ) true end |
#create_zone(zone) ⇒ Object
9 10 11 12 13 |
# File 'lib/bosh_cli_plugin_aws/route53.rb', line 9 def create_zone(zone) zone = "#{zone}." unless zone =~ /\.$/ aws_route53.client.create_hosted_zone(:name => zone, :caller_reference => generate_unique_name) true end |
#delete_all_records(options = {}) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/bosh_cli_plugin_aws/route53.rb', line 74 def delete_all_records( = {}) omit_types = [:omit_types] || [] aws_route53.hosted_zones.each do |zone| zone.rrsets.each do |rs| rs.delete unless omit_types.include?(rs.type) end end end |
#delete_record(host, zone, options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bosh_cli_plugin_aws/route53.rb', line 46 def delete_record(host, zone, ={}) host = "\\052" if host == "*" zone = "#{zone}." unless zone =~ /\.$/ record_name = "#{host}.#{zone}" record_type = [:type] || "A" zone_response = aws_route53.client.list_resource_record_sets(:hosted_zone_id => get_zone_id(zone)) resource_record_set = zone_response.data[:resource_record_sets].find do |rr| rr[:name] == record_name && rr[:type] == record_type end unless resource_record_set raise "no #{record_type} record found for #{record_name}" end aws_route53.client.change_resource_record_sets( hosted_zone_id: get_zone_id(zone), change_batch: { changes: [ { action: "DELETE", resource_record_set: resource_record_set } ] } ) true end |
#delete_zone(zone) ⇒ Object
15 16 17 18 19 |
# File 'lib/bosh_cli_plugin_aws/route53.rb', line 15 def delete_zone(zone) zone = "#{zone}." unless zone =~ /\.$/ aws_route53.client.delete_hosted_zone(:id => get_zone_id(zone)) true end |