Class: OpenStack::Keystone::Admin::Tenant
- Inherits:
-
Base
- Object
- ActiveResource::Base
- Base
- Common
- Base
- OpenStack::Keystone::Admin::Tenant
- Defined in:
- lib/open_stack/keystone/admin/tenant.rb
Overview
An OpenStack Tenant (“admin view”)
Attributes
-
name
- The name of this tenant -
description
- A description of this tenant -
enabled
- True if this tenant is enabled
Class Method Summary collapse
-
.find_by_name(name) ⇒ Object
List of tenant with a given name.
-
.find_every(options) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#add_role_to_user(role, user) ⇒ Object
Adds a role to a user in this tenant.
-
#delete_role_from_user(role, user) ⇒ Object
Removes a role to a user in this tenant.
-
#description=(description) ⇒ Object
Returns a filtered description for this tenant.
-
#initialize(params = {}, persisted = false) ⇒ Tenant
constructor
:notnew:.
-
#user(id) ⇒ Object
Returns the instance of OpenStack::Keystone::Admin::User with the given id.
-
#user_roles(user, scope = :all) ⇒ Object
List if roles in this tenant for a given instance of OpenStack::Keystone::Admin::User or user id.
-
#users(scope = :all) ⇒ Object
List of Users (instances of OpenStack::Keystone::Admin::User) in this tenant.
Methods inherited from Base
Methods inherited from Common
collection_path, custom_method_collection_url, element_path
Methods inherited from Base
Methods inherited from ActiveResource::Base
Constructor Details
#initialize(params = {}, persisted = false) ⇒ Tenant
:notnew:
44 45 46 47 48 |
# File 'lib/open_stack/keystone/admin/tenant.rb', line 44 def initialize(params = {}, persisted = false) # :notnew: super(params, persisted) self.description = description end |
Class Method Details
.find_by_name(name) ⇒ Object
List of tenant with a given name
Attributes
-
name
- A string
75 76 77 |
# File 'lib/open_stack/keystone/admin/tenant.rb', line 75 def self.find_by_name(name) all.detect { |x| x.name == name } end |
.find_every(options) ⇒ Object
:nodoc:
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/open_stack/keystone/admin/tenant.rb', line 50 def self.find_every() # :nodoc: class_name = self.name.split('::').last.downcase begin case from = [:from] when Symbol instantiate_collection(get(from, [:params])) when String path = "#{from}#{query_string([:params])}" instantiate_collection(format.decode(connection.get(path, headers).body)[class_name.pluralize] || []) else , = ([:params]) path = collection_path(, ) instantiate_collection((format.decode(connection.get(path, headers).body)[class_name.pluralize] || []), ) end rescue ActiveResource::ResourceNotFound # Swallowing ResourceNotFound exceptions and return nil - as per # ActiveRecord. nil end end |
Instance Method Details
#add_role_to_user(role, user) ⇒ Object
Adds a role to a user in this tenant
Attributes
-
role
- Instance of OpenStack::Keystone::Admin::Role or a role id -
user
- Instance of OpenStack::Keystone::Admin::User or a user id
111 112 113 114 115 116 |
# File 'lib/open_stack/keystone/admin/tenant.rb', line 111 def add_role_to_user(role, user) role_id = role.is_a?(OpenStack::Keystone::Admin::Role) ? role.id : role user_id = user.is_a?(OpenStack::Keystone::Admin::User) ? user.id : user put("users/#{user_id}/roles/OS-KSADM/#{role_id}", {}, "null") end |
#delete_role_from_user(role, user) ⇒ Object
Removes a role to a user in this tenant
Attributes
-
role
- Instance of OpenStack::Keystone::Admin::Role or a role id -
user
- Instance of OpenStack::Keystone::Admin::User or a user id
123 124 125 126 127 128 |
# File 'lib/open_stack/keystone/admin/tenant.rb', line 123 def delete_role_from_user(role, user) role_id = role.is_a?(OpenStack::Keystone::Admin::Role) ? role.id : role user_id = user.is_a?(OpenStack::Keystone::Admin::User) ? user.id : user delete("users/#{user_id}/roles/OS-KSADM/#{role_id}") end |
#description=(description) ⇒ Object
Returns a filtered description for this tenant
131 132 133 134 |
# File 'lib/open_stack/keystone/admin/tenant.rb', line 131 def description=(description) @attributes[:description] = description.gsub /[^\w\s\.\-:@+,'"]/, '_' if description end |
#user(id) ⇒ Object
Returns the instance of OpenStack::Keystone::Admin::User with the given id
Attributes
-
id
- A string
91 92 93 |
# File 'lib/open_stack/keystone/admin/tenant.rb', line 91 def user(id) users(id) end |
#user_roles(user, scope = :all) ⇒ Object
List if roles in this tenant for a given instance of OpenStack::Keystone::Admin::User or user id
Attributes
-
user
- A string -
scope
- An ActiveResource scope (defaults to :all)
100 101 102 103 104 |
# File 'lib/open_stack/keystone/admin/tenant.rb', line 100 def user_roles(user, scope = :all) user_id = user.is_a?(OpenStack::Keystone::Admin::User) ? user.id : user Role.find(scope, :params => {:tenant_id => self.id, :user_id => user_id}) end |
#users(scope = :all) ⇒ Object
List of Users (instances of OpenStack::Keystone::Admin::User) in this tenant
Attributes
-
scope
- An ActiveResource scope (defaults to :all)
83 84 85 |
# File 'lib/open_stack/keystone/admin/tenant.rb', line 83 def users(scope = :all) User.find(scope, :params => {:tenant_id => self.id}) end |