deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "marios@redhat.com" <mandr...@redhat.com>
Subject Re: [PATCH core] Core: Replaced 'check_capability' method with Sinatra::Base 'set' method
Date Tue, 10 Jul 2012 12:45:02 GMT
side note - this worked for me even with sinatra-rabbit 1.0.6... not
sure if that's expected (noticed your instructions)

On 10/07/12 15:43, marios@redhat.com wrote:
> ACK - solves issue reported in
> https://issues.apache.org/jira/browse/DTACLOUD-254
> 
> On 10/07/12 15:39, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mfojtik@redhat.com>
>>
>> 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)
>>
>> Signed-off-by: Michal fojtik <mfojtik@redhat.com>
>> ---
>>  server/lib/deltacloud/collections/addresses.rb         |    2 +-
>>  server/lib/deltacloud/collections/buckets.rb           |    3 ++-
>>  server/lib/deltacloud/collections/firewalls.rb         |    3 ++-
>>  server/lib/deltacloud/collections/hardware_profiles.rb |    2 +-
>>  server/lib/deltacloud/collections/images.rb            |    2 +-
>>  server/lib/deltacloud/collections/instance_states.rb   |    2 +-
>>  server/lib/deltacloud/collections/instances.rb         |    2 +-
>>  server/lib/deltacloud/collections/keys.rb              |    2 +-
>>  server/lib/deltacloud/collections/load_balancers.rb    |    3 ++-
>>  server/lib/deltacloud/collections/metrics.rb           |    3 ++-
>>  server/lib/deltacloud/collections/realms.rb            |    2 +-
>>  server/lib/deltacloud/collections/storage_snapshots.rb |    3 ++-
>>  server/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(-)
>>
>> 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 )
>> 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
>> 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
>> 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
>>  
>> 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] )
>> 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
>> 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
>> 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
>> 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)
>> 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'
>> 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"
>> 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)
>> 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)
>> 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
>> 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
>> 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