You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/11/22 14:26:02 UTC

[PATCH core 1/3] CIMI: Fixed inheriting schema properties in various models problem

From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/cimi/model/base.rb |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/server/lib/cimi/model/base.rb b/server/lib/cimi/model/base.rb
index 7cc3f49..8218fac 100644
--- a/server/lib/cimi/model/base.rb
+++ b/server/lib/cimi/model/base.rb
@@ -77,20 +77,35 @@ class CIMI::Model::Base
   # attribute, we also define a getter and a setter to access/change the
   # value for that attribute
   class << self
-    def schema
+    def base_schema
       @schema ||= CIMI::Model::Schema.new
     end
 
-    def schema=(s)
-      @schema = s
+    def clone_base_schema
+      @schema_duped = true
+      @schema = Marshal::load(Marshal.dump(superclass.base_schema))
     end
 
+    def base_schema_cloned?
+      @schema_duped
+    end
+
+    private :'clone_base_schema', :'base_schema_cloned?'
+
     def inherited(child)
-      child.schema = self.schema.dup
+      child.instance_eval do
+        def schema
+          base_schema_cloned? ? @schema : clone_base_schema
+        end
+      end
     end
 
     def add_attributes!(names, attr_klass, &block)
-      schema.add_attributes!(names, attr_klass, &block)
+      if self.respond_to? :schema
+        schema.add_attributes!(names, attr_klass, &block)
+      else
+        base_schema.add_attributes!(names, attr_klass, &block)
+      end
       names.each do |name|
         define_method(name) { @attribute_values[name] }
         define_method(:"#{name}=") { |newval| @attribute_values[name] = newval }
-- 
1.7.4.4


[PATCH core 2/3] CIMI: Added test to machine_spec to check if Machine schema hold only Machin attributes (inheritation works ;)

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/spec/cimi/model/machine_spec.rb |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/server/spec/cimi/model/machine_spec.rb b/server/spec/cimi/model/machine_spec.rb
index d50b078..f1ee296 100644
--- a/server/spec/cimi/model/machine_spec.rb
+++ b/server/spec/cimi/model/machine_spec.rb
@@ -20,6 +20,11 @@ describe "Machine model" do
     @json = IO::read(File::join(DATA_DIR, "machine.json"))
   end
 
+  it "should hold just machine schema" do
+    CIMI::Model::Machine.schema.attribute_names.should_not include(:image_location)
+    CIMI::Model::Machine.schema.attribute_names.should include(:meters)
+  end
+
   it "can be constructed from XML" do
     machine = CIMI::Model::Machine.from_xml(@xml)
     machine.should_not be_nil
-- 
1.7.4.4


Re: [PATCH core 1/3] CIMI: Fixed inheriting schema properties in various models problem

Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK to all 3 patches


On 22/11/11 15:26, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
>  server/lib/cimi/model/base.rb |   25 ++++++++++++++++++++-----
>  1 files changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/server/lib/cimi/model/base.rb b/server/lib/cimi/model/base.rb
> index 7cc3f49..8218fac 100644
> --- a/server/lib/cimi/model/base.rb
> +++ b/server/lib/cimi/model/base.rb
> @@ -77,20 +77,35 @@ class CIMI::Model::Base
>    # attribute, we also define a getter and a setter to access/change the
>    # value for that attribute
>    class << self
> -    def schema
> +    def base_schema
>        @schema ||= CIMI::Model::Schema.new
>      end
>  
> -    def schema=(s)
> -      @schema = s
> +    def clone_base_schema
> +      @schema_duped = true
> +      @schema = Marshal::load(Marshal.dump(superclass.base_schema))
>      end
>  
> +    def base_schema_cloned?
> +      @schema_duped
> +    end
> +
> +    private :'clone_base_schema', :'base_schema_cloned?'
> +
>      def inherited(child)
> -      child.schema = self.schema.dup
> +      child.instance_eval do
> +        def schema
> +          base_schema_cloned? ? @schema : clone_base_schema
> +        end
> +      end
>      end
>  
>      def add_attributes!(names, attr_klass, &block)
> -      schema.add_attributes!(names, attr_klass, &block)
> +      if self.respond_to? :schema
> +        schema.add_attributes!(names, attr_klass, &block)
> +      else
> +        base_schema.add_attributes!(names, attr_klass, &block)
> +      end
>        names.each do |name|
>          define_method(name) { @attribute_values[name] }
>          define_method(:"#{name}=") { |newval| @attribute_values[name] = newval }


[PATCH core 3/3] CIMI: Added missing :operations attribute to Volume schema

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/cimi/model/volume.rb |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/server/lib/cimi/model/volume.rb b/server/lib/cimi/model/volume.rb
index b83fcc3..ed80903 100644
--- a/server/lib/cimi/model/volume.rb
+++ b/server/lib/cimi/model/volume.rb
@@ -28,4 +28,7 @@ class CIMI::Model::Volume < CIMI::Model::Base
     scalar :ref
   end
   scalar :eventlog
+  array :operations do
+    scalar :rel, :href
+  end
 end
-- 
1.7.4.4