deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 1/6] CIMI: Simplified the create method in CloudEntryPoint
Date Tue, 17 Jan 2012 11:52:54 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/cimi/model/cloud_entry_point.rb |   35 ++++++++++++++++-----------
 server/lib/cimi/model/entity_metadata.rb   |   10 ++++----
 2 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/server/lib/cimi/model/cloud_entry_point.rb b/server/lib/cimi/model/cloud_entry_point.rb
index e7464f0..e14678d 100644
--- a/server/lib/cimi/model/cloud_entry_point.rb
+++ b/server/lib/cimi/model/cloud_entry_point.rb
@@ -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
diff --git a/server/lib/cimi/model/entity_metadata.rb b/server/lib/cimi/model/entity_metadata.rb
index 2611873..922df1f 100644
--- a/server/lib/cimi/model/entity_metadata.rb
+++ b/server/lib/cimi/model/entity_metadata.rb
@@ -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
-- 
1.7.4.4


Mime
View raw message