From e47c5eb9c4219ae15708e11a8776cdff7785b6da Mon Sep 17 00:00:00 2001 From: Nelvin Driz Date: Mon, 2 Apr 2012 15:26:45 +0800 Subject: [PATCH] [openstack|identity] Update Fog to Accomodate Tenant Deletion Workaround Workflow Signed-off-by: Nelvin Driz --- lib/fog/openstack/identity.rb | 1 + lib/fog/openstack/models/compute/tenant.rb | 2 +- lib/fog/openstack/models/identity/tenant.rb | 5 +++++ lib/fog/openstack/models/identity/users.rb | 5 ++++- .../requests/identity/delete_tenant.rb | 2 +- .../openstack/requests/identity/list_users.rb | 7 ++++--- .../identity/remove_user_from_tenant.rb | 20 +++++++++++++++++++ 7 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 lib/fog/openstack/requests/identity/remove_user_from_tenant.rb diff --git a/lib/fog/openstack/identity.rb b/lib/fog/openstack/identity.rb index fa08fbda6..62e1c55a2 100644 --- a/lib/fog/openstack/identity.rb +++ b/lib/fog/openstack/identity.rb @@ -38,6 +38,7 @@ module Fog request :get_user_by_id request :get_user_by_name request :add_user_to_tenant + request :remove_user_from_tenant request :list_endpoints_for_token request :list_roles_for_user_on_tenant diff --git a/lib/fog/openstack/models/compute/tenant.rb b/lib/fog/openstack/models/compute/tenant.rb index cc1c77e1b..6575e22a4 100644 --- a/lib/fog/openstack/models/compute/tenant.rb +++ b/lib/fog/openstack/models/compute/tenant.rb @@ -9,7 +9,7 @@ module Fog attribute :description attribute :enabled attribute :name - + def to_s self.name end diff --git a/lib/fog/openstack/models/identity/tenant.rb b/lib/fog/openstack/models/identity/tenant.rb index 1d1818de2..fe6d911e6 100644 --- a/lib/fog/openstack/models/identity/tenant.rb +++ b/lib/fog/openstack/models/identity/tenant.rb @@ -20,6 +20,11 @@ module Fog :user => user) end + def users + requires :id + connection.users(:tenant => self) + end + def destroy requires :id connection.delete_tenant(self.id) diff --git a/lib/fog/openstack/models/identity/users.rb b/lib/fog/openstack/models/identity/users.rb index c2518d81a..073899b83 100644 --- a/lib/fog/openstack/models/identity/users.rb +++ b/lib/fog/openstack/models/identity/users.rb @@ -7,8 +7,11 @@ module Fog class Users < Fog::Collection model Fog::Identity::OpenStack::User + attribute :tenant + def all - load(connection.list_users.body['users']) + tenant_id = tenant.id || nil + load(connection.list_users(tenant_id).body['users']) end def find_by_id(id) diff --git a/lib/fog/openstack/requests/identity/delete_tenant.rb b/lib/fog/openstack/requests/identity/delete_tenant.rb index d93356826..0f3ad5ee8 100644 --- a/lib/fog/openstack/requests/identity/delete_tenant.rb +++ b/lib/fog/openstack/requests/identity/delete_tenant.rb @@ -4,7 +4,7 @@ module Fog class Real def delete_tenant(id) request( - :expects => [200], + :expects => [200, 204], :method => 'DELETE', :path => "tenants/#{id}" ) diff --git a/lib/fog/openstack/requests/identity/list_users.rb b/lib/fog/openstack/requests/identity/list_users.rb index 03310846e..8060d075b 100644 --- a/lib/fog/openstack/requests/identity/list_users.rb +++ b/lib/fog/openstack/requests/identity/list_users.rb @@ -2,17 +2,18 @@ module Fog module Identity class OpenStack class Real - def list_users + def list_users(tenant_id = nil) + path = tenant_id ? "tenants/#{tenant_id}/users" : 'users' request( :expects => [200, 204], :method => 'GET', - :path => 'users' + :path => path ) end end # class Real class Mock - def list_users + def list_users(tenant_id = nil) response = Excon::Response.new response.status = 200 response.body = { 'users' => self.data[:users].values } diff --git a/lib/fog/openstack/requests/identity/remove_user_from_tenant.rb b/lib/fog/openstack/requests/identity/remove_user_from_tenant.rb new file mode 100644 index 000000000..bc816efde --- /dev/null +++ b/lib/fog/openstack/requests/identity/remove_user_from_tenant.rb @@ -0,0 +1,20 @@ +module Fog + module Identity + class OpenStack + class Real + def remove_user_from_tenant(tenant_id, user_id, role_id) + request( + :expects => [200, 204], + :method => 'DELETE', + :path => "/tenants/#{tenant_id}/users/#{user_id}/roles/OS-KSADM/#{role_id}" + ) + end + end # class Real + + class Mock + def remove_user_from_tenant(tenant_id, user_id, role_id) + end # def remove_user_from_tenant + end # class Mock + end # class OpenStack + end # module Identity +end