deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@redhat.com
Subject [PATCH 1/2] CIMI - dont expose 'add' URI for collection if not supported DTACLOUD-400
Date Fri, 14 Dec 2012 11:56:37 GMT
From: marios <marios@redhat.com>

https://issues.apache.org/jira/browse/DTACLOUD-400

Signed-off-by: marios <marios@redhat.com>
---
 server/lib/cimi/helpers/cimi_helper.rb | 12 ++++++++++++
 server/lib/cimi/models/collection.rb   |  8 +++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/server/lib/cimi/helpers/cimi_helper.rb b/server/lib/cimi/helpers/cimi_helper.rb
index 8fad786..b062af7 100644
--- a/server/lib/cimi/helpers/cimi_helper.rb
+++ b/server/lib/cimi/helpers/cimi_helper.rb
@@ -92,6 +92,18 @@ module CIMI
       type = (xml)? :xml : :json
     end
 
+    def deltacloud_create_method_for(cimi_entity)
+      case cimi_entity
+        when "machine"                then "create_instance"
+        when "machine_configuration"  then "create_hardware_profile"
+        when "machine_image"          then "create_image"
+        when "volume"                 then "create_storage_volume"
+        when "volume_image"           then "create_storage_snapshot"
+        else "create_#{cimi_entity}"
+      end
+
+    end
+
   end
 end
 
diff --git a/server/lib/cimi/models/collection.rb b/server/lib/cimi/models/collection.rb
index c7f3b21..0fc5eec 100644
--- a/server/lib/cimi/models/collection.rb
+++ b/server/lib/cimi/models/collection.rb
@@ -118,9 +118,11 @@ module CIMI::Model
         desc = "#{self.name.split("::").last} Collection for the #{context.driver.name.capitalize}
driver"
         id = context.send("#{collection_class.entry_name}_url")
         ops = []
-        create = "create_#{collection_class.entry_name.to_s.singularize}_url"
-        if context.respond_to?(create)
-          url = context.send(create)
+        cimi_entity = collection_class.entry_name.to_s.singularize
+        cimi_create = "create_#{cimi_entity}_url"
+        dcloud_create = context.deltacloud_create_method_for(cimi_entity)
+        if context.respond_to?(cimi_create) && context.driver.respond_to?(dcloud_create)
+          url = context.send(cimi_create)
           ops << { :rel => "add", :href => url }
         end
         collection_class.new(:id => id, :name => 'default',
-- 
1.7.11.7


Mime
View raw message