Class: Gcloud::ResourceManager::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/resource_manager/manager.rb

Overview

Manager

Provides methods for creating, retrieving, and updating projects.

require "gcloud"

gcloud = Gcloud.new resource_manager = gcloud.resource_manager resource_manager.projects.each do |project| puts projects.project_id end

See Gcloud#resource_manager

Instance Method Summary collapse

Instance Method Details

#create_project(project_id, name: nil, labels: nil) ⇒ Gcloud::ResourceManager::Project

Creates a project resource.

Initially, the project resource is owned by its creator exclusively. The creator can later grant permission to others to read or update the project.

Several APIs are activated automatically for the project, including Google Cloud Storage.

Examples:

require "gcloud"

gcloud = Gcloud.new
resource_manager = gcloud.resource_manager
project = resource_manager.create_project "tokyo-rain-123"

A project can also be created with a name and labels:

require "gcloud"

gcloud = Gcloud.new
resource_manager = gcloud.resource_manager
project = resource_manager.create_project "tokyo-rain-123",
                                          name: "Todos Development",
                                          labels: {env: :development}

190
191
192
193
194
195
196
197
198
199
# File 'lib/gcloud/resource_manager/manager.rb', line 190

def create_project project_id, name: nil, labels: nil
  resp = connection.create_project project_id,
                                   name,
                                   labels
  if resp.success?
    Project.from_gapi resp.data, connection
  else
    fail ApiError.from_response(resp)
  end
end

#delete(project_id) ⇒ Object

Marks the project for deletion. This method will only affect the project if the following criteria are met:

  • The project does not have a billing account associated with it.
  • The project has a lifecycle state of ACTIVE.
  • This method changes the project's lifecycle state from ACTIVE to DELETE_REQUESTED. The deletion starts at an unspecified time, at which point the lifecycle state changes to DELETE_IN_PROGRESS.

Until the deletion completes, you can check the lifecycle state by retrieving the project with Manager#project. The project remains visible to Manager#project and Manager#projects, but cannot be updated.

After the deletion completes, the project is not retrievable by the Manager#project and Manager#projects methods.

The caller must have modify permissions for this project.

Examples:

require "gcloud"

gcloud = Gcloud.new
resource_manager = gcloud.resource_manager
resource_manager.delete "tokyo-rain-123"

229
230
231
232
233
234
235
236
# File 'lib/gcloud/resource_manager/manager.rb', line 229

def delete project_id
  resp = connection.delete_project project_id
  if resp.success?
    true
  else
    fail ApiError.from_response(resp)
  end
end

#project(project_id) ⇒ Gcloud::ResourceManager::Project?

Retrieves the project identified by the specified project_id.

Examples:

require "gcloud"

gcloud = Gcloud.new
resource_manager = gcloud.resource_manager
project = resource_manager.project "tokyo-rain-123"
project.project_id #=> "tokyo-rain-123"

134
135
136
137
138
139
140
141
# File 'lib/gcloud/resource_manager/manager.rb', line 134

def project project_id
  resp = connection.get_project project_id
  if resp.success?
    Project.from_gapi resp.data, connection
  else
    nil
  end
end

#projects(filter: nil, token: nil, max: nil) ⇒ Array<Gcloud::ResourceManager::Project>

Retrieves the projects that are visible to the user and satisfy the specified filter. This method returns projects in an unspecified order. New projects do not necessarily appear at the end of the list.

Examples:

require "gcloud"

gcloud = Gcloud.new
resource_manager = gcloud.resource_manager
projects = resource_manager.projects
projects.each do |project|
  puts project.project_id
end

Projects can be filtered using the filter option:

require "gcloud"

gcloud = Gcloud.new
resource_manager = gcloud.resource_manager
projects = resource_manager.projects filter: "labels.env:production"
projects.each do |project|
  puts project.project_id
end

With pagination: (See Project::List)

require "gcloud"

gcloud = Gcloud.new
resource_manager = gcloud.resource_manager
projects = resource_manager.projects.all
projects.each do |project|
  puts project.project_id
end

109
110
111
112
113
114
115
116
# File 'lib/gcloud/resource_manager/manager.rb', line 109

def projects filter: nil, token: nil, max: nil
  resp = connection.list_project filter: filter, token: token, max: max
  if resp.success?
    Project::List.from_response resp, self
  else
    fail ApiError.from_response(resp)
  end
end

#undelete(project_id) ⇒ Object

Restores the project. You can only use this method for a project that has a lifecycle state of DELETE_REQUESTED. After deletion starts, as indicated by a lifecycle state of DELETE_IN_PROGRESS, the project cannot be restored.

The caller must have modify permissions for this project.

Examples:

require "gcloud"

gcloud = Gcloud.new
resource_manager = gcloud.resource_manager
resource_manager.undelete "tokyo-rain-123"

255
256
257
258
259
260
261
262
# File 'lib/gcloud/resource_manager/manager.rb', line 255

def undelete project_id
  resp = connection.undelete_project project_id
  if resp.success?
    true
  else
    fail ApiError.from_response(resp)
  end
end