Class: Gcloud::Dns::Project
- Inherits:
-
Object
- Object
- Gcloud::Dns::Project
- Defined in:
- lib/gcloud/dns/project.rb
Overview
Project
The project is a top level container for resources including Cloud DNS ManagedZones. Projects can be created only in the Google Developers Console.
require "gcloud"
gcloud = Gcloud.new
dns = gcloud.dns
zone = dns.zone "example-com"
zone.records.each do |record|
puts record.name
end
See Gcloud#dns
Instance Attribute Summary collapse
-
#connection ⇒ Object
The Connection object.
-
#gapi ⇒ Object
The Google API Client object.
Class Method Summary collapse
-
.default_project ⇒ Object
Default project.
Instance Method Summary collapse
-
#additions_per_change ⇒ Object
Maximum allowed number of records to add per change.
-
#create_zone(zone_name, zone_dns, description: nil, name_server_set: nil) ⇒ Object
Creates a new zone.
-
#data_per_record ⇒ Object
Maximum allowed number of data entries per record.
-
#deletions_per_change ⇒ Object
Maximum allowed number of records to delete per change.
-
#initialize(project, credentials) ⇒ Project
constructor
Creates a new Connection instance.
-
#number ⇒ Object
The project number.
-
#project ⇒ Object
(also: #id)
The unique ID string for the current project.
-
#records_per_zone ⇒ Object
Maximum allowed number of records per zone in the project.
-
#reload! ⇒ Object
(also: #refresh!)
Reloads the change with updated status from the DNS service.
-
#total_data_per_change ⇒ Object
Maximum allowed total bytes size for all the data in one change.
-
#zone(zone_id) ⇒ Object
(also: #find_zone, #get_zone)
Retrieves an existing zone by name or id.
-
#zones(token: nil, max: nil) ⇒ Object
(also: #find_zones)
Retrieves the list of zones belonging to the project.
-
#zones_quota ⇒ Object
Maximum allowed number of zones in the project.
Constructor Details
#initialize(project, credentials) ⇒ Project
Creates a new Connection instance.
See Gcloud.dns
54 55 56 57 58 59 |
# File 'lib/gcloud/dns/project.rb', line 54 def initialize project, credentials #:nodoc: project = project.to_s # Always cast to a string fail ArgumentError, "project is missing" if project.empty? @connection = Connection.new project, credentials @gapi = nil end |
Instance Attribute Details
#connection ⇒ Object
The Connection object.
44 45 46 |
# File 'lib/gcloud/dns/project.rb', line 44 def connection @connection end |
#gapi ⇒ Object
The Google API Client object.
48 49 50 |
# File 'lib/gcloud/dns/project.rb', line 48 def gapi @gapi end |
Class Method Details
.default_project ⇒ Object
Default project.
129 130 131 132 133 134 |
# File 'lib/gcloud/dns/project.rb', line 129 def self.default_project #:nodoc: ENV["DNS_PROJECT"] || ENV["GCLOUD_PROJECT"] || ENV["GOOGLE_CLOUD_PROJECT"] || Gcloud::GCE.project_id end |
Instance Method Details
#additions_per_change ⇒ Object
Maximum allowed number of records to add per change.
101 102 103 104 |
# File 'lib/gcloud/dns/project.rb', line 101 def additions_per_change reload! if @gapi.nil? @gapi["quota"]["rrsetAdditionsPerChange"] if @gapi["quota"] end |
#create_zone(zone_name, zone_dns, description: nil, name_server_set: nil) ⇒ Object
Creates a new zone.
Parameters
zone_name
-
User assigned name for this resource. Must be unique within the project. The name must be 1-32 characters long, must begin with a letter, end with a letter or digit, and only contain lowercase letters, digits or dashes. (
String
) zone_dns
-
The DNS name of this managed zone, for instance “example.com.”. (
String
) description
-
A string of at most 1024 characters associated with this resource for the user’s convenience. Has no effect on the managed zone’s function. (
String
) name_server_set
-
A NameServerSet is a set of DNS name servers that all host the same ManagedZones. Most users will leave this field unset. (
String
)
Returns
Gcloud::Dns::Zone
Examples
require "gcloud"
gcloud = Gcloud.new
dns = gcloud.dns
zone = dns.create_zone "example-com", "example.com."
255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/gcloud/dns/project.rb', line 255 def create_zone zone_name, zone_dns, description: nil, name_server_set: nil ensure_connection! resp = connection.create_zone zone_name, zone_dns, description: description, name_server_set: name_server_set if resp.success? Zone.from_gapi resp.data, connection else fail ApiError.from_response(resp) end end |
#data_per_record ⇒ Object
Maximum allowed number of data entries per record.
94 95 96 97 |
# File 'lib/gcloud/dns/project.rb', line 94 def data_per_record reload! if @gapi.nil? @gapi["quota"]["resourceRecordsPerRrset"] if @gapi["quota"] end |
#deletions_per_change ⇒ Object
Maximum allowed number of records to delete per change.
108 109 110 111 |
# File 'lib/gcloud/dns/project.rb', line 108 def deletions_per_change reload! if @gapi.nil? @gapi["quota"]["rrsetDeletionsPerChange"] if @gapi["quota"] end |
#number ⇒ Object
The project number.
80 81 82 83 |
# File 'lib/gcloud/dns/project.rb', line 80 def number reload! if @gapi.nil? @gapi["number"] end |
#project ⇒ Object Also known as: id
73 74 75 |
# File 'lib/gcloud/dns/project.rb', line 73 def project connection.project end |
#records_per_zone ⇒ Object
Maximum allowed number of records per zone in the project.
115 116 117 118 |
# File 'lib/gcloud/dns/project.rb', line 115 def records_per_zone reload! if @gapi.nil? @gapi["quota"]["rrsetsPerManagedZone"] if @gapi["quota"] end |
#reload! ⇒ Object Also known as: refresh!
Reloads the change with updated status from the DNS service.
270 271 272 273 274 275 276 277 278 |
# File 'lib/gcloud/dns/project.rb', line 270 def reload! ensure_connection! resp = connection.get_project if resp.success? @gapi = resp.data else fail ApiError.from_response(resp) end end |
#total_data_per_change ⇒ Object
Maximum allowed total bytes size for all the data in one change.
122 123 124 125 |
# File 'lib/gcloud/dns/project.rb', line 122 def total_data_per_change reload! if @gapi.nil? @gapi["quota"]["totalRrdataSizePerChange"] if @gapi["quota"] end |
#zone(zone_id) ⇒ Object Also known as: find_zone, get_zone
157 158 159 160 161 162 163 164 165 |
# File 'lib/gcloud/dns/project.rb', line 157 def zone zone_id ensure_connection! resp = connection.get_zone zone_id if resp.success? Zone.from_gapi resp.data, connection else nil end end |
#zones(token: nil, max: nil) ⇒ Object Also known as: find_zones
Retrieves the list of zones belonging to the project.
Parameters
token
-
A previously-returned page token representing part of the larger set of results to view. (
String
) max
-
Maximum number of zones to return. (
Integer
)
Returns
Array of Gcloud::Dns::Zone (See Gcloud::Dns::Zone::List)
Examples
require "gcloud"
gcloud = Gcloud.new
dns = gcloud.dns
zones = dns.zones
zones.each do |zone|
puts zone.name
end
If you have a significant number of zones, you may need to paginate through them: (See Gcloud::Dns::Zone::List)
require "gcloud"
gcloud = Gcloud.new
dns = gcloud.dns
zones = dns.zones
loop do
zones.each do |zone|
puts zone.name
end
break unless zones.next?
zones = zones.next
end
211 212 213 214 215 216 217 218 219 |
# File 'lib/gcloud/dns/project.rb', line 211 def zones token: nil, max: nil ensure_connection! resp = connection.list_zones token: token, max: max if resp.success? Zone::List.from_response resp, connection else fail ApiError.from_response(resp) end end |
#zones_quota ⇒ Object
Maximum allowed number of zones in the project.
87 88 89 90 |
# File 'lib/gcloud/dns/project.rb', line 87 def zones_quota reload! if @gapi.nil? @gapi["quota"]["managedZones"] if @gapi["quota"] end |