Class: Google::Cloud::Dns::Zone::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/dns/zone/transaction.rb

Overview

DNS Zone Transaction

This object is used by #update when passed a block. These methods are used to update the records that are sent to the Google Cloud DNS API.

Examples:

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.update do |tx|
  tx.add     "example.com.", "A",  86400, "1.2.3.4"
  tx.remove  "example.com.", "TXT"
  tx.replace "example.com.", "MX", 86400, ["10 mail1.example.com.",
                                           "20 mail2.example.com."]
  tx.modify "www.example.com.", "CNAME" do |cname|
    cname.ttl = 86400 # only change the TTL
  end
end

Instance Method Summary collapse

Instance Method Details

#add(name, type, ttl, data) ⇒ Object

Adds a record to the Zone.

Examples:

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.update do |tx|
  tx.add     "example.com.", "A",  86400, "1.2.3.4"
end

Parameters:

  • name (String)

    The owner of the record. For example: example.com..

  • type (String)

    The identifier of a supported record type. For example: A, AAAA, CNAME, MX, or TXT.

  • ttl (Integer)

    The number of seconds that the record can be cached by resolvers.

  • data (String, Array<String>)

    The resource record data, as determined by type and defined in RFC 1035 (section 5) and RFC 1034 (section 3.6.1). For example: 192.0.2.1 or example.com..



80
81
82
# File 'lib/google/cloud/dns/zone/transaction.rb', line 80

def add name, type, ttl, data
  @additions += Array(@zone.record(name, type, ttl, data))
end

#modify(name, type) {|record| ... } ⇒ Object

Modifies records on the Zone. Records matching the name and type are yielded to the block where they can be modified.

Examples:

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.update do |tx|
  tx.modify "www.example.com.", "CNAME" do |cname|
    cname.ttl = 86400 # only change the TTL
  end
end

Parameters:

  • name (String)

    The owner of the record. For example: example.com..

  • type (String)

    The identifier of a supported record type. For example: A, AAAA, CNAME, MX, or TXT.

Yields:

  • (record)

    a block yielding each matching record

Yield Parameters:

  • record (Record)

    the record to be modified



165
166
167
168
169
170
171
# File 'lib/google/cloud/dns/zone/transaction.rb', line 165

def modify name, type
  existing = @zone.records(name, type).all.to_a
  updated = existing.map(&:dup)
  updated.each { |r| yield r }
  @additions += updated
  @deletions += existing
end

#remove(name, type) ⇒ Object

Removes records from the Zone. The records are looked up before they are removed.

Examples:

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.update do |tx|
  tx.remove  "example.com.", "TXT"
end

Parameters:

  • name (String)

    The owner of the record. For example: example.com..

  • type (String)

    The identifier of a supported record type. For example: A, AAAA, CNAME, MX, or TXT.



103
104
105
# File 'lib/google/cloud/dns/zone/transaction.rb', line 103

def remove name, type
  @deletions += @zone.records(name, type).all.to_a
end

#replace(name, type, ttl, data) ⇒ Object

Replaces existing records on the Zone. Records matching the name and type are replaced.

Examples:

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.update do |tx|
  tx.replace "example.com.",
             "MX", 86400,
             ["10 mail1.example.com.",
              "20 mail2.example.com."]
end

Parameters:

  • name (String)

    The owner of the record. For example: example.com..

  • type (String)

    The identifier of a supported record type. For example: A, AAAA, CNAME, MX, or TXT.

  • ttl (Integer)

    The number of seconds that the record can be cached by resolvers.

  • data (String, Array<String>)

    The resource record data, as determined by type and defined in RFC 1035 (section 5) and RFC 1034 (section 3.6.1). For example: 192.0.2.1 or example.com..



137
138
139
140
# File 'lib/google/cloud/dns/zone/transaction.rb', line 137

def replace name, type, ttl, data
  remove name, type
  add name, type, ttl, data
end