From: David Lutterkort <[email protected]> --- server/lib/cimi/collections/entity_metadata.rb | 46 ----------- server/lib/cimi/collections/resource_metadata.rb | 46 +++++++++++ server/lib/cimi/models.rb | 3 +- server/lib/cimi/models/cloud_entry_point.rb | 14 ++-- server/lib/cimi/models/entity_metadata.rb | 83 ------------------- .../lib/cimi/models/entity_metadata_collection.rb | 31 ------- server/lib/cimi/models/machine.rb | 6 +- server/lib/cimi/models/resource_metadata.rb | 85 ++++++++++++++++++++ 8 files changed, 141 insertions(+), 173 deletions(-) delete mode 100644 server/lib/cimi/collections/entity_metadata.rb create mode 100644 server/lib/cimi/collections/resource_metadata.rb delete mode 100644 server/lib/cimi/models/entity_metadata.rb delete mode 100644 server/lib/cimi/models/entity_metadata_collection.rb create mode 100644 server/lib/cimi/models/resource_metadata.rb
diff --git a/server/lib/cimi/collections/entity_metadata.rb b/server/lib/cimi/collections/entity_metadata.rb deleted file mode 100644 index 0bca4e3..0000000 --- a/server/lib/cimi/collections/entity_metadata.rb +++ /dev/null @@ -1,46 +0,0 @@ -# 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. - -module CIMI::Collections - class EntityMetadata < Base - - collection :entity_metadata do - - operation :index do - description "List all entity metadata defined for this provider" - control do - entity_metadata = CIMI::Model::EntityMetadataCollection.default(self) - respond_to do |format| - format.xml{entity_metadata.to_xml} - format.json{entity_metadata.to_json} - end - end - end - - operation :show do - description "Get the entity metadata for a specific collection" - 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 -end diff --git a/server/lib/cimi/collections/resource_metadata.rb b/server/lib/cimi/collections/resource_metadata.rb new file mode 100644 index 0000000..302f868 --- /dev/null +++ b/server/lib/cimi/collections/resource_metadata.rb @@ -0,0 +1,46 @@ +# 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. + +module CIMI::Collections + class ResourceMetadata < Base + + collection :resource_metadata do + + operation :index do + description "List all resource metadata defined for this provider" + control do + resource_metadata = CIMI::Model::ResourceMetadataCollection.default(self) + respond_to do |format| + format.xml{resource_metadata.to_xml} + format.json{resource_metadata.to_json} + end + end + end + + operation :show do + description "Get the resource metadata for a specific collection" + control do + resource_metadata = ResourceMetadata.find(params[:id], self) + respond_to do |format| + format.xml{resource_metadata.to_xml} + format.json{resource_metadata.to_json} + end + end + end + + end + + end +end diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb index 722bbad..a4796e0 100644 --- a/server/lib/cimi/models.rb +++ b/server/lib/cimi/models.rb @@ -23,9 +23,8 @@ require_relative './models/schema' require_relative './models/base' require_relative './models/collection' require_relative './models/errors' -require_relative './models/entity_metadata' -require_relative './models/entity_metadata_collection' require_relative './models/cloud_entry_point' +require_relative './models/resource_metadata' require_relative './models/machine_template' require_relative './models/machine_image' require_relative './models/machine_configuration' diff --git a/server/lib/cimi/models/cloud_entry_point.rb b/server/lib/cimi/models/cloud_entry_point.rb index f623798..67706af 100644 --- a/server/lib/cimi/models/cloud_entry_point.rb +++ b/server/lib/cimi/models/cloud_entry_point.rb @@ -17,27 +17,25 @@ class CIMI::Model::CloudEntryPoint < CIMI::Model::Base text :base_uri, :xml_name => "baseURI", :json_name => "baseURI" - array :entity_metadata do - scalar :href - end - def self.create(context) self.new(entities(context).merge({ :name => context.driver.name, :description => "Cloud Entry Point for the Deltacloud #{context.driver.name} driver", :id => context.cloudEntryPoint_url, :base_uri => context.base_uri, - :created => Time.now, - :entity_metadata => CIMI::Model::EntityMetadata.all_uri(context) + :created => Time.now })) end # Return an Hash of the CIMI root entities used in CloudEntryPoint def self.entities(context) CIMI::Collections.cimi_modules.inject({}) do |supported_entities, m| + puts "Mod #{m.name}" m.collections.each do |c| index_operation_capability = c.operation(:index).required_capability + puts " index cap" next if m.settings.respond_to?(:capability) and !m.settings.capability(index_operation_capability) + puts" YES" supported_entities[c.collection_name.to_s] = { :href => context.send(:"#{c.collection_name}_url") } end supported_entities @@ -46,8 +44,8 @@ class CIMI::Model::CloudEntryPoint < CIMI::Model::Base private - def self.href_defined?(entity) - true if schema.attribute_names.include? entity.underscore + def self.href_defined?(resource) + true if schema.attribute_names.include? resource.underscore end end diff --git a/server/lib/cimi/models/entity_metadata.rb b/server/lib/cimi/models/entity_metadata.rb deleted file mode 100644 index 2379e7d..0000000 --- a/server/lib/cimi/models/entity_metadata.rb +++ /dev/null @@ -1,83 +0,0 @@ -# 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_class| - entity_metadata << entity_class.create_entity_metadata(context) if entity_class.respond_to?(:create_entity_metadata) - end - return entity_metadata - else - entity_class = CIMI::Model.const_get("#{id.camelize}") - if entity_class.respond_to?(:create_entity_metadata) - entity_class.create_entity_metadata(context) - end - end - end - - def self.metadata_from_deltacloud_features(cimi_entity, dcloud_entity, context) - deltacloud_features = context.driver.class.features[dcloud_entity] - metadata_attributes = deltacloud_features.map{|f| attributes_from_feature(f)} - from_feature(cimi_entity, context, metadata_attributes.flatten!) - end - - def includes_attribute?(attribute) - self.attributes.any?{|attr| attr[:name] == attribute} - end - - private - - def self.attributes_from_feature(feature) - feature = CIMI::FakeCollection.feature(feature) - feature.operations.first.params_array.map do |p| - { - :name=> p.name, - :type=> "xs:string", - :required=> p.required? ? "true" : "false", - :constraints=> (feature.constraints.empty? ? (feature.description.nil? ? "" : feature.description): feature.constraints) - } - end - 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/models/entity_metadata_collection.rb b/server/lib/cimi/models/entity_metadata_collection.rb deleted file mode 100644 index 595b502..0000000 --- a/server/lib/cimi/models/entity_metadata_collection.rb +++ /dev/null @@ -1,31 +0,0 @@ -# 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::EntityMetadataCollection < CIMI::Model::Base - - array :entity_metadata do - scalar :href - end - - def self.default(context) - self.new( - :id => context.entity_metadata_url, - :name => 'default', - :created => Time.now, - :entity_metadata => CIMI::Model::EntityMetadata.all_uri(context) - ) - end - -end diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb index 41b6b6b..da67eb7 100644 --- a/server/lib/cimi/models/machine.rb +++ b/server/lib/cimi/models/machine.rb @@ -90,9 +90,9 @@ class CIMI::Model::Machine < CIMI::Model::Base context.driver.destroy_instance(context.credentials, id) end - def self.create_entity_metadata(context) - cimi_entity = self.name.split("::").last - metadata = CIMI::Model::EntityMetadata.metadata_from_deltacloud_features(cimi_entity, :instances, context) + def self.create_resource_metadata(context) + cimi_resource = self.name.split("::").last + metadata = CIMI::Model::ResourceMetadata.metadata_from_deltacloud_features(cimi_resource, :instances, context) unless metadata.includes_attribute?(:name) metadata.attributes << {:name=>"name", :required=>"false", :constraints=>"Determined by the cloud provider", :type=>"xs:string"} diff --git a/server/lib/cimi/models/resource_metadata.rb b/server/lib/cimi/models/resource_metadata.rb new file mode 100644 index 0000000..5e62061 --- /dev/null +++ b/server/lib/cimi/models/resource_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::ResourceMetadata < CIMI::Model::Base + + acts_as_root_entity + + 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) + resource_metadata = [] + if id == :all + CIMI::Model.root_entities.each do |resource_class| + resource_metadata << resource_class.create_resource_metadata(context) if resource_class.respond_to?(:create_resource_metadata) + end + return resource_metadata + else + resource_class = CIMI::Model.const_get("#{id.camelize}") + if resource_class.respond_to?(:create_resource_metadata) + resource_class.create_resource_metadata(context) + end + end + end + + def self.metadata_from_deltacloud_features(cimi_resource, dcloud_resource, context) + deltacloud_features = context.driver.class.features[dcloud_resource] + metadata_attributes = deltacloud_features.map{|f| attributes_from_feature(f)} + from_feature(cimi_resource, context, metadata_attributes.flatten!) + end + + def includes_attribute?(attribute) + self.attributes.any?{|attr| attr[:name] == attribute} + end + + private + + def self.attributes_from_feature(feature) + feature = CIMI::FakeCollection.feature(feature) + feature.operations.first.params_array.map do |p| + { + :name=> p.name, + :type=> "xs:string", + :required=> p.required? ? "true" : "false", + :constraints=> (feature.constraints.empty? ? (feature.description.nil? ? "" : feature.description): feature.constraints) + } + end + end + + def self.from_feature(cimi_resource, context, metadata_attributes) + self.new(:name => cimi_resource, :uri=>"#{context.resource_metadata_url}/#{cimi_resource.underscore}", + :type_uri=> context.send("#{cimi_resource.pluralize.underscore}_url"), + :attributes => metadata_attributes) + end + +end -- 1.7.7.6
