deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [2/2] git commit: Core: Replaced 'check_capability' method with Sinatra::Base 'set' method
Date Tue, 10 Jul 2012 12:49:01 GMT
Core: Replaced 'check_capability' method with Sinatra::Base 'set' method

The 'check_capability' method set a class variable in Sinatra::Rabbit
to a lambda that was evaluated when server was starting.
However this class variable was not replaced when client switched the
driver using HTTP headers.

This patch will replace it with 'set' and now the lambda is evaluated
for every request in Sinatra::Rabbit (sinatra-rabbit 1.0.7)


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/255bb89e
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/255bb89e
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/255bb89e

Branch: refs/heads/master
Commit: 255bb89e0453601c4af48faf996171a6fd2cb58a
Parents: 311baf1
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Tue Jul 10 14:31:23 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Tue Jul 10 14:31:23 2012 +0200

----------------------------------------------------------------------
 server/lib/deltacloud/collections/addresses.rb     |    2 +-
 server/lib/deltacloud/collections/buckets.rb       |    3 ++-
 server/lib/deltacloud/collections/firewalls.rb     |    3 ++-
 .../deltacloud/collections/hardware_profiles.rb    |    2 +-
 server/lib/deltacloud/collections/images.rb        |    2 +-
 .../lib/deltacloud/collections/instance_states.rb  |    2 +-
 server/lib/deltacloud/collections/instances.rb     |    2 +-
 server/lib/deltacloud/collections/keys.rb          |    2 +-
 .../lib/deltacloud/collections/load_balancers.rb   |    3 ++-
 server/lib/deltacloud/collections/metrics.rb       |    3 ++-
 server/lib/deltacloud/collections/realms.rb        |    2 +-
 .../deltacloud/collections/storage_snapshots.rb    |    3 ++-
 .../lib/deltacloud/collections/storage_volumes.rb  |    2 +-
 server/lib/deltacloud/helpers.rb                   |    4 ----
 server/lib/deltacloud/server.rb                    |    4 ++++
 server/lib/sinatra/rack_driver_select.rb           |    4 ++--
 16 files changed, 24 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/addresses.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/addresses.rb b/server/lib/deltacloud/collections/addresses.rb
index 95c4ae5..c43f478 100644
--- a/server/lib/deltacloud/collections/addresses.rb
+++ b/server/lib/deltacloud/collections/addresses.rb
@@ -16,7 +16,7 @@
 module Deltacloud::Collections
   class Addresses < Base
 
-    check_capability :for => lambda { |m| driver.respond_to? m }
+    set :capability, lambda { |m| driver.respond_to? m }
 
     get route_for('/addresses/:id/associate') do
       @address = driver.address(credentials, params )

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/buckets.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/buckets.rb b/server/lib/deltacloud/collections/buckets.rb
index 28b6d5a..77a431c 100644
--- a/server/lib/deltacloud/collections/buckets.rb
+++ b/server/lib/deltacloud/collections/buckets.rb
@@ -18,7 +18,8 @@ module Deltacloud::Collections
 
     include Deltacloud::Features
 
-    check_capability :for => lambda { |m| driver.respond_to? m }
+    set :capability, lambda { |m| driver.respond_to? m }
+
     check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
 
     new_route_for :buckets

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/firewalls.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/firewalls.rb b/server/lib/deltacloud/collections/firewalls.rb
index 0a4242a..603a62e 100644
--- a/server/lib/deltacloud/collections/firewalls.rb
+++ b/server/lib/deltacloud/collections/firewalls.rb
@@ -16,7 +16,8 @@
 module Deltacloud::Collections
   class Firewalls < Base
 
-    check_capability :for => lambda { |m| driver.respond_to? m }
+    set :capability, lambda { |m| driver.respond_to? m }
+
     check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
 
     get route_for('/firewalls/:id/new_rule') do

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/hardware_profiles.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/hardware_profiles.rb b/server/lib/deltacloud/collections/hardware_profiles.rb
index 5c72aff..d5bf400 100644
--- a/server/lib/deltacloud/collections/hardware_profiles.rb
+++ b/server/lib/deltacloud/collections/hardware_profiles.rb
@@ -16,7 +16,7 @@
 module Deltacloud::Collections
   class HardwareProfiles < Base
 
-    check_capability :for => lambda { |m| !driver.class.send(m).empty? }
+    set :capability, lambda { |m| !driver.class.send(m).empty? }
 
     collection :hardware_profiles do
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/images.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/images.rb b/server/lib/deltacloud/collections/images.rb
index 0edd7c0..2bb836e 100644
--- a/server/lib/deltacloud/collections/images.rb
+++ b/server/lib/deltacloud/collections/images.rb
@@ -18,8 +18,8 @@ module Deltacloud::Collections
 
     include Deltacloud::Features
 
-    check_capability :for => lambda { |m| driver.respond_to? m }
     check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
+    set :capability, lambda { |m| driver.respond_to? m }
 
     new_route_for :images do
       @instance = Instance.new( :id => params[:instance_id] )

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/instance_states.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/instance_states.rb b/server/lib/deltacloud/collections/instance_states.rb
index 6122cca..74328a8 100644
--- a/server/lib/deltacloud/collections/instance_states.rb
+++ b/server/lib/deltacloud/collections/instance_states.rb
@@ -16,7 +16,7 @@
 module Deltacloud::Collections
   class InstanceStates < Base
 
-    check_capability :for => lambda { |m| !driver.send(m).nil? }
+    set :capability, lambda { |m| !driver.send(m).nil? }
 
     collection :instance_states do
       operation :index, :with_capability => :instance_state_machine do

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/instances.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/instances.rb b/server/lib/deltacloud/collections/instances.rb
index 0faea0c..742b16a 100644
--- a/server/lib/deltacloud/collections/instances.rb
+++ b/server/lib/deltacloud/collections/instances.rb
@@ -18,7 +18,7 @@ module Deltacloud::Collections
 
     include Deltacloud::Features
 
-    check_capability :for => lambda { |m| driver.respond_to? m }
+    set :capability, lambda { |m| driver.respond_to? m }
     check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
 
     new_route_for(:instances) do

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/keys.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/keys.rb b/server/lib/deltacloud/collections/keys.rb
index 6d0ef03..c59eb15 100644
--- a/server/lib/deltacloud/collections/keys.rb
+++ b/server/lib/deltacloud/collections/keys.rb
@@ -18,7 +18,7 @@ module Deltacloud::Collections
 
     include Deltacloud::Features
 
-    check_capability :for => lambda { |m| driver.respond_to? m }
+    set :capability, lambda { |m| driver.respond_to? m }
     check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
 
     get route_for('/keys/new') do

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/load_balancers.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/load_balancers.rb b/server/lib/deltacloud/collections/load_balancers.rb
index 7d6392b..2a10311 100644
--- a/server/lib/deltacloud/collections/load_balancers.rb
+++ b/server/lib/deltacloud/collections/load_balancers.rb
@@ -15,7 +15,8 @@
 
 module Deltacloud::Collections
   class LoadBalancers < Base
-    check_capability :for => lambda { |m| driver.has_capability? m }
+
+    set :capability, lambda { |m| driver.respond_to? m }
 
     new_route_for :load_balancers do
       @realms = driver.realms(credentials)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/metrics.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/metrics.rb b/server/lib/deltacloud/collections/metrics.rb
index d13ba38..45b0ee5 100644
--- a/server/lib/deltacloud/collections/metrics.rb
+++ b/server/lib/deltacloud/collections/metrics.rb
@@ -15,7 +15,8 @@
 
 module Deltacloud::Collections
   class Metrics < Base
-    check_capability :for => lambda { |m| driver.respond_to? m }
+
+    set :capability, lambda { |m| driver.respond_to? m }
 
     collection :metrics do
       description 'Metrics provide monitoring for the cloud resources'

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/realms.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/realms.rb b/server/lib/deltacloud/collections/realms.rb
index 609a1dd..619e31a 100644
--- a/server/lib/deltacloud/collections/realms.rb
+++ b/server/lib/deltacloud/collections/realms.rb
@@ -15,7 +15,7 @@
 
 module Deltacloud::Collections
   class Realms < Base
-    check_capability :for => lambda { |m| driver.respond_to? m }
+    set :capability, lambda { |m| driver.respond_to? m }
 
     collection :realms do
       description "Within a cloud provider a realm represents a boundary containing resources"

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/storage_snapshots.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/storage_snapshots.rb b/server/lib/deltacloud/collections/storage_snapshots.rb
index b468614..5d5ac53 100644
--- a/server/lib/deltacloud/collections/storage_snapshots.rb
+++ b/server/lib/deltacloud/collections/storage_snapshots.rb
@@ -15,7 +15,8 @@
 
 module Deltacloud::Collections
   class StorageSnapshots < Base
-    check_capability :for => lambda { |m| driver.respond_to? m }
+
+    set :capability, lambda { |m| driver.respond_to? m }
     check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
 
     new_route_for(:storage_snapshots)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/collections/storage_volumes.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/storage_volumes.rb b/server/lib/deltacloud/collections/storage_volumes.rb
index 9cdcd66..147c4c1 100644
--- a/server/lib/deltacloud/collections/storage_volumes.rb
+++ b/server/lib/deltacloud/collections/storage_volumes.rb
@@ -16,7 +16,7 @@
 module Deltacloud::Collections
   class StorageVolumes < Base
 
-    check_capability :for => lambda { |m| driver.respond_to? m }
+    set :capability, lambda { |m| driver.respond_to? m }
     check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
 
     new_route_for(:storage_volumes)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/helpers.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers.rb b/server/lib/deltacloud/helpers.rb
index 77d201e..0c66103 100644
--- a/server/lib/deltacloud/helpers.rb
+++ b/server/lib/deltacloud/helpers.rb
@@ -79,10 +79,6 @@ module Deltacloud::Collections
       end
     end
 
-    def self.check_capability(opts={})
-      Sinatra::Rabbit.set :check_capability, opts[:for]
-    end
-
     def self.check_features(opts={})
       Sinatra::Rabbit.set :check_features, opts[:for]
     end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/deltacloud/server.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/server.rb b/server/lib/deltacloud/server.rb
index 9f00ca1..10af202 100644
--- a/server/lib/deltacloud/server.rb
+++ b/server/lib/deltacloud/server.rb
@@ -55,6 +55,10 @@ module Deltacloud
       end
     end
 
+    options Deltacloud.config[:deltacloud].root_url + '/?' do
+      headers 'Allow' => Deltacloud.collections.select { |c| driver.respond_to?(c.collection_name)
}.map { |c| c.collection_name }.join(',')
+    end
+
     post Deltacloud.config[:deltacloud].root_url + '/?' do
       param_driver, param_provider = params["driver"], params["provider"]
       if param_driver

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/255bb89e/server/lib/sinatra/rack_driver_select.rb
----------------------------------------------------------------------
diff --git a/server/lib/sinatra/rack_driver_select.rb b/server/lib/sinatra/rack_driver_select.rb
index 141f399..6bba3e0 100644
--- a/server/lib/sinatra/rack_driver_select.rb
+++ b/server/lib/sinatra/rack_driver_select.rb
@@ -31,10 +31,10 @@ module Rack
       original_settings = { }
       req = Rack::Request.new(env)
       if req.params['api'] and req.params['api']['driver']
-	env['HTTP_X_DELTACLOUD_DRIVER'] = req.params['api']['driver']
+        env['HTTP_X_DELTACLOUD_DRIVER'] = req.params['api']['driver']
       end
       if req.params['api'] and req.params['api']['provider']
-	env['HTTP_X_DELTACLOUD_PROVIDER'] = req.params['api']['provider']
+        env['HTTP_X_DELTACLOUD_PROVIDER'] = req.params['api']['provider']
       end
       HEADER_TO_ENV_MAP.each do |header, name|
         original_settings[name] = Thread.current[name]


Mime
View raw message