You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2010/07/09 01:38:37 UTC

svn commit: r962235 - /incubator/deltacloud/trunk/client/lib/deltacloud.rb

Author: lutter
Date: Thu Jul  8 23:38:36 2010
New Revision: 962235

URL: http://svn.apache.org/viewvc?rev=962235&view=rev
Log:
* client/lib/deltacloud.rb: support for optional features

Add method feature? to query if driver supports a certain feature, and
discover them during discovery of entry points

Modified:
    incubator/deltacloud/trunk/client/lib/deltacloud.rb

Modified: incubator/deltacloud/trunk/client/lib/deltacloud.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/lib/deltacloud.rb?rev=962235&r1=962234&r2=962235&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/lib/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/client/lib/deltacloud.rb Thu Jul  8 23:38:36 2010
@@ -35,6 +35,7 @@ class DeltaCloud
   attr_reader   :entry_points
   attr_reader   :driver_name
   attr_reader   :last_request_xml
+  attr_reader   :features
 
   def self.driver_name(url)
     DeltaCloud.new( nil, nil, url) do |client|
@@ -49,6 +50,7 @@ class DeltaCloud
     @api_uri      = URI.parse( api_uri )
     @entry_points = {}
     @verbose      = opts[:verbose]
+    @features = {}
     discover_entry_points
     connect( &block )
     self
@@ -74,6 +76,10 @@ class DeltaCloud
     @api_uri.path
   end
 
+  def feature?(collection, name)
+    @features.has_key?(collection) && @features[collection].include?(name)
+  end
+
   def flavors(opts={})
     flavors = []
     request(entry_points[:flavors], :get, opts) do |response|
@@ -344,15 +350,21 @@ class DeltaCloud
   attr_reader :http
 
   def discover_entry_points
+    return if @discovered
     request(api_uri.to_s) do |response|
       doc = REXML::Document.new( response )
       @driver_name = doc.root.attributes['driver']
       doc.get_elements( 'api/link' ).each do |link|
-        rel = link.attributes['rel']
+        rel = link.attributes['rel'].to_sym
         uri = link.attributes['href']
-        @entry_points[rel.to_sym] = uri
+        @entry_points[rel] = uri
+        @features[rel] ||= []
+        link.get_elements('feature').each do |feature|
+          @features[rel] << feature.attributes['name'].to_sym
+        end
       end
     end
+    @discovered = true
   end
 
   def request(path='', method=:get, query_args={}, form_data={}, &block)