Class: BuildCloud::Zone
- Inherits:
-
Object
- Object
- BuildCloud::Zone
- Includes:
- Component
- Defined in:
- lib/build-cloud/zone.rb
Constant Summary collapse
- @@objects =
[]
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
-
#initialize(fog_interfaces, log, options = {}) ⇒ Zone
constructor
A new instance of Zone.
- #read ⇒ Object (also: #fog_object)
Methods included from Component
Constructor Details
#initialize(fog_interfaces, log, options = {}) ⇒ Zone
Returns a new instance of Zone.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/build-cloud/zone.rb', line 7 def initialize ( fog_interfaces, log, = {} ) @r53 = fog_interfaces[:r53] @log = log @options = @log.debug( .inspect ) (:domain) end |
Instance Method Details
#create ⇒ Object
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 |
# File 'lib/build-cloud/zone.rb', line 19 def create return if exists? @log.info( "Creating zone for #{@options[:domain]}" ) = @options.dup zone = @r53.zones.new( ) zone.save if .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 == [: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] = [:ttl] rr = [ soa.join(' ') ] end changes << { :action => 'CREATE', :name => set['Name'], :type => set['Type'], :ttl => [:ttl], :resource_records => rr, } end @r53.change_resource_record_sets( zone.id, changes ) end @log.debug( zone.inspect ) end |
#delete ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/build-cloud/zone.rb', line 85 def delete return unless exists? @log.info( "Deleting zone for #{@options[:domain]}" ) fog_object.destroy end |
#read ⇒ Object Also known as: fog_object
79 80 81 |
# File 'lib/build-cloud/zone.rb', line 79 def read @r53.zones.select { |z| z.domain == @options[:domain] }.first end |