+1 ACK ... great stuff - this is a much neater way of doing this -
applied cleanly and started up gogrid and ec2 drivers with no explosions.
On 15/07/10 12:46, [email protected] wrote:
---
server/lib/deltacloud/base_driver/base_driver.rb | 10 ++++++++++
.../lib/deltacloud/drivers/gogrid/gogrid_driver.rb | 4 ++++
server/lib/drivers.rb | 10 ++++++++++
server/lib/sinatra/rabbit.rb | 1 +
4 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/server/lib/deltacloud/base_driver/base_driver.rb
b/server/lib/deltacloud/base_driver/base_driver.rb
index f7dcf7e..e4b5a7b 100644
--- a/server/lib/deltacloud/base_driver/base_driver.rb
+++ b/server/lib/deltacloud/base_driver/base_driver.rb
@@ -185,6 +185,16 @@ module Deltacloud
return collection.select{|e| filter == e.send(attribute) }
end
end
+
+ def supported_collections
+ DEFAULT_COLLECTIONS
+ end
+
+ def has_collection?(collection)
+ return true if self.supported_collections.include?(collection)
+ return false
+ end
+
end
end
diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index 7e7fe4e..1550f9b 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -43,6 +43,10 @@ class GogridDriver< Deltacloud::BaseDriver
storage 10
end
+ def supported_collections
+ DEFAULT_COLLECTIONS.reject { |c| [ :storage_volumes, :storage_snapshots
].include?(c) }
+ end
+
# The only valid option for flavors is server RAM for now
def flavors(credentials, opts=nil)
flavors = []
diff --git a/server/lib/drivers.rb b/server/lib/drivers.rb
index 17829f2..261e0c8 100644
--- a/server/lib/drivers.rb
+++ b/server/lib/drivers.rb
@@ -9,6 +9,16 @@ DRIVERS = {
: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
def driver_name
diff --git a/server/lib/sinatra/rabbit.rb b/server/lib/sinatra/rabbit.rb
index 6018810..f411268 100644
--- a/server/lib/sinatra/rabbit.rb
+++ b/server/lib/sinatra/rabbit.rb
@@ -203,6 +203,7 @@ module Sinatra
# operation on this collection.
def collection(name,&block)
raise DuplicateCollectionException if collections[name]
+ return unless driver.has_collection?(name.to_sym)
collections[name] = Collection.new(name,&block)
collections[name].add_feature_params(driver.features(name))
collections[name].generate