You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2011/02/21 16:46:00 UTC

svn commit: r1073029 - in /incubator/deltacloud/trunk/server: ./ config/ lib/ lib/deltacloud/drivers/ec2/ tests/drivers/mock/ views/api/

Author: mfojtik
Date: Mon Feb 21 15:46:00 2011
New Revision: 1073029

URL: http://svn.apache.org/viewvc?rev=1073029&view=rev
Log:
Advertising supported drivers and their entrypoints Advertising of credentials needed for backend authentication Drivers Hash moved to YAML configuration file

Added:
    incubator/deltacloud/trunk/server/config/drivers.yaml
Removed:
    incubator/deltacloud/trunk/server/config/rhevm_config.yml.EXAMPLE
Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
    incubator/deltacloud/trunk/server/lib/drivers.rb
    incubator/deltacloud/trunk/server/server.rb
    incubator/deltacloud/trunk/server/tests/drivers/mock/api_test.rb
    incubator/deltacloud/trunk/server/views/api/drivers.html.haml
    incubator/deltacloud/trunk/server/views/api/drivers.xml.haml

Added: incubator/deltacloud/trunk/server/config/drivers.yaml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/config/drivers.yaml?rev=1073029&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/config/drivers.yaml (added)
+++ incubator/deltacloud/trunk/server/config/drivers.yaml Mon Feb 21 15:46:00 2011
@@ -0,0 +1,50 @@
+--- 
+:gogrid: 
+  :username: API key
+  :password: GoGrid Account password
+  :name: Gogrid
+:mock: 
+  :username: Username
+  :password: Password
+  :name: Mock
+:rhevm: 
+  :username: RHEV-M Username (with domain)
+  :password: RHEV-M Password
+  :name: RHEVM
+:rimuhosting: 
+  :username: API key
+  :password: API password
+  :name: RimuHosting
+:opennebula: 
+  :class: OpennebulaDriver
+  :name: Opennebula
+:sbc: 
+  :name: SBC
+:terremark: 
+  :name: Terremark
+:rackspace: 
+  :username: API key
+  :password: Rackspace password
+  :name: Rackspace
+:azure: 
+  :name: Azure
+:ec2: 
+  :entrypoints: 
+    s3: 
+      us-west-1: s3-us-west-1.amazonaws.com
+      ap-southeast-1: s3-ap-southeast-1.amazonaws.com
+      eu-west-1: s3-eu-west-1.amazonaws.com
+      us-east-1: s3.amazonaws.com
+    elb: 
+      us-west-1: elasticloadbalancing.us-west-1.amazonaws.com
+      ap-southeast-1: elasticloadbalancing.ap-southeast-1.amazonaws.com
+      eu-west-1: elasticloadbalancing.eu-west-1.amazonaws.com
+      us-east-1: elasticloadbalancing.us-east-1.amazonaws.com
+    ec2: 
+      us-west-1: ec2.us-west-1.amazonaws.com
+      ap-southeast-1: ec2.ap-southeast-1.amazonaws.com
+      eu-west-1: ec2.eu-west-1.amazonaws.com
+      us-east-1: ec2.us-east-1.amazonaws.com
+  :username: Access Key ID
+  :password: Secret Access Key
+  :name: EC2

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb?rev=1073029&r1=1073028&r2=1073029&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb Mon Feb 21 15:46:00 2011
@@ -515,34 +515,11 @@ module Deltacloud
           klass.new(credentials.user, credentials.password, {:server => endpoint_for_service(type), :connection_mode => :per_thread})
         end
 
-        DEFAULT_SERVICE_ENDPOINTS = {
-          'ec2' => {
-            'ap-southeast-1' => 'ec2.ap-southeast-1.amazonaws.com',
-            'eu-west-1' => 'ec2.eu-west-1.amazonaws.com',
-            'us-east-1' => 'ec2.us-east-1.amazonaws.com',
-            'us-west-1' => 'ec2.us-west-1.amazonaws.com'
-          },
-          
-          'elb' => {
-            'ap-southeast-1' => 'elasticloadbalancing.ap-southeast-1.amazonaws.com',
-            'eu-west-1' => 'elasticloadbalancing.eu-west-1.amazonaws.com',
-            'us-east-1' => 'elasticloadbalancing.us-east-1.amazonaws.com',
-            'us-west-1' => 'elasticloadbalancing.us-west-1.amazonaws.com'
-          },
-
-          's3' => {
-            'us-east-1' => 's3.amazonaws.com',
-            'us-west-1' => 's3-us-west-1.amazonaws.com',
-            'ap-southeast-1' => 's3-ap-southeast-1.amazonaws.com',
-            'eu-west-1' => 's3-eu-west-1.amazonaws.com'
-          }
-        }
-
         def endpoint_for_service(service)
           endpoint = (Thread.current[:provider] || ENV['API_PROVIDER'] || DEFAULT_REGION)
           # return the endpoint if it does not map to a default endpoint, allowing
           # the endpoint to be a full hostname instead of a region.
-          DEFAULT_SERVICE_ENDPOINTS[service.to_s][endpoint] || endpoint
+          Deltacloud::Drivers::driver_config[:ec2][:entry_points][service.to_s][endpoint] || endpoint
         end
 
         def tag_instance(credentials, instance, name)

Modified: incubator/deltacloud/trunk/server/lib/drivers.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/drivers.rb?rev=1073029&r1=1073028&r2=1073029&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/drivers.rb (original)
+++ incubator/deltacloud/trunk/server/lib/drivers.rb Mon Feb 21 15:46:00 2011
@@ -18,56 +18,50 @@
 # FIXME: This should be moved into lib/ and be called Deltacloud::Drivers
 # or some such
 module Deltacloud
-  DRIVERS = {
-    :ec2 => { :name => "EC2" },
-	:sbc => { :name => "SBC" },
-    :rackspace => { :name => "Rackspace" },
-    :gogrid => { :name => "Gogrid" },
-    :rhevm => { :name => "RHEVM" },
-    :rimuhosting => { :name => "RimuHosting"},
-    :opennebula => { :name => "Opennebula", :class => "OpennebulaDriver" },
-    :terremark => { :name => "Terremark"},
-    :azure => { :name => "Azure" },
-    :mock => { :name => "Mock" }
-  }
-
-  DEFAULT_COLLECTIONS = [
-    :hardware_profiles,
-    :images,
-    :instances,
-    :instance_states,
-    :realms,
-    :storage_volumes,
-    :storage_snapshots
-  ]
 
-  DRIVER=ENV['API_DRIVER'] ? ENV['API_DRIVER'].to_sym : :mock
+  module Drivers
 
-  def driver_symbol
-    (Thread.current[:driver] || DRIVER).to_sym
-  end
-
-  def driver_name
-    DRIVERS[:"#{driver_symbol}"][:name]
-  end
-
-  def driver_class
-    basename = DRIVERS[:"#{driver_symbol}"][:class] || "#{driver_name}Driver"
-    Deltacloud::Drivers.const_get(driver_name).const_get(basename)
-  end
-
-  def driver_source_name
-    File.join("deltacloud", "drivers", "#{driver_symbol}", "#{driver_symbol}_driver.rb")
-  end
-
-  def driver_mock_source_name
-    return File.join('deltacloud', 'drivers', "#{driver_symbol}",
-                     "#{driver_symbol}_driver.rb") if driver_name.eql? 'Mock'
-  end
-
-  def driver
-    require driver_source_name
-
-    @driver ||= driver_class.new
+    DEFAULT_COLLECTIONS = [
+      :hardware_profiles,
+      :images,
+      :instances,
+      :instance_states,
+      :realms,
+      :storage_volumes,
+      :storage_snapshots
+    ]
+
+    DRIVER=ENV['API_DRIVER'] ? ENV['API_DRIVER'].to_sym : :mock
+
+    def driver_config
+      YAML::load(File.read(File.join(File.dirname(__FILE__), '..', 'config', 'drivers.yaml')))
+    end
+
+    def driver_symbol
+      (Thread.current[:driver] || DRIVER).to_sym
+    end
+
+    def driver_name
+      driver_config[:"#{driver_symbol}"][:name]
+    end
+
+    def driver_class
+      basename = driver_config[:"#{driver_symbol}"][:class] || "#{driver_name}Driver"
+      Deltacloud::Drivers.const_get(driver_name).const_get(basename)
+    end
+
+    def driver_source_name
+      File.join("deltacloud", "drivers", "#{driver_symbol}", "#{driver_symbol}_driver.rb")
+    end
+
+    def driver_mock_source_name
+      return File.join('deltacloud', 'drivers', "#{driver_symbol}",
+		       "#{driver_symbol}_driver.rb") if driver_name.eql? 'Mock'
+    end
+
+    def driver
+      require driver_source_name
+      @driver ||= driver_class.new
+    end
   end
 end

Modified: incubator/deltacloud/trunk/server/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/server.rb?rev=1073029&r1=1073028&r2=1073029&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/server.rb (original)
+++ incubator/deltacloud/trunk/server/server.rb Mon Feb 21 15:46:00 2011
@@ -33,6 +33,8 @@ require 'sinatra/rack_etag'
 
 set :version, '0.2.0'
 
+include Deltacloud::Drivers
+set :drivers, Proc.new { driver_config }
 
 use Rack::DriverSelect
 use Rack::ETag

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=1073029&r1=1073028&r2=1073029&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/tests/drivers/mock/api_test.rb (original)
+++ incubator/deltacloud/trunk/server/tests/drivers/mock/api_test.rb Mon Feb 21 15:46:00 2011
@@ -67,11 +67,27 @@ module DeltacloudUnitTest
       end
     end
 
-    def test_it_repond_to_head
+    def test_it_respond_to_head
       head '/api/instances'
       last_response.headers['Allow'].should_not == nil
       last_response.headers['Allow'].split(',').include?('HEAD').should == true
     end
 
+    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
+    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 == ""
+    end
+
   end
 end

Modified: incubator/deltacloud/trunk/server/views/api/drivers.html.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/api/drivers.html.haml?rev=1073029&r1=1073028&r2=1073029&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/views/api/drivers.html.haml (original)
+++ incubator/deltacloud/trunk/server/views/api/drivers.html.haml Mon Feb 21 15:46:00 2011
@@ -7,7 +7,7 @@
       %th ID
       %th Name
   %tbody
-    - DRIVERS.each do |id, details|
+    - settings.drivers.each do |id, details|
       %tr
         %td{ :width => '20%' }
           %tt= id

Modified: incubator/deltacloud/trunk/server/views/api/drivers.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/api/drivers.xml.haml?rev=1073029&r1=1073028&r2=1073029&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/views/api/drivers.xml.haml (original)
+++ incubator/deltacloud/trunk/server/views/api/drivers.xml.haml Mon Feb 21 15:46:00 2011
@@ -1,6 +1,15 @@
 %api{ :version => settings.version }
   %drivers
-    - DRIVERS.each do |id, details|
+    - settings.drivers.each do |id, details|
       %driver{ :id => id }
         %name<
           =details[:name]
+        - if details[:username] or details[:password]
+          %credentials
+            %username<=cdata(details[:username])
+            %password<=cdata(details[:password])
+        - if details[:entrypoints]
+          - details[:entrypoints].each do |list_id, entrypoints|
+            %entrypoints{:id => list_id}
+              - entrypoints.each do |entrypoint, url|
+                %entrypoint{ :id => entrypoint }<=cdata(url)