You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2012/11/09 05:18:42 UTC
[PATCH 3/8] CIMI collections: create embedded collections within their containing classes
From: David Lutterkort <lu...@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
RE: [PATCH 3/8] CIMI collections: create embedded collections within their containing classes
Posted by "Koper, Dies" <di...@fast.au.fujitsu.com>.
Hi David,
I can't reproduce it anymore so you're probably right. Sorry for the
noise.
> Can you get /cimi/network_ports on your server ?
Yes.
Regards,
Dies Koper
> -----Original Message-----
> From: David Lutterkort [mailto:lutter@redhat.com]
> Sent: Saturday, 10 November 2012 3:48 PM
> To: dev@deltacloud.apache.org
> Subject: RE: [PATCH 3/8] CIMI collections: create embedded collections
within
> their containing classes
>
> On Sat, 2012-11-10 at 13:18 +1100, Koper, Dies wrote:
> > 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
>
> Are you sure you're running with that patch ? Because that's the one
> that should have gotten rid of the warning (the warning was the reason
> why I did that)
>
> Can you get /cimi/network_ports on your server ?
>
> David
>
>
RE: [PATCH 3/8] CIMI collections: create embedded collections
within their containing classes
Posted by David Lutterkort <lu...@redhat.com>.
On Sat, 2012-11-10 at 13:18 +1100, Koper, Dies wrote:
> 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
Are you sure you're running with that patch ? Because that's the one
that should have gotten rid of the warning (the warning was the reason
why I did that)
Can you get /cimi/network_ports on your server ?
David
RE: [PATCH 3/8] CIMI collections: create embedded collections within their containing classes
Posted by "Koper, Dies" <di...@fast.au.fujitsu.com>.
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 <lu...@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
>