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:19 UTC
svn commit: r962231 - in /incubator/deltacloud/trunk/server/libexec:
lib/deltacloud/base_driver.rb lib/deltacloud/base_driver/features.rb
views/api/show.xml.haml
Author: lutter
Date: Thu Jul 8 23:38:19 2010
New Revision: 962231
URL: http://svn.apache.org/viewvc?rev=962231&view=rev
Log:
Advertising of optional features
* base_driver: add features and support for defining them in drivers
* views (xml): list features for each collection in api.xml
Added:
incubator/deltacloud/trunk/server/libexec/lib/deltacloud/base_driver/features.rb
Modified:
incubator/deltacloud/trunk/server/libexec/lib/deltacloud/base_driver.rb
incubator/deltacloud/trunk/server/libexec/views/api/show.xml.haml
Modified: incubator/deltacloud/trunk/server/libexec/lib/deltacloud/base_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/lib/deltacloud/base_driver.rb?rev=962231&r1=962230&r2=962231&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/lib/deltacloud/base_driver.rb (original)
+++ incubator/deltacloud/trunk/server/libexec/lib/deltacloud/base_driver.rb Thu Jul 8 23:38:19 2010
@@ -16,3 +16,4 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
require 'deltacloud/base_driver/base_driver'
+require 'deltacloud/base_driver/features'
Added: incubator/deltacloud/trunk/server/libexec/lib/deltacloud/base_driver/features.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/lib/deltacloud/base_driver/features.rb?rev=962231&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/lib/deltacloud/base_driver/features.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/lib/deltacloud/base_driver/features.rb Thu Jul 8 23:38:19 2010
@@ -0,0 +1,114 @@
+require 'deltacloud/validation'
+
+# Add advertising of optional features to the base driver
+module Deltacloud
+
+ class FeatureError < StandardError; end
+ class DuplicateFeatureDeclError < FeatureError; end
+ class DuplicateFeatureError < FeatureError; end
+ class UndeclaredFeatureError < FeatureError; end
+
+ class BaseDriver
+
+ # An operation on a collection like cretae or show. Features
+ # can add parameters to operations
+ class Operation
+ attr_reader :name
+
+ include Deltacloud::Validation
+
+ def initialize(name, &block)
+ @name = name
+ @params = {}
+ instance_eval &block
+ end
+ end
+
+ # The declaration of a feature, defines what operations
+ # are modified by it
+ class FeatureDecl
+ attr_reader :name, :operations
+
+ def initialize(name, &block)
+ @name = name
+ @operations = []
+ instance_eval &block
+ end
+
+ def description(text=nil)
+ @description = text if text
+ @description
+ end
+
+ def operation(name, &block)
+ @operations << Operation.new(name, &block)
+ end
+ end
+
+ # A specific feature enabled by a driver (see +feature+)
+ class Feature
+ attr_reader :decl
+
+ def initialize(decl, &block)
+ @decl = decl
+ instance_eval &block if block_given?
+ end
+
+ def name
+ decl.name
+ end
+
+ def operations
+ decl.operations
+ end
+
+ def description
+ decl.description
+ end
+ end
+
+ def self.feature_decls
+ @@feature_decls ||= {}
+ end
+
+ def self.feature_decl_for(collection, name)
+ decls = feature_decls[collection]
+ if decls
+ decls.find { |dcl| dcl.name == name }
+ else
+ nil
+ end
+ end
+
+ # Declare a new feature
+ def self.declare_feature(collection, name, &block)
+ feature_decls[collection] ||= []
+ raise DuplicateFeatureDeclError if feature_decl_for(collection, name)
+ feature_decls[collection] << FeatureDecl.new(name, &block)
+ end
+
+ def self.features
+ @@features ||= {}
+ end
+
+ # Declare in a driver that it supports a specific feature
+ def self.feature(collection, name, &block)
+ features[collection] ||= []
+ if features[collection].find { |f| f.name == name }
+ raise DuplicateFeatureError
+ end
+ unless decl = feature_decl_for(collection, name)
+ raise UndeclaredFeatureError, "No feature #{name} for #{collection}"
+ end
+ features[collection] << Feature.new(decl, &block)
+ end
+
+ def features(collection)
+ self.class.features[collection] || []
+ end
+
+ #
+ # Declaration of optional features
+ #
+ end
+end
Modified: incubator/deltacloud/trunk/server/libexec/views/api/show.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/views/api/show.xml.haml?rev=962231&r1=962230&r2=962231&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/views/api/show.xml.haml (original)
+++ incubator/deltacloud/trunk/server/libexec/views/api/show.xml.haml Thu Jul 8 23:38:19 2010
@@ -1,3 +1,5 @@
%api{ :version=>@version, :driver=>DRIVER }
- for entry_point in entry_points
%link{ :rel=>entry_point[0], :href=>entry_point[1] }
+ - for feature in driver.features(entry_point[0])
+ %feature{ :name=>feature.name }