deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r1211948 - in /deltacloud/trunk/server/lib/cimi: model.rb model/entity_metadata.rb server.rb
Date Thu, 08 Dec 2011 16:21:12 GMT
Author: marios
Date: Thu Dec  8 16:21:12 2011
New Revision: 1211948

URL: http://svn.apache.org/viewvc?rev=1211948&view=rev
Log:
Adds CIMI::EntityMetadata model

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

Modified: deltacloud/trunk/server/lib/cimi/model.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model.rb?rev=1211948&r1=1211947&r2=1211948&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model.rb Thu Dec  8 16:21:12 2011
@@ -43,3 +43,4 @@ require 'cimi/model/machine_admin_collec
 require 'cimi/model/volume_configuration_collection'
 require 'cimi/model/volume_image_collection'
 require 'cimi/model/volume_template_collection'
+require 'cimi/model/entity_metadata'

Added: 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=1211948&view=auto
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/entity_metadata.rb (added)
+++ deltacloud/trunk/server/lib/cimi/model/entity_metadata.rb Thu Dec  8 16:21:12 2011
@@ -0,0 +1,85 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+
+class CIMI::Model::EntityMetadata < CIMI::Model::Base
+
+text :type_uri
+
+  array :attributes do
+    scalar :name
+    scalar :namespace
+    scalar :type
+    scalar :required
+    scalar :constraints
+  end
+
+  array :operations do
+    scalar :name
+    scalar :uri
+    scalar :description
+    scalar :method
+    scalar :input_message
+    scalar :output_message
+  end
+
+  def self.find(id, context)
+    entity_metadata = []
+    if id == :all
+      CIMI::Model.root_entities.each do |entity|
+        entity_class = Object::const_get("CIMI").const_get("Model").const_get("#{entity.singularize}")
+        entity_metadata << entity_class.create_entity_metadata(context) if entity_class.respond_to?("create_entity_metadata")
+      end
+      return entity_metadata
+    else
+      entity_class = Object::const_get("CIMI").const_get("Model").const_get("#{id.camelize}")
+      entity_metadata << entity_class.create_entity_metadata(context) if entity_class.respond_to?("create_entity_metadata")
+      return entity_metadata.first
+    end
+  end
+
+  def self.metadata_from_deltacloud_features(cimi_entity, dcloud_entity, context)
+      metadata_attributes = []
+      deltacloud_features = context.driver.features(dcloud_entity)
+      deltacloud_features.each do |feature|
+        metadata_attributes << attributes_from_feature(feature)
+      end
+      from_feature(cimi_entity, context, metadata_attributes)
+  end
+
+  def includes_attribute?(attribute)
+    self.attributes.each do |attr|
+      return true if attr[:name] == attribute
+    end
+    return false
+  end
+
+  private
+
+  def self.attributes_from_feature(feature)
+    { :name=>(feature.name == :user_name ? :name : feature.name),
+      :type=> "xs:string",
+      :required=>(feature.operations.first.params[feature.name].type == :optional ? "false"
: "true"),
+      :constraints=> (feature.constraints.empty? ? (feature.description.nil? ? "" : feature.description):
feature.constraints)
+    }
+  end
+
+  def self.from_feature(cimi_entity, context, metadata_attributes)
+    self.new(:name => cimi_entity, :uri=>"#{context.entity_metadata_url}/#{cimi_entity.underscore}",
+            :type_uri=> context.send("#{cimi_entity.pluralize.underscore}_url"),
+            :attributes => metadata_attributes   )
+  end
+
+end

Modified: deltacloud/trunk/server/lib/cimi/server.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/server.rb?rev=1211948&r1=1211947&r2=1211948&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/server.rb (original)
+++ deltacloud/trunk/server/lib/cimi/server.rb Thu Dec  8 16:21:12 2011
@@ -75,7 +75,6 @@ end
 
 global_collection  :cloudEntryPoint do
   description 'Cloud entry point'
-
   operation :index do
     description "list all resources of the cloud"
     control do
@@ -423,4 +422,33 @@ global_collection :volume_images do
 
 end
 
+
+global_collection :entity_metadata do
+  description 'This allows for the discovery of Provider defined constraints on the CIMI
defined attributes as well as discovery of any new extension attributes that the Provider
may have defined.'
+
+  operation :index do
+    description "List all entity metadata defined for this provider"
+    control do
+      entity_metadata = EntityMetadata.all(self)
+      respond_to do |format|
+        format.xml{entity_metadata.to_xml_cimi_collection(self)}
+        format.json{entity_metadata.to_json_cimi_collection(self)}
+      end
+    end
+  end
+
+  operation :show do
+    description "Get the entity metadata for a specific collection"
+    param :id, :required, :string
+    control do
+      entity_metadata = EntityMetadata.find(params[:id], self)
+      respond_to do |format|
+        format.xml{entity_metadata.to_xml}
+        format.json{entity_metadata.to_json}
+      end
+    end
+  end
+
+end
+
 end



Mime
View raw message