deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Koper, Dies" <di...@fast.au.fujitsu.com>
Subject RE: [PATCH 3/8] CIMI collections: create embedded collections within their containing classes
Date Sat, 10 Nov 2012 02:18:29 GMT
Hi David,

Not sure if it's this patch, but I'm seeing the following warning now
when I start deltacloud:

d:/sources/OSS/cloud/deltacloud/server/lib/cimi/models/collection.rb:79:
warning: already initialized constant NetworkPortCollection

Regards,
Dies Koper



> -----Original Message-----
> From: lutter@redhat.com [mailto:lutter@redhat.com]
> Sent: Friday, 9 November 2012 3:19 PM
> To: dev@deltacloud.apache.org
> Subject: [PATCH 3/8] CIMI collections: create embedded collections
within their
> containing classes
> 
> From: David Lutterkort <lutter@redhat.com>
> 
> We had two NetworkPortCollections: one being the toplevel one, the
other
> being the collection of ports within a Network. Both classes were
being
> generated as CIMI::Model::NetworkPortCollection.
> 
> This changes it so that the toplevel collection will be
> CIMI::Model::NetworkPortCollection, while the other will be
> CIMI::Model::Network::NetworPortCollection.
> 
> This double-defining of CIMI::Model::NetworkPortCollection caused
server
> errors when retrieving the toplevel NetworkPortCollection
> ---
>  server/lib/cimi/models/collection.rb |    3 ++-
>  server/lib/cimi/models/schema.rb     |    6 +++++-
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/server/lib/cimi/models/collection.rb
> b/server/lib/cimi/models/collection.rb
> index 70692ca..c7f3b21 100644
> --- a/server/lib/cimi/models/collection.rb
> +++ b/server/lib/cimi/models/collection.rb
> @@ -75,8 +75,9 @@ module CIMI::Model
> 
>      def self.generate(model_class, opts = {})
>        model_name = model_class.name.split("::").last
> +      scope = opts[:scope] || CIMI::Model
>        coll_class = Class.new(CIMI::Model::Collection)
> -      CIMI::Model.const_set(:"#{model_name}Collection", coll_class)
> +      scope.const_set(:"#{model_name}Collection", coll_class)
>        coll_class.entry_name = model_name.underscore.pluralize.to_sym
>        coll_class.embedded = opts[:embedded]
>        entry_schema = model_class.schema
> diff --git a/server/lib/cimi/models/schema.rb
> b/server/lib/cimi/models/schema.rb
> index fe4ed07..115e236 100644
> --- a/server/lib/cimi/models/schema.rb
> +++ b/server/lib/cimi/models/schema.rb
> @@ -218,11 +218,14 @@ class CIMI::Model::Schema
> 
>    class Collection < Attribute
>      def initialize(name, opts = {})
> +      params = {}
> +      params[:scope] = opts.delete(:scope)
>        super(name, opts)
>        unless opts[:class]
>          raise "Specify the class of collection entries using :class"
>        end
> -      @collection_class =
> CIMI::Model::Collection.generate(opts[:class], :embedded => true)
> +      params[:embedded] = true
> +      @collection_class =
CIMI::Model::Collection.generate(opts[:class], params)
>      end
> 
>      def from_xml(xml, model)
> @@ -354,6 +357,7 @@ class CIMI::Model::Schema
>      end
> 
>      def collection(name, opts={})
> +      opts[:scope] = self.class
>        add_attributes!([name, opts], Collection)
>      end
>    end
> --
> 1.7.7.6
> 



Mime
View raw message