Class: Gcloud::Dns::Project

Inherits:
Object
  • Object
show all
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](console.developers.google.com).

See Gcloud#dns

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
zone = dns.zone "example-com"
zone.records.each do |record|
  puts record.name
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ Project



55
56
57
58
# File 'lib/gcloud/dns/project.rb', line 55

def initialize service
  @service = service
  @gapi = nil
end

Instance Attribute Details

#gapiObject



49
50
51
# File 'lib/gcloud/dns/project.rb', line 49

def gapi
  @gapi
end

#serviceObject



45
46
47
# File 'lib/gcloud/dns/project.rb', line 45

def service
  @service
end

Class Method Details

.default_projectObject



127
128
129
130
131
132
# File 'lib/gcloud/dns/project.rb', line 127

def self.default_project
  ENV["DNS_PROJECT"] ||
    ENV["GCLOUD_PROJECT"] ||
    ENV["GOOGLE_CLOUD_PROJECT"] ||
    Gcloud::GCE.project_id
end

Instance Method Details

#additions_per_changeObject

Maximum allowed number of records to add per change.



99
100
101
102
# File 'lib/gcloud/dns/project.rb', line 99

def additions_per_change
  reload! if @gapi.nil?
  @gapi.quota.rrset_additions_per_change if @gapi.quota
end

#create_zone(zone_name, zone_dns, description: nil, name_server_set: nil) ⇒ Gcloud::Dns::Zone

Creates a new zone.

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
zone = dns.create_zone "example-com", "example.com."

Parameters:

  • zone_name (String)

    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.

  • zone_dns (String)

    The DNS name of this managed zone, for instance “example.com.”.

  • description (String) (defaults to: nil)

    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.

  • name_server_set (String) (defaults to: nil)

    A NameServerSet is a set of DNS name servers that all host the same ManagedZones. Most users will leave this field unset.

Returns:



221
222
223
224
225
226
227
228
# File 'lib/gcloud/dns/project.rb', line 221

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_recordObject

Maximum allowed number of data entries per record.



92
93
94
95
# File 'lib/gcloud/dns/project.rb', line 92

def data_per_record
  reload! if @gapi.nil?
  @gapi.quota.resource_records_per_rrset if @gapi.quota
end

#deletions_per_changeObject

Maximum allowed number of records to delete per change.



106
107
108
109
# File 'lib/gcloud/dns/project.rb', line 106

def deletions_per_change
  reload! if @gapi.nil?
  @gapi.quota.rrset_deletions_per_change if @gapi.quota
end

#numberObject

The project number.



78
79
80
81
# File 'lib/gcloud/dns/project.rb', line 78

def number
  reload! if @gapi.nil?
  @gapi.number
end

#projectObject Also known as: id

The unique ID string for the current project.

Examples:

require "gcloud"

gcloud = Gcloud.new "my-todo-project", "/path/to/keyfile.json"
dns = gcloud.dns

dns.project #=> "my-todo-project"


71
72
73
# File 'lib/gcloud/dns/project.rb', line 71

def project
  service.project
end

#records_per_zoneObject

Maximum allowed number of records per zone in the project.



113
114
115
116
# File 'lib/gcloud/dns/project.rb', line 113

def records_per_zone
  reload! if @gapi.nil?
  @gapi.quota.rrsets_per_managed_zone if @gapi.quota
end

#reload!Object Also known as: refresh!

Reloads the change with updated status from the DNS service.



232
233
234
235
# File 'lib/gcloud/dns/project.rb', line 232

def reload!
  ensure_service!
  @gapi = service.get_project
end

#total_data_per_changeObject

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



120
121
122
123
# File 'lib/gcloud/dns/project.rb', line 120

def total_data_per_change
  reload! if @gapi.nil?
  @gapi.quota.total_rrdata_size_per_change if @gapi.quota
end

#zone(zone_id) ⇒ Gcloud::Dns::Zone? Also known as: find_zone, get_zone

Retrieves an existing zone by name or id.

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
zone = dns.zone "example-com"
puts zone.name

Parameters:

  • zone_id (String, Integer)

    The name or id of a zone.

Returns:



150
151
152
153
154
155
156
# File 'lib/gcloud/dns/project.rb', line 150

def zone zone_id
  ensure_service!
  gapi = service.get_zone zone_id
  Zone.from_gapi gapi, service
rescue Gcloud::NotFoundError
  nil
end

#zones(token: nil, max: nil) ⇒ Array<Gcloud::Dns::Zone> Also known as: find_zones

Retrieves the list of zones belonging to the project.

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
zones = dns.zones
zones.each do |zone|
  puts zone.name
end

Retrieve all zones: (See Zone::List#all)

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
zones = dns.zones
zones.all do |zone|
  puts zone.name
end

Parameters:

  • token (String) (defaults to: nil)

    A previously-returned page token representing part of the larger set of results to view.

  • max (Integer) (defaults to: nil)

    Maximum number of zones to return.

Returns:



189
190
191
192
193
# File 'lib/gcloud/dns/project.rb', line 189

def zones token: nil, max: nil
  ensure_service!
  gapi = service.list_zones token: token, max: max
  Zone::List.from_gapi gapi, service, max
end

#zones_quotaObject

Maximum allowed number of zones in the project.



85
86
87
88
# File 'lib/gcloud/dns/project.rb', line 85

def zones_quota
  reload! if @gapi.nil?
  @gapi.quota.managed_zones if @gapi.quota
end