class Google::Cloud::Dns::Change

# DNS Change

Represents a request containing additions or deletions or records. Additions and deletions can be done in bulk, in a single atomic transaction, and take effect at the same time in each authoritative DNS server.

@example

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.changes.each do |change|
  puts "Change includes #{change.additions.count} additions " \
       "and #{change.additions.count} deletions."
end

Attributes

gapi[RW]

@private The Google API Client object.

zone[RW]

@private The Zone object this Change belongs to.

Public Class Methods

from_gapi(gapi, zone) click to toggle source

@private New Change from a Google API Client object.

# File lib/google/cloud/dns/change.rb, line 141
def self.from_gapi gapi, zone
  new.tap do |f|
    f.gapi = gapi
    f.zone = zone
  end
end
new() click to toggle source

@private Create an empty Change object.

# File lib/google/cloud/dns/change.rb, line 51
def initialize
  @zone = nil
  @gapi = {}
end

Public Instance Methods

additions() click to toggle source

The records added in this change request.

# File lib/google/cloud/dns/change.rb, line 66
def additions
  Array(@gapi.additions).map { |gapi| Record.from_gapi gapi }
end
deletions() click to toggle source

The records removed in this change request.

# File lib/google/cloud/dns/change.rb, line 73
def deletions
  Array(@gapi.deletions).map { |gapi| Record.from_gapi gapi }
end
done?() click to toggle source

Checks if the status is `“done”`.

# File lib/google/cloud/dns/change.rb, line 86
def done?
  return false if status.nil?
  "done".casecmp(status).zero?
end
id() click to toggle source

Unique identifier for the resource; defined by the server.

# File lib/google/cloud/dns/change.rb, line 59
def id
  @gapi.id
end
pending?() click to toggle source

Checks if the status is `“pending”`.

# File lib/google/cloud/dns/change.rb, line 93
def pending?
  return false if status.nil?
  "pending".casecmp(status).zero?
end
refresh!()
Alias for: reload!
reload!() click to toggle source

Reloads the change with updated status from the DNS service.

# File lib/google/cloud/dns/change.rb, line 109
def reload!
  ensure_service!
  @gapi = zone.service.get_change @zone.id, id
end
Also aliased as: refresh!
started_at() click to toggle source

The time that this operation was started by the server.

# File lib/google/cloud/dns/change.rb, line 101
def started_at
  Time.parse @gapi.start_time
rescue StandardError
  nil
end
status() click to toggle source

Status of the operation. Values are `“done”` and `“pending”`.

# File lib/google/cloud/dns/change.rb, line 80
def status
  @gapi.status
end
wait_until_done!() click to toggle source

Refreshes the change until the status is `done`. The delay between refreshes will incrementally increase.

@example

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
change = zone.change 1234567890
change.done? #=> false
change.wait_until_done!
change.done? #=> true
# File lib/google/cloud/dns/change.rb, line 129
def wait_until_done!
  backoff = ->(retries) { sleep 2 * retries + 5 }
  retries = 0
  until done?
    backoff.call retries
    retries += 1
    reload!
  end
end

Protected Instance Methods

ensure_service!() click to toggle source

Raise an error unless an active service is available.

# File lib/google/cloud/dns/change.rb, line 152
def ensure_service!
  raise "Must have active connection" unless zone&.service
end