Class: Gcloud::Dns::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/dns/importer.rb

Overview

DNS Importer

Reads a DNS zone file and parses it, creating a collection of Record instances. The returned records are unsaved, as they are not yet associated with a Zone. Use Zone#import to add zone file records to a Zone.

Because the Google Cloud DNS API only accepts a single resource record for each name and type combination (with multiple data elements), the zone file’s records are merged as necessary. During this merge, the lowest ttl of the merged records is used. If none of the merged records have a ttl value, the zone file’s global TTL is used for the record.

The following record types are supported: A, AAAA, CNAME, MX, NAPTR, NS, PTR, SOA, SPF, SRV, and TXT.

Instance Method Summary collapse

Constructor Details

#initialize(zone, path_or_io) ⇒ Importer

Creates a new Importer that immediately parses the provided zone file data and creates Record instances.

Parameters

path_or_io

The path to a zone file on the filesystem, or an IO instance from which zone file data can be read. (String or IO)



49
50
51
52
53
54
55
56
57
# File 'lib/gcloud/dns/importer.rb', line 49

def initialize zone, path_or_io
  @zone = zone
  @merged_zf_records = {}
  @records = []
  @zonefile = create_zonefile path_or_io
  merge_zonefile_records
  from_zonefile_records
  @records.unshift soa_record
end

Instance Method Details

#records(options = {}) ⇒ Object

Returns the Record instances created from the zone file.

Parameters

options

An optional Hash for controlling additional behavior. (Hash)

options[:only]

Include only records of this type or types. (String or Array)

options[:except]

Exclude records of this type or types. (String or Array)

Returns

An array of unsaved Record instances.



75
76
77
# File 'lib/gcloud/dns/importer.rb', line 75

def records options = {}
  filtered_records options[:only], options[:except]
end