You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2012/01/07 01:33:05 UTC
[PATCH 1/2] Do not throw an error on HTML request to /api for non-EC2 drivers
From: David Lutterkort <lu...@redhat.com>
The generation of the provider selection was EC2 specific, and causes an
internal error for drivers other than the EC2 driver.
Cleaned this up by adding a 'configured_providers' method to drivers, since
they ultimately are the ones who knows how available providers are listed
in their YAML config files.
Fixes https://issues.apache.org/jira/browse/DTACLOUD-124
Signed-off-by: David Lutterkort <lu...@redhat.com>
---
server/lib/deltacloud/base_driver/base_driver.rb | 5 +++++
server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 4 ++++
server/lib/deltacloud/server.rb | 3 +--
server/views/api/show.html.haml | 3 +--
4 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb
index 5620a30..dcc3b9a 100644
--- a/server/lib/deltacloud/base_driver/base_driver.rb
+++ b/server/lib/deltacloud/base_driver/base_driver.rb
@@ -235,6 +235,11 @@ module Deltacloud
Thread.current[:provider] || ENV['API_PROVIDER']
end
+ # Return an array of the providers statically configured
+ # in the driver's YAML file
+ def configured_providers
+ []
+ end
end
end
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index a6e2380..f899ea1 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -701,6 +701,10 @@ module Deltacloud
:url=>"#{ENV['API_HOST']}:#{ENV['API_PORT']}#{settings.root_url}\;provider=#{r}" }) }
end
+ def configured_providers
+ Deltacloud::Drivers::driver_config[:ec2][:entrypoints]["ec2"].keys
+ end
+
def valid_credentials?(credentials)
retval = true
begin
diff --git a/server/lib/deltacloud/server.rb b/server/lib/deltacloud/server.rb
index aa3e4fe..bc9ef76 100644
--- a/server/lib/deltacloud/server.rb
+++ b/server/lib/deltacloud/server.rb
@@ -110,8 +110,7 @@ get "#{settings.root_url}\/?" do
return [401, 'Authentication failed'] unless driver.valid_credentials?(credentials)
end
@collections = [:drivers] + driver.supported_collections
- #could use driver.providers - but that will require credentials for /api ...
- @providers = Deltacloud::Drivers::driver_config["#{driver.name}".to_sym][:entrypoints]["#{driver.name}"].keys unless driver_provider(Deltacloud::Drivers::driver_config["#{driver.name}".to_sym]).empty?
+ @providers = driver.configured_providers
respond_to do |format|
format.xml { haml :"api/show" }
format.json do
diff --git a/server/views/api/show.html.haml b/server/views/api/show.html.haml
index 7bd5c16..0d8a0fc 100644
--- a/server/views/api/show.html.haml
+++ b/server/views/api/show.html.haml
@@ -6,7 +6,7 @@
- @collections.sort_by { |k| k.to_s }.each do |key|
%li= link_to key.to_s.gsub('_', ' ').titlecase, api_url_for(key), :'data-icon' => "arrow-r", :'data-ajax' => false
-- if @providers
+- if @providers.size > 1
%div{ :'data-role' => :footer, :'data-theme' => 'a'}
%form{ :action => settings.root_url, :method => :post, :'data-ajax' => 'false'}
%div{ :'data-role' => :footer, :'data-theme' => 'a' , :class => 'middle-dialog'}
@@ -16,4 +16,3 @@
- @providers.each do |provider|
%option{ :value => provider } #{provider}
%button{ :type => :submit} Change Provider
-
--
1.7.7.5