Class: BuildCloud::R53RecordSet

Inherits:
Object
  • Object
show all
Includes:
Component
Defined in:
lib/build-cloud/r53recordset.rb

Constant Summary collapse

@@objects =
[]

Instance Method Summary collapse

Methods included from Component

included

Constructor Details

#initialize(fog_interfaces, log, options = {}) ⇒ R53RecordSet

Returns a new instance of R53RecordSet.



7
8
9
10
11
12
13
14
15
16
17
# 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

Instance Method Details

#createObject



19
20
21
22
23
24
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
58
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
# 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

#deleteObject



95
96
97
98
99
100
101
102
103
104
105
# 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

#readObject Also known as: fog_object



87
88
89
90
91
# File 'lib/build-cloud/r53recordset.rb', line 87

def read
    if zone
       zone.records.get @options[:name]
    end
end

#wait_until_readyObject



107
108
109
# File 'lib/build-cloud/r53recordset.rb', line 107

def wait_until_ready
    @log.debug("Can't wait on r53 record set creation")
end