Class: Gcloud::Dns::Zone::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/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 "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
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 "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
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..


81
82
83
# File 'lib/gcloud/dns/zone/transaction.rb', line 81

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

#modify(name, type) ⇒ Object

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

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
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.


164
165
166
167
168
169
170
# File 'lib/gcloud/dns/zone/transaction.rb', line 164

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 "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
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.


105
106
107
# File 'lib/gcloud/dns/zone/transaction.rb', line 105

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

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

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

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
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..


138
139
140
141
# File 'lib/gcloud/dns/zone/transaction.rb', line 138

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