deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Fojtik <mfoj...@redhat.com>
Subject Re: [PATCH 09/10] CIMI: rename entityMetadata to resourceMetadata
Date Sat, 22 Sep 2012 21:35:39 GMT
On Sep 21, 2012, at 11:51 PM, lutter@redhat.com wrote:

This test will need to be revamped in order to import this patch:

  1) Error:
test_0002_generate proper url for EntityMetadata(CIMI):
NoMethodError: undefined method `entity_metadata_url' for #<CIMITestHelper:0x007ffbb18f9210>
    /Users/mfojtik/code/core/server/tests/cimi/collections/url_helper_test.rb:26:in `block
(2 levels) in <top (required)>'

  -- Michal

> From: David Lutterkort <lutter@redhat.com>
> 
> ---
> 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      |   11 +--
> server/lib/cimi/models/entity_metadata.rb        |   83 ---------------------
> server/lib/cimi/models/machine.rb                |    6 +-
> server/lib/cimi/models/resource_metadata.rb      |   85 ++++++++++++++++++++++
> 7 files changed, 138 insertions(+), 142 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
> 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 a81abff..e0a9544 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..38b5a88 100644
> --- a/server/lib/cimi/models/cloud_entry_point.rb
> +++ b/server/lib/cimi/models/cloud_entry_point.rb
> @@ -17,18 +17,13 @@ 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
> 
> @@ -46,8 +41,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/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
> 


Mime
View raw message