Class: Gcloud::Dns::Importer

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

Overview

# DNS Importer

Reads a [DNS zone file](en.wikipedia.org/wiki/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 (String, IO)

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



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

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(only: nil, except: nil) ⇒ Array<Record>

Returns the Record instances created from the zone file.

Parameters:

  • only (String, Array<String>) (defaults to: nil)

    Include only records of this type or types.

  • except (String, Array<String>) (defaults to: nil)

    Exclude records of this type or types.

Returns:



67
68
69
70
71
72
# File 'lib/gcloud/dns/importer.rb', line 67

def records only: nil, except: nil
  ret = @records
  ret = ret.select { |r| Array(only).include? r.type } if only
  ret = ret.reject { |r| Array(except).include? r.type } if except
  ret
end