Class: Datacentred::Model::Project

Inherits:
Base
  • Object
show all
Defined in:
lib/datacentred/model/project.rb

Overview

A project on your DataCentred account.

Projects (also called “Cloud Projects” or “Tenants”) are a way of grouping together users and resources.

All projects created in your DataCented account are backed by a corresponding project in OpenStack’s identity service (Keystone).

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Datacentred::Model::Base

Instance Attribute Details

#created_atTime (readonly)

Returns the current value of created_at.

Returns:

  • (Time)

    the current value of created_at



14
15
16
# File 'lib/datacentred/model/project.rb', line 14

def created_at
  @created_at
end

#idString

Returns the current value of id.

Returns:

  • (String)

    the current value of id



14
15
16
# File 'lib/datacentred/model/project.rb', line 14

def id
  @id
end

#nameString

Returns the current value of name.

Returns:

  • (String)

    the current value of name



14
15
16
# File 'lib/datacentred/model/project.rb', line 14

def name
  @name
end

#quota_setHash

Returns the current value of quota_set.

Returns:

  • (Hash)

    the current value of quota_set



14
15
16
# File 'lib/datacentred/model/project.rb', line 14

def quota_set
  @quota_set
end

#updated_atTime (readonly)

Returns the current value of updated_at.

Returns:

  • (Time)

    the current value of updated_at



14
15
16
# File 'lib/datacentred/model/project.rb', line 14

def updated_at
  @updated_at
end

Class Method Details

.add_user(project_id:, user_id:) ⇒ Boolean

Add a new user to this project, giving them access to it via OpenStack.

Parameters:

  • project_id (String)

    The unique identifier for this project.

  • user_id (String)

    The unique identifier for this user.

Returns:

  • (Boolean)

    Confirms the user was added (or is already present).

Raises:



84
85
86
87
# File 'lib/datacentred/model/project.rb', line 84

def add_user(project_id:, user_id:)
  Request::Projects.add_user project_id, user_id
  true
end

.all[Project]

List all available projects.

 @raise [Errors::Unauthorized] Raised if credentials aren’t valid.

Returns:

  • ([Project])

    A collection of all projects on this account.



30
31
32
# File 'lib/datacentred/model/project.rb', line 30

def all
  Request::Projects.list.map{|project| new project }
end

.create(params) ⇒ Project

Create a new project.

Parameters:

  • params (Hash)

    Project attributes

Returns:

Raises:



22
23
24
# File 'lib/datacentred/model/project.rb', line 22

def create(params)
  new Request::Projects.create params
end

.destroy(id) ⇒ Boolean

Permanently remove the specified project.

Parameters:

  • id (String)

    The unique identifier for this project.

Returns:

  • (Boolean)

    Confirms the user was destroyed.

Raises:



63
64
65
66
# File 'lib/datacentred/model/project.rb', line 63

def destroy(id)
  Request::Projects.destroy id
  true
end

.find(id) ⇒ Project

Find a project by unique ID.

Parameters:

  • id (String)

    The unique identifier for this project.

Returns:

  • (Project)

    The project, if it exists.

Raises:



40
41
42
# File 'lib/datacentred/model/project.rb', line 40

def find(id)
  new Request::Projects.show id
end

.remove_user(project_id:, user_id:) ⇒ Boolean

Remove user from this project, revoking their access to it on OpenStack.

Parameters:

  • project_id (String)

    The unique identifier for this project.

  • user_id (String)

    The unique identifier for this user.

Returns:

  • (Boolean)

    Confirms that user was removed (or is already absent).

Raises:



96
97
98
99
# File 'lib/datacentred/model/project.rb', line 96

def remove_user(project_id:, user_id:)
  Request::Projects.remove_user project_id, user_id
  true
end

.update(id, params) ⇒ Project

Update a project by unique ID.

Parameters:

  • id (String)

    The unique identifier for this project.

  • params (Hash)

    Project attributes.

Returns:

  • (Project)

    The updated project.

Raises:



52
53
54
# File 'lib/datacentred/model/project.rb', line 52

def update(id, params)
  new Request::Projects.update id, params
end

.users(id) ⇒ [User]

List all users assigned to this project.

Parameters:

  • id (String)

    The unique identifier for this project.

Returns:

  • ([User])

    A collection of the project’s users.

Raises:



73
74
75
# File 'lib/datacentred/model/project.rb', line 73

def users(id)
  Request::Projects.list_users(id).map{|user| new user }
end