diff --git a/lib/fog/openstack/identity.rb b/lib/fog/openstack/identity.rb index daec8f440..f8b96e949 100644 --- a/lib/fog/openstack/identity.rb +++ b/lib/fog/openstack/identity.rb @@ -37,6 +37,7 @@ module Fog request :delete_user request :get_user_by_id request :get_user_by_name + request :add_user_to_tenant request :list_endpoints_for_token request :list_roles_for_user_on_tenant diff --git a/lib/fog/openstack/models/identity/tenant.rb b/lib/fog/openstack/models/identity/tenant.rb index c71c3f962..714e82bb3 100644 --- a/lib/fog/openstack/models/identity/tenant.rb +++ b/lib/fog/openstack/models/identity/tenant.rb @@ -43,6 +43,10 @@ module Fog connection.create_tenant(attributes).body['tenant']) self end + + def add_user(user_id, role_id) + connection.add_user_to_tenant(self.id, user_id, role_id) + end end # class Tenant end # class OpenStack end # module Identity diff --git a/lib/fog/openstack/requests/identity/add_user_to_tenant.rb b/lib/fog/openstack/requests/identity/add_user_to_tenant.rb new file mode 100644 index 000000000..353bca328 --- /dev/null +++ b/lib/fog/openstack/requests/identity/add_user_to_tenant.rb @@ -0,0 +1,29 @@ +module Fog + module Identity + class OpenStack + class Real + def add_user_to_tenant(tenant_id, user_id, role_id) + request( + :expects => 200, + :method => 'PUT', + :path => "/tenants/#{tenant_id}/users/#{user_id}/roles/OS-KSADM/#{role_id}" + ) + end + end # class Real + + class Mock + def add_user_to_tenant(tenant_id, user_id, role_id) + response = Excon::Response.new + response.status = 200 + response.body = { + 'role' => { + 'id' => '503df61a99d6461fb247cdb6a3f3a4dd', + 'name' => 'admin' + } + } + response + end # def add_user_to_tenant + end # class Mock + end # class OpenStack + end # module Identity +end