deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1235276 - in /deltacloud/trunk: client/lib/base_object.rb client/lib/deltacloud.rb server/lib/deltacloud/server.rb
Date Tue, 24 Jan 2012 14:42:47 GMT
Author: mfojtik
Date: Tue Jan 24 14:42:46 2012
New Revision: 1235276

URL: http://svn.apache.org/viewvc?rev=1235276&view=rev
Log:
Client: Added .providers method on driver objects. Client can now retrieve list of configured
API_PROVIDERS for active driver.

Signed-off-by: Michal fojtik <mfojtik@redhat.com>

Modified:
    deltacloud/trunk/client/lib/base_object.rb
    deltacloud/trunk/client/lib/deltacloud.rb
    deltacloud/trunk/server/lib/deltacloud/server.rb

Modified: deltacloud/trunk/client/lib/base_object.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/client/lib/base_object.rb?rev=1235276&r1=1235275&r2=1235276&view=diff
==============================================================================
--- deltacloud/trunk/client/lib/base_object.rb (original)
+++ deltacloud/trunk/client/lib/base_object.rb Tue Jan 24 14:42:46 2012
@@ -90,6 +90,18 @@ module DeltaCloud
           :values => value
         }
       end
+
+      def add_provider!(provider_id, entrypoints)
+        @providers ||= []
+        @providers << {
+          provider_id.intern => entrypoints.map { |e| { :kind => e[:kind], :url =>
e.text } }
+        }
+        @objects << {
+          :type => :collection,
+          :method_name => 'providers',
+          :values => @providers
+        }
+      end
       
 
       # This method define collection of text elements inside REST model
@@ -135,6 +147,12 @@ module DeltaCloud
         # First of all search throught array for method name
         m = search_for_method(method_name)
         if m.nil?
+          if method_name == :"valid_provider?"
+            return providers.any? { |p| p.keys.include? args.first.to_sym }
+          end
+          if method_name == :"valid_provider_url?"
+            return providers.map { |p| !p.find { |k, v| v.find { |u| u[:url] == args.first
} }.nil? }
+          end
           super
         else
           # Call appropriate handler for method

Modified: deltacloud/trunk/client/lib/deltacloud.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/client/lib/deltacloud.rb?rev=1235276&r1=1235275&r2=1235276&view=diff
==============================================================================
--- deltacloud/trunk/client/lib/deltacloud.rb (original)
+++ deltacloud/trunk/client/lib/deltacloud.rb Tue Jan 24 14:42:46 2012
@@ -239,6 +239,11 @@ module DeltaCloud
           obj.add_authentication!(attribute[:type], (attribute/'*')) && next
         end
 
+        #deal with providers
+        if(attribute.name == 'provider')
+          obj.add_provider!(attribute.attributes['id'].value, (attribute/'entrypoint')) &&
next
+        end
+
         # Deal with collections like public-addresses, private-addresses
         if (attribute/'./*').length > 0
           obj.add_collection!(attribute.name, (attribute/'*').collect { |value| value.text
}) && next
@@ -362,7 +367,7 @@ module DeltaCloud
       if conf[:method].eql?(:post)
         resource = RestClient::Resource.new(conf[:path], :open_timeout => conf[:open_timeout],
:timeout => conf[:timeout])
         resource.send(:post, conf[:form_data], default_headers.merge(extended_headers)) do
|response, request, block|
-          handle_backend_error(response) if [500, 502, 501].include? response.code
+          handle_backend_error(response) if [500, 502, 501, 401].include? response.code
           if response.respond_to?('body')
             yield response.body if block_given?
           else
@@ -372,7 +377,7 @@ module DeltaCloud
       else
         resource = RestClient::Resource.new(conf[:path], :open_timeout => conf[:open_timeout],
:timeout => conf[:timeout])
         resource.send(conf[:method], default_headers.merge(extended_headers)) do |response,
request, block|
-          handle_backend_error(response) if [500, 502, 501].include? response.code
+          handle_backend_error(response) if [500, 502, 501, 401].include? response.code
           if conf[:method].eql?(:get) and [301, 302, 307].include? response.code
             response.follow_redirection(request) do |response, request, block|
               if response.respond_to?('body')
@@ -397,6 +402,7 @@ module DeltaCloud
     class BackendError < StandardError
 
       def initialize(opts={})
+        opts[:message] = "Not authorized / Invalid credentials" if opts[:code] == 401
         super("#{opts[:code]} : #{opts[:message]}")
         set_backtrace(opts[:backtrace].split("\n").map { |l| l.strip }[0..10]) if opts[:backtrace]
       end

Modified: deltacloud/trunk/server/lib/deltacloud/server.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/deltacloud/server.rb?rev=1235276&r1=1235275&r2=1235276&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/deltacloud/server.rb (original)
+++ deltacloud/trunk/server/lib/deltacloud/server.rb Tue Jan 24 14:42:46 2012
@@ -163,7 +163,9 @@ EOS
     param :id,      :string
     control do
       @name = params[:id].to_sym
-      @providers = driver.providers(credentials) if driver.respond_to? :providers
+      if driver_symbol == @name
+        @providers = driver.providers(credentials)  if driver.respond_to? :providers
+      end
       @driver = settings.drivers[@name]
       return [404, "Driver #{@name} not found"] unless @driver
       respond_to do |format|



Mime
View raw message