class BuildCloud::R53RecordSet

Public Class Methods

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

    @log     = log
    @options = options

    @log.debug( options.inspect )

    required_options(:name, :type, :zone)

    @zone_name = options.delete(:zone)
end

Public Instance Methods

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

    @log.info( "Creating record set #{@options[:name]}" )

    options = @options.dup

    if options.has_key?(:alias_target)

        unless options[:alias_target][:dns_name] and options[:alias_target][:hosted_zone_id]

            elb_name = options[:alias_target].delete(:elb)
            elb = BuildCloud::LoadBalancer.search( :id => elb_name ).first

            unless elb
                raise "Can't find ELB object for #{elb_name}"
            end

            options[:alias_target][:dns_name]       = elb.read.dns_name
            options[:alias_target][:hosted_zone_id] = elb.read.hosted_zone_name_id
            
        end

    end

    if network_interface_public_ip = options.delete(:network_interface_public_ip)

        network_interface = BuildCloud::NetworkInterface.search( :name => network_interface_public_ip ).first

        unless network_interface
            raise "Can't find Network Interface ID #{network_interface_id} for Instance #{instance_public_ip}"
        end

        options[:value] = network_interface.read.association['publicIp']

    end

    if rds_server = options.delete(:rds_server)

        rds = BuildCloud::RDSServer.search( :id => rds_server ).first

        unless rds 
            raise "Can't find RDS Server for #{rds_server}"
        end

        options[:value] = [ rds.read.endpoint["Address"] ]
    end

    if cache_cluster = options.delete(:cache_cluster)

        cache = BuildCloud::CacheCluster.search( :id => cache_cluster ).first

        unless cache
            raise "Can't find cache cluster for #{cache_cluster}"
        end

        options[:value] = [ cache.read.nodes.first["Address"] ]

    end


    record = zone.records.create( options )

    @log.debug(record.inspect)

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

    return unless exists?

    @log.info( "Deleting record #{@options[:name]}" )

    # Fog errors unless ttl is set:
    fog_object.ttl = 1
    fog_object.destroy

end
fog_object()
Alias for: read
read() click to toggle source
# File lib/build-cloud/r53recordset.rb, line 87
def read
    if zone
       zone.records.get @options[:name]
    end
end
Also aliased as: fog_object
wait_until_ready() click to toggle source
# File lib/build-cloud/r53recordset.rb, line 107
def wait_until_ready
    @log.debug("Can't wait on r53 record set creation")
end

Private Instance Methods

zone() click to toggle source
# File lib/build-cloud/r53recordset.rb, line 113
def zone

    BuildCloud::Zone.search( :domain => @zone_name ).first.fog_object

end