class Google::Cloud::Dns::Project

# Project

The project is a top level container for resources including Cloud DNS ManagedZones. Projects can be created only in the [Google Developers Console](console.developers.google.com).

@example

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.records.each do |record|
  puts record.name
end

See {Google::Cloud#dns}

Attributes

gapi[RW]

@private The Google API Client object.

service[RW]

@private The Service object.

Public Class Methods

new(service) click to toggle source

@private Creates a new Service instance.

See {Google::Cloud.dns}

# File lib/google/cloud/dns/project.rb, line 54
def initialize service
  @service = service
  @gapi = nil
end

Public Instance Methods

additions_per_change() click to toggle source

Maximum allowed number of records to add per change.

# File lib/google/cloud/dns/project.rb, line 101
def additions_per_change
  reload! if @gapi.nil?
  @gapi.quota&.rrset_additions_per_change
end
create_zone(zone_name, zone_dns, description: nil, name_server_set: nil) click to toggle source

Creates a new zone.

@param [String] 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.

@param [String] zone_dns The DNS name of this managed zone, for

instance "example.com.".

@param [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.

@param [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.

@return [Google::Cloud::Dns::Zone]

@example

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.create_zone "example-com", "example.com."
# File lib/google/cloud/dns/project.rb, line 211
def create_zone zone_name, zone_dns, description: nil,
                name_server_set: nil
  ensure_service!
  gapi = service.create_zone zone_name, zone_dns,
                             description: description,
                             name_server_set: name_server_set
  Zone.from_gapi gapi, service
end
data_per_record() click to toggle source

Maximum allowed number of data entries per record.

# File lib/google/cloud/dns/project.rb, line 94
def data_per_record
  reload! if @gapi.nil?
  @gapi.quota&.resource_records_per_rrset
end
deletions_per_change() click to toggle source

Maximum allowed number of records to delete per change.

# File lib/google/cloud/dns/project.rb, line 108
def deletions_per_change
  reload! if @gapi.nil?
  @gapi.quota&.rrset_deletions_per_change
end
find_zone(zone_id)
Alias for: zone
find_zones(token: nil, max: nil)
Alias for: zones
get_zone(zone_id)
Alias for: zone
id()
Alias for: project_id
number() click to toggle source

The project number.

# File lib/google/cloud/dns/project.rb, line 80
def number
  reload! if @gapi.nil?
  @gapi.number
end
project()
Alias for: project_id
project_id() click to toggle source

The unique ID string for the current project.

@example

require "google/cloud/dns"

dns = Google::Cloud::Dns.new(
  project_id: "my-project",
  credentials: "/path/to/keyfile.json"
)

dns.project_id #=> "my-project"
# File lib/google/cloud/dns/project.rb, line 72
def project_id
  service.project
end
Also aliased as: project, id
records_per_zone() click to toggle source

Maximum allowed number of records per zone in the project.

# File lib/google/cloud/dns/project.rb, line 115
def records_per_zone
  reload! if @gapi.nil?
  @gapi.quota&.rrsets_per_managed_zone
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/project.rb, line 222
def reload!
  ensure_service!
  @gapi = service.get_project
end
Also aliased as: refresh!
total_data_per_change() click to toggle source

Maximum allowed total bytes size for all the data in one change.

# File lib/google/cloud/dns/project.rb, line 122
def total_data_per_change
  reload! if @gapi.nil?
  @gapi.quota&.total_rrdata_size_per_change
end
zone(zone_id) click to toggle source

Retrieves an existing zone by name or id.

@param [String, Integer] zone_id The name or id of a zone.

@return [Google::Cloud::Dns::Zone, nil] Returns `nil` if the zone does

not exist.

@example

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
puts zone.name
# File lib/google/cloud/dns/project.rb, line 142
def zone zone_id
  ensure_service!
  gapi = service.get_zone zone_id
  Zone.from_gapi gapi, service
rescue Google::Cloud::NotFoundError
  nil
end
Also aliased as: find_zone, get_zone
zones(token: nil, max: nil) click to toggle source

Retrieves the list of zones belonging to the project.

@param [String] token A previously-returned page token representing

part of the larger set of results to view.

@param [Integer] max Maximum number of zones to return.

@return [Array<Google::Cloud::Dns::Zone>] (See {Google::Cloud::Dns::Zone::List})

@example

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zones = dns.zones
zones.each do |zone|
  puts zone.name
end

@example Retrieve all zones: (See {Zone::List#all})

require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zones = dns.zones
zones.all do |zone|
  puts zone.name
end
# File lib/google/cloud/dns/project.rb, line 180
def zones token: nil, max: nil
  ensure_service!
  gapi = service.list_zones token: token, max: max
  Zone::List.from_gapi gapi, service, max
end
Also aliased as: find_zones
zones_quota() click to toggle source

Maximum allowed number of zones in the project.

# File lib/google/cloud/dns/project.rb, line 87
def zones_quota
  reload! if @gapi.nil?
  @gapi.quota&.managed_zones
end

Protected Instance Methods

ensure_service!() click to toggle source

Raise an error unless an active connection is available.

# File lib/google/cloud/dns/project.rb, line 232
def ensure_service!
  raise "Must have active connection" unless service
end