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(project, credentials) ⇒ Project



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

def initialize project, credentials
  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

#connectionObject



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

def connection
  @connection
end

#gapiObject



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

def gapi
  @gapi
end

Class Method Details

.default_projectObject



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

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.



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) ⇒ 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:



233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/gcloud/dns/project.rb', line 233

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_recordObject

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_changeObject

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

#numberObject

The project number.



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

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"


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

def project
  connection.project
end

#records_per_zoneObject

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.



248
249
250
251
252
253
254
255
256
# File 'lib/gcloud/dns/project.rb', line 248

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_changeObject

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) ⇒ 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:



152
153
154
155
156
157
158
159
160
# File 'lib/gcloud/dns/project.rb', line 152

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) ⇒ 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

With pagination: (See 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

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:



197
198
199
200
201
202
203
204
205
# File 'lib/gcloud/dns/project.rb', line 197

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_quotaObject

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