incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r1087443 - in /incubator/deltacloud/trunk/server: ./ lib/deltacloud/helpers/ tests/drivers/mock/ views/api/ views/drivers/
Date Thu, 31 Mar 2011 21:20:32 GMT
Author: lutter
Date: Thu Mar 31 21:20:31 2011
New Revision: 1087443

URL: http://svn.apache.org/viewvc?rev=1087443&view=rev
Log:
drivers: new collection

Added:
    incubator/deltacloud/trunk/server/views/drivers/
    incubator/deltacloud/trunk/server/views/drivers/index.html.haml
      - copied, changed from r1087441, incubator/deltacloud/trunk/server/views/api/drivers.html.haml
    incubator/deltacloud/trunk/server/views/drivers/index.xml.haml
    incubator/deltacloud/trunk/server/views/drivers/show.html.haml
    incubator/deltacloud/trunk/server/views/drivers/show.xml.haml
Removed:
    incubator/deltacloud/trunk/server/views/api/drivers.html.haml
    incubator/deltacloud/trunk/server/views/api/drivers.xml.haml
Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb
    incubator/deltacloud/trunk/server/server.rb
    incubator/deltacloud/trunk/server/tests/drivers/mock/api_test.rb
    incubator/deltacloud/trunk/server/views/api/show.html.haml

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb?rev=1087443&r1=1087442&r2=1087443&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb Thu Mar
31 21:20:31 2011
@@ -204,4 +204,18 @@ module ApplicationHelper
     "#{text[0..(length/2)]}#{end_string}"
   end
 
+  # Reverse the entrypoints hash for a driver from drivers.yaml; note that
+  # +d+ is a hash, not an actual driver object
+  def driver_provider(d)
+    result = {}
+    if d[:entrypoints]
+      d[:entrypoints].each do |kind, details|
+        details.each do |prov, url|
+          result[prov] ||= {}
+          result[prov][kind] = url
+        end
+      end
+    end
+    result
+  end
 end

Modified: incubator/deltacloud/trunk/server/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/server.rb?rev=1087443&r1=1087442&r2=1087443&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/server.rb (original)
+++ incubator/deltacloud/trunk/server/server.rb Thu Mar 31 21:20:31 2011
@@ -84,17 +84,11 @@ Sinatra::Application.register Sinatra::R
 # Redirect to /api
 get '/' do redirect url_for('/api'), 301; end
 
-get '/api/drivers\/?' do
-  respond_to do |format|
-    format.xml { haml :"api/drivers" }
-    format.html { haml :"api/drivers" }
-  end
-end
-
 get '/api\/?' do
   if params[:force_auth]
     return [401, 'Authentication failed'] unless driver.valid_credentials?(credentials)
   end
+  @collections = [:drivers] + driver.supported_collections
   respond_to do |format|
     format.xml { haml :"api/show" }
     format.json do
@@ -111,6 +105,41 @@ end
 
 # Rabbit DSL
 
+collection :drivers do
+  global!
+
+  description <<EOS
+List all the drivers supported by this server.
+EOS
+
+  operation :index do
+    description "List all drivers"
+    control do
+      @drivers = settings.drivers
+      respond_to do |format|
+        format.xml { haml :"drivers/index" }
+        format.json { @drivers.to_json }
+        format.html { haml :"drivers/index" }
+      end
+    end
+  end
+
+  operation :show do
+    description "Show details for a driver"
+    param :id,      :string
+    control do
+      @name = params[:id].to_sym
+      @driver = settings.drivers[@name]
+      return [404, "Driver #{@name} not found"] unless @driver
+      respond_to do |format|
+        format.xml { haml :"drivers/show" }
+        format.json { @driver.to_json }
+        format.html { haml :"drivers/show" }
+      end
+    end
+  end
+end
+
 collection :realms do
   description <<END
   Within a cloud provider a realm represents a boundary containing resources.

Modified: incubator/deltacloud/trunk/server/tests/drivers/mock/api_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/drivers/mock/api_test.rb?rev=1087443&r1=1087442&r2=1087443&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/tests/drivers/mock/api_test.rb (original)
+++ incubator/deltacloud/trunk/server/tests/drivers/mock/api_test.rb Thu Mar 31 21:20:31 2011
@@ -76,17 +76,21 @@ module DeltacloudUnitTest
     def test_it_expose_available_drivers
       do_xml_request '/api/drivers'
       last_response.status.should == 200
-      (last_xml_response/"api/drivers").length.should > 0
-      (last_xml_response/'api/drivers/driver').length.should > 0
+      (last_xml_response/"drivers").length.should > 0
+      (last_xml_response/'drivers/driver').length.should > 0
+      (last_xml_response/"drivers/driver[@id = 'mock']").length.should == 1
     end
 
     def test_it_expose_ec2_driver_entrypoints
       do_xml_request '/api/drivers'
       last_response.status.should == 200
-      (last_xml_response/"api/drivers").length.should > 0
-      (last_xml_response/'api/drivers/driver[@id=ec2]/entrypoints').length.should > 0
-      (last_xml_response/'api/drivers/driver[@id=ec2]/entrypoints/entrypoint').first[:id].should_not
== nil
-      (last_xml_response/'api/drivers/driver[@id=ec2]/entrypoints/entrypoint').first.text.should_not
== ""
+      ec2 = (last_xml_response/'drivers/driver[@id=ec2]').first
+      (ec2/"provider").length.should > 0
+      (ec2/"provider[@id = 'eu-west-1']").length.should == 1
+      do_xml_request ec2[:href]
+      eu_west = (last_xml_response/"provider[@id = 'eu-west-1']").first
+      (eu_west/"entrypoint").length.should > 0
+      (eu_west/"entrypoint[@kind = 'ec2']").length.should == 1
     end
 
     def test_it_supports_matrix_params

Modified: incubator/deltacloud/trunk/server/views/api/show.html.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/api/show.html.haml?rev=1087443&r1=1087442&r2=1087443&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/views/api/show.html.haml (original)
+++ incubator/deltacloud/trunk/server/views/api/show.html.haml Thu Mar 31 21:20:31 2011
@@ -2,7 +2,7 @@
   Deltacloud API #{settings.version}
 
 %ul
-  - driver.supported_collections.sort_by { |k| k.to_s }.each do |key|
+  - @collections.sort_by { |k| k.to_s }.each do |key|
     %li
       = link_to key.to_s.gsub('_', ' ').titlecase, url_for("/api/#{key}")
       %dl

Copied: incubator/deltacloud/trunk/server/views/drivers/index.html.haml (from r1087441, incubator/deltacloud/trunk/server/views/api/drivers.html.haml)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/drivers/index.html.haml?p2=incubator/deltacloud/trunk/server/views/drivers/index.html.haml&p1=incubator/deltacloud/trunk/server/views/api/drivers.html.haml&r1=1087441&r2=1087443&rev=1087443&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/views/api/drivers.html.haml (original)
+++ incubator/deltacloud/trunk/server/views/drivers/index.html.haml Thu Mar 31 21:20:31 2011
@@ -7,8 +7,9 @@
       %th ID
       %th Name
   %tbody
-    - settings.drivers.each do |id, details|
+    - @drivers.each do |id, details|
       %tr
         %td{ :width => '20%' }
-          %tt= id
+          %tt
+            %a{ :href => driver_url(id) }= id
         %td= details[:name]

Added: incubator/deltacloud/trunk/server/views/drivers/index.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/drivers/index.xml.haml?rev=1087443&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/drivers/index.xml.haml (added)
+++ incubator/deltacloud/trunk/server/views/drivers/index.xml.haml Thu Mar 31 21:20:31 2011
@@ -0,0 +1,7 @@
+%drivers
+  - @drivers.each do |id, details|
+    %driver{ :href => driver_url(id), :id => id }
+      %name<
+        =details[:name]
+      - driver_provider(details).keys.each do |prov|
+        %provider{ :id => prov }

Added: incubator/deltacloud/trunk/server/views/drivers/show.html.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/drivers/show.html.haml?rev=1087443&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/drivers/show.html.haml (added)
+++ incubator/deltacloud/trunk/server/views/drivers/show.html.haml Thu Mar 31 21:20:31 2011
@@ -0,0 +1,20 @@
+%h1
+  Details for driver #{@name}
+
+%dl
+  %di
+    %dt ID
+    %dd= @name
+  %di
+    %dt Name
+    %dd= @driver[:name]
+  %di
+    %dt Provider
+    %dd
+      - providers = driver_provider(@driver).keys.collect { |k| k.to_s }.sort
+      - if providers.empty?
+        None
+      - else
+        %ol
+          - providers.each do |k|
+            %li= k

Added: incubator/deltacloud/trunk/server/views/drivers/show.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/drivers/show.xml.haml?rev=1087443&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/drivers/show.xml.haml (added)
+++ incubator/deltacloud/trunk/server/views/drivers/show.xml.haml Thu Mar 31 21:20:31 2011
@@ -0,0 +1,7 @@
+%driver{ :href => driver_url(@name), :id => @name }
+  %name<
+    = @driver[:name]
+  - driver_provider(@driver).each do |prov, details|
+    %provider{ :id => prov }
+      - details.each do |kind, url|
+        %entrypoint{ :kind => kind }<=cdata(url)



Mime
View raw message