You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2012/01/23 11:26:13 UTC

svn commit: r1234727 - in /deltacloud/trunk/server/lib/cimi/model: cloud_entry_point.rb entity_metadata.rb

Author: mfojtik
Date: Mon Jan 23 10:26:13 2012
New Revision: 1234727

URL: http://svn.apache.org/viewvc?rev=1234727&view=rev
Log:
CIMI: Simplified the create method in CloudEntryPoint

Modified:
    deltacloud/trunk/server/lib/cimi/model/cloud_entry_point.rb
    deltacloud/trunk/server/lib/cimi/model/entity_metadata.rb

Modified: deltacloud/trunk/server/lib/cimi/model/cloud_entry_point.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/cloud_entry_point.rb?rev=1234727&r1=1234726&r2=1234727&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/cloud_entry_point.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/cloud_entry_point.rb Mon Jan 23 10:26:13 2012
@@ -15,29 +15,36 @@
 
 class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
 
-array :entity_metadata do
-  scalar :href
-end
+  array :entity_metadata do
+    scalar :href
+  end
 
   def self.create(context)
-    root_entities = CIMI::Model.root_entities.inject({}) do |result, entity|
+    self.new(entities(context).merge({
+      :name => context.driver.name,
+      :description => "Cloud Entry Point for the Deltacloud #{context.driver.name} driver",
+      :uri => context.cloudEntryPoint_url,
+      :created => Time.now,
+      :entity_metadata => EntityMetadata.all_uri(context)
+    }))
+  end
+
+  # Return an Hash of the CIMI root entities used in CloudEntryPoint
+  def self.entities(context)
+    CIMI::Model.root_entities.inject({}) do |result, entity|
       if context.respond_to? :"#{entity.underscore}_url"
         result[entity.underscore] = { :href => context.send(:"#{entity.underscore}_url") }
       end
       result
     end
+  end
+
+  # Return an Hash of links to the EntityMetadata objects
+  def root_entity_metadata(context)
     entity_metadata = EntityMetadata.all(context)
-    root_entity_meta = [] ; entity_metadata.each do |m|
-      root_entity_meta << {:href=>m.uri}
+    entity_metadata.map do |m|
+      { :href => m.uri }
     end
-    root_entities.merge!({
-      :name => context.driver.name,
-      :description => "Cloud Entry Point for the Deltacloud #{context.driver.name} driver",
-      :uri => context.cloudEntryPoint_url,
-      :created => Time.now,
-      :entity_metadata => root_entity_meta
-    })
-    self.new(root_entities)
   end
 
   private

Modified: deltacloud/trunk/server/lib/cimi/model/entity_metadata.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/entity_metadata.rb?rev=1234727&r1=1234726&r2=1234727&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/entity_metadata.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/entity_metadata.rb Mon Jan 23 10:26:13 2012
@@ -63,14 +63,14 @@ text :type_uri
   private
 
   def self.attributes_from_feature(feature)
-    attributes = []
-    feature.operations.first.params.each_key do |param|
-      attributes << {
+    feature.operations.first.params.inject([]) do |result, param|
+      p = feature.operations.first.params[param]
+      result << {
         :name=>(feature.name == :user_name ? :name : param),
         :type=> "xs:string",
-        :required=>(feature.operations.first.params[param].type == :optional ? "false" : "true"),
+        :required=> (p and p.optional?) ? "false" : "true",
         :constraints=> (feature.constraints.empty? ? (feature.description.nil? ? "" : feature.description): feature.constraints)
-                    }
+      }
     end
     attributes
   end