class BuildCloud::Zone

Public Class Methods

new( fog_interfaces, log, options = {} ) click to toggle source
# File lib/build-cloud/zone.rb, line 7
def initialize ( fog_interfaces, log, options = {} )

    @r53     = fog_interfaces[:r53]
    @log     = log
    @options = options

    @log.debug( options.inspect )

    required_options(:domain)

end

Public Instance Methods

create() click to toggle source
# File lib/build-cloud/zone.rb, line 19
def create
    
    return if exists?

    @log.info( "Creating zone for #{@options[:domain]}" )

    options = @options.dup

    zone = @r53.zones.new( options )
    zone.save

    if options.has_key?(:ttl)

        # Change TTL of default RR sets if required:

        record_sets = @r53.list_resource_record_sets( zone.id ).data[:body]['ResourceRecordSets']
        changes = []

        record_sets.each do |set|

            next if set['TTL'].to_i == options[:ttl].to_i

            rr = set['ResourceRecords']

            changes << {
                :action           => 'DELETE',
                :name             => set['Name'],
                :type             => set['Type'],
                :ttl              => set['TTL'],
                :resource_records => rr,
            }

            if( set['Type'] == 'SOA' )

                # Set min TTL in SOA too

                soa = rr.first.split(/\s+/)
                soa[6] = options[:ttl]
                rr = [ soa.join(' ') ]

            end

            changes << {
                :action           => 'CREATE',
                :name             => set['Name'],
                :type             => set['Type'],
                :ttl              => options[:ttl],
                :resource_records => rr,
            }

        end

        @r53.change_resource_record_sets( zone.id, changes )

    end

    @log.debug( zone.inspect )

end
delete() click to toggle source
# File lib/build-cloud/zone.rb, line 85
def delete

    return unless exists?

    @log.info( "Deleting zone for #{@options[:domain]}" )

    fog_object.destroy

end
fog_object()
Alias for: read
read() click to toggle source
# File lib/build-cloud/zone.rb, line 79
def read
    @r53.zones.select { |z| z.domain == @options[:domain] }.first
end
Also aliased as: fog_object