2012-02-22 09:40:32 -05:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Identity
|
|
|
|
class OpenStack
|
|
|
|
class Tenant < Fog::Model
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :description
|
|
|
|
attribute :enabled
|
|
|
|
attribute :name
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
self.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def roles_for(user)
|
|
|
|
connection.roles(
|
|
|
|
:tenant => self,
|
|
|
|
:user => user)
|
|
|
|
end
|
2012-02-26 03:09:22 -05:00
|
|
|
|
2012-04-02 03:26:45 -04:00
|
|
|
def users
|
|
|
|
requires :id
|
2012-12-10 21:13:20 -05:00
|
|
|
connection.users(:tenant_id => self.id)
|
2012-04-02 03:26:45 -04:00
|
|
|
end
|
|
|
|
|
2012-02-26 03:09:22 -05:00
|
|
|
def destroy
|
|
|
|
requires :id
|
|
|
|
connection.delete_tenant(self.id)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def update(attr = nil)
|
|
|
|
requires :id
|
|
|
|
merge_attributes(
|
|
|
|
connection.update_tenant(self.id, attr || attributes).body['tenant'])
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
requires :name
|
|
|
|
identity ? update : create
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
merge_attributes(
|
|
|
|
connection.create_tenant(attributes).body['tenant'])
|
|
|
|
self
|
|
|
|
end
|
2012-03-04 08:24:28 -05:00
|
|
|
|
2012-05-03 01:38:12 -04:00
|
|
|
def grant_user_role(user_id, role_id)
|
2012-03-04 08:24:28 -05:00
|
|
|
connection.add_user_to_tenant(self.id, user_id, role_id)
|
2012-03-04 08:24:28 -05:00
|
|
|
end
|
2012-05-03 01:38:12 -04:00
|
|
|
|
|
|
|
def revoke_user_role(user_id, role_id)
|
|
|
|
connection.remove_user_from_tenant(self.id, user_id, role_id)
|
|
|
|
end
|
2012-02-22 09:40:32 -05:00
|
|
|
end # class Tenant
|
|
|
|
end # class OpenStack
|
|
|
|
end # module Identity
|
|
|
|
end # module Fog
|