From: marios <[email protected]>
Signed-off-by: marios <[email protected]> --- server/lib/cimi/model.rb | 1 + server/lib/cimi/model/entity_metadata.rb | 63 ++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 0 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 d11d77b..314c8fa 100644 --- a/server/lib/cimi/model.rb +++ b/server/lib/cimi/model.rb @@ -42,3 +42,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..2d9d07d --- /dev/null +++ b/server/lib/cimi/model/entity_metadata.rb @@ -0,0 +1,63 @@ +# 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 + +act_as_root_entity + +text :type_uri + + array :attributes do + scalar :name + scalar :namespace + scalar :type + scalar :required + scalar :constraints + end + +#array :operations do +#end + + def self.find(context, cimi_entity, dcloud_entity) + metadata = [] + metadata_attributes = [] + deltacloud_features = context.driver.features(dcloud_entity) + deltacloud_features.each do |feature| + metadata_attributes << attributes_from_feature(feature) + end + from_feature(context, cimi_entity, metadata_attributes) + end + + private + + def self.attributes_from_feature(feature) + { :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(context, cimi_entity, attributes) + self.new(:name => cimi_entity, :uri=>"http://localhost:3001/cimi/meta/#{cimi_entity}", #FIXME context.entity_metadata_url(cimi_entity), + :type_uri=> context.send("#{cimi_entity.pluralize.underscore}_url"), + :attributes => attributes ) + end + +#array :operations do +#end + +end -- 1.7.6.4
