Class: Route53::DNSRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/route53.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, ttl, values, zone, zone_apex = nil, weight = nil, ident = nil) ⇒ DNSRecord

Returns a new instance of DNSRecord.



318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/route53.rb', line 318

def initialize(name,type,ttl,values,zone,zone_apex=nil,weight=nil,ident=nil)
  @name = name
  unless @name.end_with?(".")
    @name += "."
  end
  @type = type.upcase
  @ttl = ttl
  @values = values
  @zone = zone
  @zone_apex = zone_apex
  @weight = weight
  @ident = ident
end

Instance Attribute Details

#identObject (readonly)

Returns the value of attribute ident.



315
316
317
# File 'lib/route53.rb', line 315

def ident
  @ident
end

#nameObject (readonly)

Returns the value of attribute name.



310
311
312
# File 'lib/route53.rb', line 310

def name
  @name
end

#ttlObject (readonly)

Returns the value of attribute ttl.



312
313
314
# File 'lib/route53.rb', line 312

def ttl
  @ttl
end

#typeObject (readonly)

Returns the value of attribute type.



311
312
313
# File 'lib/route53.rb', line 311

def type
  @type
end

#valuesObject (readonly)

Returns the value of attribute values.



313
314
315
# File 'lib/route53.rb', line 313

def values
  @values
end

#weightObject (readonly)

Returns the value of attribute weight.



314
315
316
# File 'lib/route53.rb', line 314

def weight
  @weight
end

#zone_apexObject (readonly)

Returns the value of attribute zone_apex.



316
317
318
# File 'lib/route53.rb', line 316

def zone_apex
  @zone_apex
end

Instance Method Details

#create(comment = nil) ⇒ Object



363
364
365
# File 'lib/route53.rb', line 363

def create(comment=nil)
  @zone.perform_actions([{:action => "CREATE", :record => self}],comment)
end

#delete(comment = nil) ⇒ Object



359
360
361
# File 'lib/route53.rb', line 359

def delete(comment=nil)
  @zone.perform_actions([{:action => "DELETE", :record => self}],comment)
end

#gen_change_xml(xml, action) ⇒ Object



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/route53.rb', line 332

def gen_change_xml(xml,action)
  xml.Change { |change|
    change.Action(action.upcase)
    change.ResourceRecordSet { |record|
      record.Name(@name)
      record.Type(@type)
      record.SetIdentifier(@ident) if @ident
      record.Weight(@weight) if @weight
      record.TTL(@ttl) unless @zone_apex
      if @zone_apex
        record.AliasTarget { |targets|
          targets.HostedZoneId(@zone_apex)
          targets.DNSName(@values.first)
        }
      else
        record.ResourceRecords { |resources|
          @values.each { |val|
            resources.ResourceRecord { |record|
              record.Value(val)
            }
          }
        }
      end
    }
  }
end

#to_sObject



394
395
396
397
398
399
400
401
402
# File 'lib/route53.rb', line 394

def to_s
  if @weight
    "#{@name} #{@type} #{@ttl} '#{@ident}' #{@weight} #{@values.join(",")}"
  elsif @zone_apex
    "#{@name} #{@type} #{@zone_apex} #{@values.join(",")}"
  else
    "#{@name} #{@type} #{@ttl} #{@values.join(",")}"
  end
end

#update(name, type, ttl, values, comment = nil, zone_apex = nil) ⇒ Object

Need to modify to a param hash



368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/route53.rb', line 368

def update(name,type,ttl,values,comment=nil, zone_apex = nil)
  prev = self.clone
  @name = name unless name.nil?
  @type = type unless type.nil?
  @ttl = ttl unless ttl.nil?
  @values = values unless values.nil?
  @zone_apex = zone_apex unless zone_apex.nil?
  @zone.perform_actions([
      {:action => "DELETE", :record => prev},
      {:action => "CREATE", :record => self},
      ],comment)
end

#update_dirty(name, type, ttl, values, zone_apex = nil) ⇒ Object

Returns the raw array so the developer can update large batches manually Need to modify to a param hash



383
384
385
386
387
388
389
390
391
392
# File 'lib/route53.rb', line 383

def update_dirty(name,type,ttl,values,zone_apex = nil)
  prev = self.clone
  @name = name unless name.nil?
  @type = type unless type.nil?
  @ttl = ttl unless ttl.nil?
  @values = values unless values.nil?
  @zone_apex = zone_apex unless zone_apex.nil?
  return [{:action => "DELETE", :record => prev},
  {:action => "CREATE", :record => self}]
end