Class: Gcloud::Dns::Change
- Inherits:
-
Object
- Object
- Gcloud::Dns::Change
- 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.
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 Attribute Summary collapse
-
#gapi ⇒ Object
The Google API Client object.
-
#zone ⇒ Object
The Zone object this Change belongs to.
Class Method Summary collapse
-
.from_gapi(gapi, zone) ⇒ Object
New Change from a Google API Client object.
Instance Method Summary collapse
-
#additions ⇒ Object
The records added in this change request.
-
#deletions ⇒ Object
The records removed in this change request.
-
#done? ⇒ Boolean
Checks if the status is “done”.
-
#id ⇒ Object
Unique identifier for the resource; defined by the server.
-
#initialize ⇒ Change
constructor
Create an empty Change object.
-
#pending? ⇒ Boolean
Checks if the status is “pending”.
-
#reload! ⇒ Object
(also: #refresh!)
Reloads the change with updated status from the DNS service.
-
#started_at ⇒ Object
The time that this operation was started by the server.
-
#status ⇒ Object
Status of the operation.
-
#wait_until_done! ⇒ Object
Refreshes the change until the status is
done.
Constructor Details
#initialize ⇒ Change
Create an empty Change object.
50 51 52 53 |
# File 'lib/gcloud/dns/change.rb', line 50 def initialize #:nodoc: @zone = nil @gapi = {} end |
Instance Attribute Details
#gapi ⇒ Object
The Google API Client object.
46 47 48 |
# File 'lib/gcloud/dns/change.rb', line 46 def gapi @gapi end |
#zone ⇒ Object
The Zone object this Change belongs to.
42 43 44 |
# File 'lib/gcloud/dns/change.rb', line 42 def zone @zone end |
Class Method Details
.from_gapi(gapi, zone) ⇒ Object
New Change from a Google API Client object.
147 148 149 150 151 152 |
# File 'lib/gcloud/dns/change.rb', line 147 def self.from_gapi gapi, zone #:nodoc: new.tap do |f| f.gapi = gapi f.zone = zone end end |
Instance Method Details
#additions ⇒ Object
The records added in this change request.
65 66 67 |
# File 'lib/gcloud/dns/change.rb', line 65 def additions Array(@gapi["additions"]).map { |gapi| Record.from_gapi gapi } end |
#deletions ⇒ Object
The records removed in this change request.
72 73 74 |
# File 'lib/gcloud/dns/change.rb', line 72 def deletions Array(@gapi["deletions"]).map { |gapi| Record.from_gapi gapi } end |
#done? ⇒ Boolean
Checks if the status is “done”.
85 86 87 88 |
# File 'lib/gcloud/dns/change.rb', line 85 def done? return false if status.nil? "done".casecmp(status).zero? end |
#id ⇒ Object
Unique identifier for the resource; defined by the server.
58 59 60 |
# File 'lib/gcloud/dns/change.rb', line 58 def id @gapi["id"] end |
#pending? ⇒ Boolean
Checks if the status is “pending”.
92 93 94 95 |
# File 'lib/gcloud/dns/change.rb', line 92 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.
108 109 110 111 112 113 114 115 116 |
# File 'lib/gcloud/dns/change.rb', line 108 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_at ⇒ Object
The time that this operation was started by the server.
100 101 102 103 104 |
# File 'lib/gcloud/dns/change.rb', line 100 def started_at Time.parse @gapi["startTime"] rescue nil end |
#status ⇒ Object
Status of the operation. Values are “done” and “pending”.
79 80 81 |
# File 'lib/gcloud/dns/change.rb', line 79 def status @gapi["status"] end |
#wait_until_done! ⇒ Object
Refreshes the change until the status is done. The delay between refreshes will incrementally increase.
Example
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 |