From: marios <[email protected]>
Signed-off-by: marios <[email protected]> --- server/lib/cimi/model.rb | 1 + server/lib/cimi/model/entity_metadata.rb | 85 ++++++++++++++++++++++++++++++ server/lib/cimi/server.rb | 30 ++++++++++- 3 files changed, 115 insertions(+), 1 deletions(-) create mode 100644 server/lib/cimi/model/entity_metadata.rb diff --git a/server/lib/cimi/model.rb b/server/lib/cimi/model.rb index 79645b2..76c0b15 100644 --- a/server/lib/cimi/model.rb +++ b/server/lib/cimi/model.rb @@ -43,3 +43,4 @@ require 'cimi/model/machine_admin_collection' require 'cimi/model/volume_configuration_collection' require 'cimi/model/volume_image_collection' require 'cimi/model/volume_template_collection' +require 'cimi/model/entity_metadata' diff --git a/server/lib/cimi/model/entity_metadata.rb b/server/lib/cimi/model/entity_metadata.rb new file mode 100644 index 0000000..eca2443 --- /dev/null +++ b/server/lib/cimi/model/entity_metadata.rb @@ -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 diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb index 746587c..305d95f 100644 --- a/server/lib/cimi/server.rb +++ b/server/lib/cimi/server.rb @@ -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 @@ -420,4 +419,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 -- 1.7.6.4
