deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francesco Vollero <fvoll...@redhat.com>
Subject [PATCH core] Improved valid_credentials? method on rhevm and vsphere driver
Date Tue, 07 Feb 2012 12:23:58 GMT

Signed-off-by: Francesco Vollero <fvollero@redhat.com>
---
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |   10 ++++++----
 .../deltacloud/drivers/vsphere/vsphere_driver.rb   |    9 ++++++---
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index 665e2fe..a66b9c6 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -208,13 +208,15 @@ class RHEVMDriver < Deltacloud::BaseDriver
   end
 
   def valid_credentials?(credentials)
-    retval = true
     begin
-      realms(credentials)
-    rescue
+      realms(credentials) && true
+    rescue RestClient::Unauthorized
       retval = false
+    rescue => e
+      safely do
+        raise e
+      end
     end
-    retval
   end
 
   private
diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index a2a5249..51b6648 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -370,10 +370,13 @@ module Deltacloud::Drivers::VSphere
 
     def valid_credentials?(credentials)
       begin
-        RbVmomi::VIM.connect(:host => host_endpoint, :user => credentials.user, :password
=> credentials.password, :insecure => true)
-        return true
-      rescue
+        RbVmomi::VIM.connect(:host => host_endpoint, :user => credentials.user, :password
=> credentials.password, :insecure => true) && true
+      rescue RbVmomi::Fault:InvalidLogin
         return false
+      rescue => e
+        safely do
+          raise e
+        end
       end
     end
 
-- 
1.7.7.6


Mime
View raw message