Class: Gcloud::Dns::Importer
- Inherits:
-
Object
- Object
- Gcloud::Dns::Importer
- 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
-
#initialize(zone, path_or_io) ⇒ Importer
constructor
Creates a new Importer that immediately parses the provided zone file data and creates Record instances.
-
#records(only: nil, except: nil) ⇒ Array<Record>
Returns the Record instances created from the zone file.
Constructor Details
#initialize(zone, path_or_io) ⇒ Importer
Creates a new Importer that immediately parses the provided zone file data and creates Record instances.
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.
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 |