Class: Gcloud::Dns::Change

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/dns/change.rb,
lib/gcloud/dns/change/list.rb

Overview

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.

Examples:

require "gcloud"

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

Defined Under Namespace

Classes: List

Instance Method Summary collapse

Instance Method Details

#additionsObject

The records added in this change request.


66
67
68
# File 'lib/gcloud/dns/change.rb', line 66

def additions
  Array(@gapi["additions"]).map { |gapi| Record.from_gapi gapi }
end

#deletionsObject

The records removed in this change request.


73
74
75
# File 'lib/gcloud/dns/change.rb', line 73

def deletions
  Array(@gapi["deletions"]).map { |gapi| Record.from_gapi gapi }
end

#done?Boolean

Checks if the status is "done".


86
87
88
89
# File 'lib/gcloud/dns/change.rb', line 86

def done?
  return false if status.nil?
  "done".casecmp(status).zero?
end

#idObject

Unique identifier for the resource; defined by the server.


59
60
61
# File 'lib/gcloud/dns/change.rb', line 59

def id
  @gapi["id"]
end

#pending?Boolean

Checks if the status is "pending".


93
94
95
96
# File 'lib/gcloud/dns/change.rb', line 93

def pending?
  return false if status.nil?
  "pending".casecmp(status).zero?
end

#reload!Object Also known as: refresh!

Reloads the change with updated status from the DNS service.


109
110
111
112
113
114
115
116
117
# File 'lib/gcloud/dns/change.rb', line 109

def reload!
  ensure_connection!
  resp = zone.connection.get_change @zone.id, id
  if resp.success?
    @gapi = resp.data
  else
    fail ApiError.from_response(resp)
  end
end

#started_atObject

The time that this operation was started by the server.


101
102
103
104
105
# File 'lib/gcloud/dns/change.rb', line 101

def started_at
  Time.parse @gapi["startTime"]
rescue
  nil
end

#statusObject

Status of the operation. Values are "done" and "pending".


80
81
82
# File 'lib/gcloud/dns/change.rb', line 80

def status
  @gapi["status"]
end

#wait_until_done!Object

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

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
zone = dns.zone "example-com"
change = zone.change 1234567890
change.done? #=> false
change.wait_until_done!
change.done? #=> true

135
136
137
138
139
140
141
142
143
# File 'lib/gcloud/dns/change.rb', line 135

def wait_until_done!
  backoff = ->(retries) { sleep 2 * retries + 5 }
  retries = 0
  until done?
    backoff.call retries
    retries += 1
    reload!
  end
end