deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 36/51] Core: Fixed advertising of collection features other than instances
Date Mon, 21 May 2012 10:07:17 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/deltacloud/collections/buckets.rb    |    9 +++----
 server/lib/deltacloud/collections/images.rb     |    3 +++
 server/lib/deltacloud/collections/instances.rb  |    2 +-
 server/lib/deltacloud/drivers/base_driver.rb    |    7 ++---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |    4 +--
 server/lib/deltacloud/drivers/features.rb       |   31 ++++++++++++++++++++++-
 6 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/server/lib/deltacloud/collections/buckets.rb b/server/lib/deltacloud/collections/buckets.rb
index 3a5591d..16f3f8f 100644
--- a/server/lib/deltacloud/collections/buckets.rb
+++ b/server/lib/deltacloud/collections/buckets.rb
@@ -15,14 +15,13 @@
 
 module Deltacloud::Collections
   class Buckets < Base
+
+    include Deltacloud::Features
+
     check_capability :for => lambda { |m| driver.respond_to? m }
     check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
 
-    get route_for('/buckets/new') do
-      respond_to do |format|
-        format.html { haml :"buckets/new" }
-      end
-    end
+    new_route_for :buckets
 
     get route_for('/buckets/:bucket/%s' % NEW_BLOB_FORM_ID) do
       @bucket_id = params[:bucket]
diff --git a/server/lib/deltacloud/collections/images.rb b/server/lib/deltacloud/collections/images.rb
index c8b3e08..0edd7c0 100644
--- a/server/lib/deltacloud/collections/images.rb
+++ b/server/lib/deltacloud/collections/images.rb
@@ -15,6 +15,9 @@
 
 module Deltacloud::Collections
   class Images < Base
+
+    include Deltacloud::Features
+
     check_capability :for => lambda { |m| driver.respond_to? m }
     check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
 
diff --git a/server/lib/deltacloud/collections/instances.rb b/server/lib/deltacloud/collections/instances.rb
index 0da94f2..bba2ef9 100644
--- a/server/lib/deltacloud/collections/instances.rb
+++ b/server/lib/deltacloud/collections/instances.rb
@@ -16,7 +16,7 @@
 module Deltacloud::Collections
   class Instances < Base
 
-    include Deltacloud::InstanceFeatures
+    include Deltacloud::Features
 
     check_capability :for => lambda { |m| driver.respond_to? m }
     check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
index 9913c27..a360807 100644
--- a/server/lib/deltacloud/drivers/base_driver.rb
+++ b/server/lib/deltacloud/drivers/base_driver.rb
@@ -30,7 +30,7 @@ module Deltacloud
     end
 
     def self.features
-      @features ||= []
+      @features ||= {}
     end
 
     def self.features_for(entity)
@@ -45,7 +45,8 @@ module Deltacloud
       constraints[collection] ||= {}
       constraints[collection][feature_name] ||= {}
       constraints[collection][feature_name].merge!(yield) if block_given?
-      features << { collection => feature_name }
+      features[collection] ||= []
+      features[collection] << feature_name
     end
 
     def self.constraints(opts={})
@@ -57,7 +58,7 @@ module Deltacloud
     end
 
     def self.has_feature?(collection, feature_name)
-      features.any? { |f| (f.values.first == feature_name) && (f.keys.first == collection)
}
+      features.has_key?(collection) and features[collection].include?(feature_name)
     end
 
     def name
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index f7559a3..b55132e 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -36,8 +36,8 @@ module Deltacloud
         feature :instances, :firewalls
         feature :instances, :instance_count
         feature :images, :owner_id
-        feature :images, :user_name
-        feature :images, :user_description
+        feature :images, :image_name
+        feature :images, :image_description
         feature :buckets, :bucket_location
         feature :instances, :attach_snapshot
 
diff --git a/server/lib/deltacloud/drivers/features.rb b/server/lib/deltacloud/drivers/features.rb
index 01d8656..c772a42 100644
--- a/server/lib/deltacloud/drivers/features.rb
+++ b/server/lib/deltacloud/drivers/features.rb
@@ -14,7 +14,8 @@
 # under the License.
 
 module Deltacloud
-  module InstanceFeatures
+
+  module Features
 
     def self.included(k)
       current_features = features
@@ -29,6 +30,34 @@ module Deltacloud
 
     features do
 
+      feature :owner_id, :for => :images do
+        description "Filter images using owner id"
+        operation :index do
+          param :owner_id,  :string,  :optional,  [],  "Owner ID"
+        end
+      end
+
+      feature :image_name, :for => :images do
+        description "Allow specifying user name for created image"
+        operation :create do
+          param :name,  :string,  :optional,  [],  "Image name"
+        end
+      end
+
+      feature :image_description, :for => :images do
+        description "Allow specifying user description for created image"
+        operation :create do
+          param :description, :string,  :optional,  [],  "Image description"
+        end
+      end
+
+      feature :bucket_location, :for => :buckets do
+        description "Take extra location parameter for Bucket creation (e.g. S3, 'eu' or
'us-west-1')"
+        operation :create do
+          param :location, :string, :optional
+        end
+      end
+
       feature :user_name, :for => :instances do
         description "Allow to set user-defined name for the instance"
         operation :create do
-- 
1.7.10.1


Mime
View raw message