Cloud DNS API - Class Google::Cloud::Dns::Zone::Transaction (v0.37.0)

Reference documentation and code samples for the Cloud DNS API class Google::Cloud::Dns::Zone::Transaction.

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.

Inherits

  • Object

Example

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

Methods

#add

def add(name, type, ttl, data)

Adds a record to the Zone.

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..
Example
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

#modify

def modify(name, type, &block) { |record| ... }

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

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 Parameter
  • record (Record) — the record to be modified
Example
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

#remove

def remove(name, type)

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

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.
Example
require "google/cloud/dns"

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

#replace

def replace(name, type, ttl, data)

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

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..
Example
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