diff --git a/lib/fog/openstack/models/identity/users.rb b/lib/fog/openstack/models/identity/users.rb index 209de7620..d5a96ca6c 100644 --- a/lib/fog/openstack/models/identity/users.rb +++ b/lib/fog/openstack/models/identity/users.rb @@ -22,6 +22,15 @@ module Fog ) end + def find_by_name(name) + self.find {|user| user.name == name} || + Fog::Identity::OpenStack::User.new( + service.get_user_by_name(name).body['user'].merge( + 'service' => service + ) + ) + end + def destroy(id) user = self.find_by_id(id) user.destroy diff --git a/tests/openstack/models/identity/users_tests.rb b/tests/openstack/models/identity/users_tests.rb index 30d30ebc1..a51fcecf4 100644 --- a/tests/openstack/models/identity/users_tests.rb +++ b/tests/openstack/models/identity/users_tests.rb @@ -14,6 +14,11 @@ Shindo.tests("Fog::Identity[:openstack] | users", ['openstack']) do user.id == @instance.id end + tests('#find_by_name').succeeds do + user = Fog::Identity[:openstack].users.find_by_name(@instance.name) + user.name == @instance.name + end + tests('#destroy').succeeds do Fog::Identity[:openstack].users.destroy(@instance.id) end @@ -26,6 +31,10 @@ Shindo.tests("Fog::Identity[:openstack] | users", ['openstack']) do Fog::Identity[:openstack].users.find_by_id('fake') end + tests('#find_by_name').raises(Fog::Identity::OpenStack::NotFound) do + Fog::Identity[:openstack].users.find_by_name('fake') + end + tests('#destroy').raises(Fog::Identity::OpenStack::NotFound) do Fog::Identity[:openstack].users.destroy('fake') end