deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Fojtik <mfoj...@redhat.com>
Subject Re: [PATCH] Deltacloud - rework 'valid_credentials' - moved to base_driver where possible
Date Tue, 26 Feb 2013 17:19:20 GMT
On 02/26, marios@redhat.com wrote:

ACK.


> From: marios <marios@redhat.com>
> 
> Drivers can override this where needed - like e.g. in ec2 driver where just
> creating a handle to the aws service (via the appoxy/aws rubygem) isn't enough
> to determine that credentials are not valid.
> 
> Signed-off-by: marios <marios@redhat.com>
> ---
>  .../lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb   |  9 ---------
>  server/lib/deltacloud/drivers/base_driver.rb                 | 12 ++++++++++++
>  server/lib/deltacloud/drivers/mock/mock_driver.rb            | 10 +---------
>  server/lib/deltacloud/drivers/openstack/openstack_driver.rb  |  9 ---------
>  server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb  |  9 ---------
>  server/lib/deltacloud/drivers/terremark/terremark_driver.rb  |  8 --------
>  server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb      | 12 ------------
>  7 files changed, 13 insertions(+), 56 deletions(-)
> 
> diff --git a/server/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb b/server/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb
> index 4a24760..be919e8 100644
> --- a/server/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb
> +++ b/server/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb
> @@ -61,15 +61,6 @@ class ArubacloudDriver < Deltacloud::BaseDriver
>      architecture ['x86_64', 'i386']
>    end
>  
> -  def valid_credentials?(credentials)
> -    begin
> -      new_client(credentials)
> -    rescue
> -      return false
> -    end
> -    true
> -  end
> -
>    def realms(credentials, opts=nil)
>      client = new_client(credentials)
>      safely do
> diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
> index 1bb80d5..e346e7c 100644
> --- a/server/lib/deltacloud/drivers/base_driver.rb
> +++ b/server/lib/deltacloud/drivers/base_driver.rb
> @@ -286,6 +286,18 @@ module Deltacloud
>      def configured_providers
>        []
>      end
> +
> +    def valid_credentials?(credentials)
> +      begin
> +        new_client(credentials)
> +      rescue  Deltacloud::Exceptions::AuthenticationFailure
> +        return false
> +      rescue => e
> +        safely { raise e }
> +      end
> +      true
> +    end
> +
>    end
>  
>  end
> diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
> index fe930c2..f4e86c1 100644
> --- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
> +++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
> @@ -578,15 +578,6 @@ module Deltacloud::Drivers::Mock
>        metric
>      end
>  
> -    def valid_credentials?(credentials)
> -      begin
> -        check_credentials(credentials)
> -        return true
> -      rescue
> -      end
> -      return false
> -    end
> -
>      private
>  
>      def check_credentials(credentials)
> @@ -596,6 +587,7 @@ module Deltacloud::Drivers::Mock
>          end
>        end
>      end
> +    alias :new_client :check_credentials
>  
>      #Mock allocation of 'new' address
>      #There is a synchronization problem (but it's the mock driver,
> diff --git a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
> index 356d835..5b420bb 100644
> --- a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
> +++ b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
> @@ -237,15 +237,6 @@ module Deltacloud
>  
>          alias_method :stop_instance, :destroy_instance
>  
> -        def valid_credentials?(credentials)
> -          begin
> -            new_client(credentials)
> -          rescue
> -            return false
> -          end
> -          true
> -        end
> -
>          def buckets(credentials, opts={})
>            os = new_client(credentials, "object-store")
>            buckets = []
> diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
> index 8082767..24ae55d 100644
> --- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
> +++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
> @@ -181,15 +181,6 @@ class RackspaceDriver < Deltacloud::BaseDriver
>      insts
>    end
>  
> -  def valid_credentials?(credentials)
> -    begin
> -      new_client(credentials)
> -    rescue
> -      return false
> -    end
> -    true
> -  end
> -
>    define_instance_states do
>      start.to( :pending )          .on( :create )
>      pending.to( :running )        .automatically
> diff --git a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
> index 1d3f4ce..30d092b 100644
> --- a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
> +++ b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
> @@ -197,14 +197,6 @@ def destroy_instance(credentials, id)
>    end
>  end
>  
> -def valid_credentials?(credentials)
> -  begin
> -    new_client(credentials)
> -  rescue
> -    return false
> -  end
> -  true
> -end
>  
>  #--
>  # PRIVATE METHODS:
> diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
> index 272f471..0f9978e 100644
> --- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
> +++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
> @@ -390,18 +390,6 @@ module Deltacloud::Drivers::Vsphere
>  
>      end
>  
> -    def valid_credentials?(credentials)
> -      begin
> -        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
> -
>      #######
>      private
>      #######
> -- 
> 1.7.11.7
> 

-- 
Michal Fojtik <mfojtik@redhat.com>
Deltacloud API, CloudForms

Mime
View raw message