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/14 16:09:26 UTC

More CIMI models

Hi,

This patches should add MachineImage and MachineConfiguration to new CIMI
object model.

There are few 'todo' items:

1. The '.properties/.property' is not correctly parsed when importing from JSON
2. In CIMI specification there is no indication about how property value should
   be stored. I assume that there will be a key called 'value' in JSON hash
3. The 'memory' property is reported as Array in XML and as single item in JSON

Also one issue which I didn't get:

class MachineImage
  scalar :image_location
end

img.image_location[0]['href'].should == 'nfs://cimi.example.com/images/1.img'

Is 'scalar' automatically being converted to an Array?

Thanks,

 -- Michal



Re: More CIMI models

Posted by David Lutterkort <lu...@redhat.com>.
On Mon, 2011-11-14 at 16:09 +0100, mfojtik@redhat.com wrote:
> There are few 'todo' items:
> 
> 1. The '.properties/.property' is not correctly parsed when importing from JSON
> 2. In CIMI specification there is no indication about how property value should
>    be stored. I assume that there will be a key called 'value' in JSON hash

The latest clarificatin in th espec is that the XML

        <property key="prop1">value1</property>
        <property key="prop2">value2</property>
        
gets turned into JSON as

    { "prop1": "value1", "prop2": "value2" }
  
> 3. The 'memory' property is reported as Array in XML and as single item in JSON

Seems like a bug somewhere.

> Also one issue which I didn't get:
> 
> class MachineImage
>   scalar :image_location
> end
> 
> img.image_location[0]['href'].should == 'nfs://cimi.example.com/images/1.img'

Weird, that shouldn't be turned into an array. It would be better to
write that as 'href :image_location' though; that makes sure you can say
        img.image_location.href.should == url

David



Re: [PATCH core 2/5] CIMI: Updated RSpec to 2.0

Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK

On 14/11/11 17:09, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
>  server/Rakefile                                 |    7 ++++---
>  server/spec/cimi/model/machine_template_spec.rb |    7 -------
>  server/spec/cimi/model/schema_spec.rb           |    4 ----
>  server/spec/spec_helper.rb                      |    5 ++++-
>  4 files changed, 8 insertions(+), 15 deletions(-)
> 
> diff --git a/server/Rakefile b/server/Rakefile
> index 0ceaf9d..9436518 100644
> --- a/server/Rakefile
> +++ b/server/Rakefile
> @@ -20,7 +20,7 @@
>  require 'rake'
>  require 'rake/testtask'
>  require 'rubygems/package_task'
> -require 'spec/rake/spectask'
> +require 'rspec/core/rake_task'
>  
>  begin
>    require 'ci/reporter/rake/test_unit'
> @@ -90,8 +90,9 @@ task :cucumber do
>    end
>  end
>  
> -Spec::Rake::SpecTask.new('spec') do |t|
> -  t.spec_files = FileList['spec/**/*_spec.rb']
> +RSpec::Core::RakeTask.new do |t|
> +  t.pattern = FileList['spec/**/*_spec.rb']
> +  t.rspec_opts = [ "--format", "nested", "--color", "-r ./spec/spec_helper.rb"]
>  end
>  
>  begin
> diff --git a/server/spec/cimi/model/machine_template_spec.rb b/server/spec/cimi/model/machine_template_spec.rb
> index d7028a6..57895c9 100644
> --- a/server/spec/cimi/model/machine_template_spec.rb
> +++ b/server/spec/cimi/model/machine_template_spec.rb
> @@ -13,15 +13,8 @@
>  # License for the specific language governing permissions and limitations
>  # under the License.
>  #
> -
> -require 'spec_helper'
> -
> -require 'cimi/model'
> -
>  describe "MachineTemplate model" do
>  
> -  DATA_DIR = File::join(File::dirname(__FILE__), '..', 'data')
> -
>    before(:all) do
>      @xml = IO::read(File::join(DATA_DIR, "machine_template.xml"))
>      @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
> diff --git a/server/spec/cimi/model/schema_spec.rb b/server/spec/cimi/model/schema_spec.rb
> index 0b262f4..9fd4338 100644
> --- a/server/spec/cimi/model/schema_spec.rb
> +++ b/server/spec/cimi/model/schema_spec.rb
> @@ -14,10 +14,6 @@
>  # under the License.
>  #
>  
> -require 'spec_helper'
> -
> -require 'cimi/model'
> -
>  describe "Schema" do
>    before(:each) do
>      @schema = CIMI::Model::Schema.new
> diff --git a/server/spec/spec_helper.rb b/server/spec/spec_helper.rb
> index d9a51f5..d046260 100644
> --- a/server/spec/spec_helper.rb
> +++ b/server/spec/spec_helper.rb
> @@ -16,10 +16,13 @@
>  
>  require 'rubygems'
>  require 'pp'
> -
> +require 'rspec'
>  require 'deltacloud/core_ext'
> +require 'cimi/model'
>  require 'xmlsimple'
>  
> +DATA_DIR = File::join(File::expand_path(File::dirname(__FILE__)), 'cimi', 'data')
> +
>  def parse_xml(xml, opts = {})
>    opts[:force_content] = true
>    opts[:keep_root] = true unless opts.has_key?(:keep_root)


Re: [PATCH core 2/5] CIMI: Updated RSpec to 2.0

Posted by David Lutterkort <lu...@redhat.com>.
On Mon, 2011-11-14 at 16:09 +0100, mfojtik@redhat.com wrote:

> diff --git a/server/spec/cimi/model/machine_template_spec.rb b/server/spec/cimi/model/machine_template_spec.rb
> index d7028a6..57895c9 100644
> --- a/server/spec/cimi/model/machine_template_spec.rb
> +++ b/server/spec/cimi/model/machine_template_spec.rb
> @@ -13,15 +13,8 @@
>  # License for the specific language governing permissions and limitations
>  # under the License.
>  #
> -
> -require 'spec_helper'

Doesn't this break running specs with rspec directly ? It's much quicker
to run 'rspec -l 17 spec/cimi/model/schema_spec.rb' than to run
everything through rake.

David



[PATCH core 2/5] CIMI: Updated RSpec to 2.0

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


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/Rakefile                                 |    7 ++++---
 server/spec/cimi/model/machine_template_spec.rb |    7 -------
 server/spec/cimi/model/schema_spec.rb           |    4 ----
 server/spec/spec_helper.rb                      |    5 ++++-
 4 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/server/Rakefile b/server/Rakefile
index 0ceaf9d..9436518 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -20,7 +20,7 @@
 require 'rake'
 require 'rake/testtask'
 require 'rubygems/package_task'
-require 'spec/rake/spectask'
+require 'rspec/core/rake_task'
 
 begin
   require 'ci/reporter/rake/test_unit'
@@ -90,8 +90,9 @@ task :cucumber do
   end
 end
 
-Spec::Rake::SpecTask.new('spec') do |t|
-  t.spec_files = FileList['spec/**/*_spec.rb']
+RSpec::Core::RakeTask.new do |t|
+  t.pattern = FileList['spec/**/*_spec.rb']
+  t.rspec_opts = [ "--format", "nested", "--color", "-r ./spec/spec_helper.rb"]
 end
 
 begin
diff --git a/server/spec/cimi/model/machine_template_spec.rb b/server/spec/cimi/model/machine_template_spec.rb
index d7028a6..57895c9 100644
--- a/server/spec/cimi/model/machine_template_spec.rb
+++ b/server/spec/cimi/model/machine_template_spec.rb
@@ -13,15 +13,8 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 #
-
-require 'spec_helper'
-
-require 'cimi/model'
-
 describe "MachineTemplate model" do
 
-  DATA_DIR = File::join(File::dirname(__FILE__), '..', 'data')
-
   before(:all) do
     @xml = IO::read(File::join(DATA_DIR, "machine_template.xml"))
     @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
diff --git a/server/spec/cimi/model/schema_spec.rb b/server/spec/cimi/model/schema_spec.rb
index 0b262f4..9fd4338 100644
--- a/server/spec/cimi/model/schema_spec.rb
+++ b/server/spec/cimi/model/schema_spec.rb
@@ -14,10 +14,6 @@
 # under the License.
 #
 
-require 'spec_helper'
-
-require 'cimi/model'
-
 describe "Schema" do
   before(:each) do
     @schema = CIMI::Model::Schema.new
diff --git a/server/spec/spec_helper.rb b/server/spec/spec_helper.rb
index d9a51f5..d046260 100644
--- a/server/spec/spec_helper.rb
+++ b/server/spec/spec_helper.rb
@@ -16,10 +16,13 @@
 
 require 'rubygems'
 require 'pp'
-
+require 'rspec'
 require 'deltacloud/core_ext'
+require 'cimi/model'
 require 'xmlsimple'
 
+DATA_DIR = File::join(File::expand_path(File::dirname(__FILE__)), 'cimi', 'data')
+
 def parse_xml(xml, opts = {})
   opts[:force_content] = true
   opts[:keep_root] = true unless opts.has_key?(:keep_root)
-- 
1.7.4.4


Re: More CIMI models

Posted by Tong Li <li...@us.ibm.com>.
Tong Li
Emerging Technologies & Standards
Building 501/B205
litong01@us.ibm.com

mfojtik@redhat.com wrote on 11/14/2011 10:09:26 AM:

> From: mfojtik@redhat.com
> To: deltacloud-dev@incubator.apache.org
> Date: 11/14/2011 10:14 AM
> Subject: More CIMI models
>
> Hi,
>
> This patches should add MachineImage and MachineConfiguration to new CIMI
> object model.
>
> There are few 'todo' items:
>
> 1. The '.properties/.property' is not correctly parsed when
> importing from JSON
> 2. In CIMI specification there is no indication about how property
> value should
>    be stored. I assume that there will be a key called 'value' in JSON
hash
It should be in a format of this
	"something":"the actual value"

It won't be something like
	"something" : {"value": "the actual value", "something else like
attributes"}

> 3. The 'memory' property is reported as Array in XML and as single
> item in JSON

Yes, that is the inconsistency of the spec. wished that it was not
specified like that.

>
> Also one issue which I didn't get:
>
> class MachineImage
>   scalar :image_location
> end
>
> img.image_location[0]['href'].should ==
'nfs://cimi.example.com/images/1.img'
>
> Is 'scalar' automatically being converted to an Array?
>
> Thanks,
>
>  -- Michal
>
>

Re: [PATCH core 4/5] CIMI: Added MachineConfiguration model

Posted by David Lutterkort <lu...@redhat.com>.
On Mon, 2011-11-14 at 16:09 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---

> diff --git a/server/lib/cimi/model/machine_configuration.rb b/server/lib/cimi/model/machine_configuration.rb
> new file mode 100644
> index 0000000..221236c
> --- /dev/null
> +++ b/server/lib/cimi/model/machine_configuration.rb
> @@ -0,0 +1,28 @@

> +class CIMI::Model::MachineConfiguration < CIMI::Model::Base
> +
> +  scalar :memory

Model that as
        struct :memory do
                scalar :quantity
                scalar :units
        end

> +  text :cpu
> +
> +  array :disk do
> +    scalar :capacity
> +  end

That has to be _disks_; the convention is that arrays always use
pluralized names, i.e. the name that is used in JSON. In fact, the whole
exercise of the model layer is to create Ruby objects that you can talk
to as if you were in JavaScript and had just deserialized the JSON form
of the object.

One general remark about specs: we should have the following roundtrip
test for everything

        Model.from_xml(xml).to_xml.should serialize_to xml
        Model.from_json(json).to_json.should serialize_to json
        Model.from_xml(xml).to_json.should serialize_to json
        Model.from_json(json).to_xml.should serialize_to xml

The last two should help us catch inconsistencies in how we treat XML
vs. JSON (and I know that you have been writing the first two kinds of
tests)

The above four tests can be hidden in a helper

        def check_serialization(model_class, xml, json)
        
David



Re: [PATCH core 4/5] CIMI: Added MachineConfiguration model

Posted by "marios@redhat.com" <ma...@redhat.com>.
minor comment inline (otherwise ACK):

On 14/11/11 17:09, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> +# 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::MachineConfiguration < CIMI::Model::Base
> +
> +  scalar :memory
> +  text :cpu
> +
> +  array :disk do
> +    scalar :capacity

also, :format and :attachment_point

> +  end
> +
> +  array :operations do
> +    scalar :rel, :href
> +  end
> +end
> diff --git a/server/spec/cimi/data/machine_configuration.json b/server/spec/cimi/data/machine_configuration.json
> new file mode 100644
> index 0000000..8864340
> --- /dev/null
> +++ b/server/spec/cimi/data/machine_configuration.json
> @@ -0,0 +1,17 @@
> +{
> +  "uri": "http://cimi.example.org/machine_configurations/1",
> +  "name": "MachineConfiguration1",
> +  "description": "Example MachineConfiguration One",
> +  "created": "2011-11-14",
> +  "cpu": "2",
> +  "memory" : { "quantity": "1", "units": "gigabyte" },
> +  "disks" : [
> +    { "capacity": { "quantity": "1", "units": "terabyte", "format": "ext4", "attachmentPoint": "/" } }
> +  ],

I think this will be:

"disks" : [
	    { "capacity": { "quantity": "1", "units": "terabyte"}},
	    {"format": "ext4"}, {"attachmentPoint": "/" }
> +  ],

> +  "properties": [ { "name": "architectore", "value" : "i386" } ],
> +  "operations": [
> +    { "rel": "edit",
> +      "href": "http://cimi.example.org/machine_images/1/edit" },
> +    { "rel": "delete",
> +      "href": "http://cimi.example.org/machine_images/1/delete" }]
> +}
> diff --git a/server/spec/cimi/data/machine_configuration.xml b/server/spec/cimi/data/machine_configuration.xml
> new file mode 100644
> index 0000000..788a185
> --- /dev/null
> +++ b/server/spec/cimi/data/machine_configuration.xml
> @@ -0,0 +1,14 @@
> +<MachineConfiguration xmlns="http://www.dmtf.org/cimi">
> +  <uri>http://cimi.example.org/machine_configurations/1</uri>
> +  <name>MachineConfiguration1</name>
> +  <description>Example MachineConfiguration One</description>
> +  <created>2011-11-14</created>
> +  <property name="architecture">i386</property>
> +  <cpu>2</cpu>
> +  <memory quantity="1" units="gigabyte"/>
> +  <disk>
> +    <capacity quantity="1" units="terabyte" format="ext4" attachmentPoint="/"/>
> +  </disk>

again, I think its:

<disk>
  <capacity quantity="1" units="terabyte"/>
  <format="ext4"/>
  <attachmentPoint="/"/>
</disk>


I should raise a mantis issue since I can't see this in any of the
examples, even though :format and :attachmentPoint are mandatory.

[PATCH core 4/5] CIMI: Added MachineConfiguration model

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


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/cimi/model/machine_configuration.rb     |   28 +++++++
 server/spec/cimi/data/machine_configuration.json   |   17 ++++
 server/spec/cimi/data/machine_configuration.xml    |   14 ++++
 .../spec/cimi/model/machine_configuration_spec.rb  |   78 ++++++++++++++++++++
 4 files changed, 137 insertions(+), 0 deletions(-)
 create mode 100644 server/lib/cimi/model/machine_configuration.rb
 create mode 100644 server/spec/cimi/data/machine_configuration.json
 create mode 100644 server/spec/cimi/data/machine_configuration.xml
 create mode 100644 server/spec/cimi/model/machine_configuration_spec.rb

diff --git a/server/lib/cimi/model/machine_configuration.rb b/server/lib/cimi/model/machine_configuration.rb
new file mode 100644
index 0000000..221236c
--- /dev/null
+++ b/server/lib/cimi/model/machine_configuration.rb
@@ -0,0 +1,28 @@
+# 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::MachineConfiguration < CIMI::Model::Base
+
+  scalar :memory
+  text :cpu
+
+  array :disk do
+    scalar :capacity
+  end
+
+  array :operations do
+    scalar :rel, :href
+  end
+end
diff --git a/server/spec/cimi/data/machine_configuration.json b/server/spec/cimi/data/machine_configuration.json
new file mode 100644
index 0000000..8864340
--- /dev/null
+++ b/server/spec/cimi/data/machine_configuration.json
@@ -0,0 +1,17 @@
+{
+  "uri": "http://cimi.example.org/machine_configurations/1",
+  "name": "MachineConfiguration1",
+  "description": "Example MachineConfiguration One",
+  "created": "2011-11-14",
+  "cpu": "2",
+  "memory" : { "quantity": "1", "units": "gigabyte" },
+  "disks" : [
+    { "capacity": { "quantity": "1", "units": "terabyte", "format": "ext4", "attachmentPoint": "/" } }
+  ],
+  "properties": [ { "name": "architectore", "value" : "i386" } ],
+  "operations": [
+    { "rel": "edit",
+      "href": "http://cimi.example.org/machine_images/1/edit" },
+    { "rel": "delete",
+      "href": "http://cimi.example.org/machine_images/1/delete" }]
+}
diff --git a/server/spec/cimi/data/machine_configuration.xml b/server/spec/cimi/data/machine_configuration.xml
new file mode 100644
index 0000000..788a185
--- /dev/null
+++ b/server/spec/cimi/data/machine_configuration.xml
@@ -0,0 +1,14 @@
+<MachineConfiguration xmlns="http://www.dmtf.org/cimi">
+  <uri>http://cimi.example.org/machine_configurations/1</uri>
+  <name>MachineConfiguration1</name>
+  <description>Example MachineConfiguration One</description>
+  <created>2011-11-14</created>
+  <property name="architecture">i386</property>
+  <cpu>2</cpu>
+  <memory quantity="1" units="gigabyte"/>
+  <disk>
+    <capacity quantity="1" units="terabyte" format="ext4" attachmentPoint="/"/>
+  </disk>
+  <operation rel="edit" href="http://cimi.example.org/machine_configurations/1/edit"/>
+  <operation rel="delete" href="http://cimi.example.org/machine_configurations/1/delete"/>
+</MachineConfiguration>
diff --git a/server/spec/cimi/model/machine_configuration_spec.rb b/server/spec/cimi/model/machine_configuration_spec.rb
new file mode 100644
index 0000000..f17c69b
--- /dev/null
+++ b/server/spec/cimi/model/machine_configuration_spec.rb
@@ -0,0 +1,78 @@
+# 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.
+#
+describe "MachineConfiguration model" do
+
+  before(:all) do
+    @xml = IO::read(File::join(DATA_DIR, "machine_configuration.xml"))
+    @json = IO::read(File::join(DATA_DIR, "machine_configuration.json"))
+  end
+
+  it "can be constructed from XML" do
+    conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
+    conf.should_not be_nil
+    conf.name.should == 'MachineConfiguration1'
+    conf.uri == 'http://cimi.example.org/machine_configurations/1'
+    conf.description == 'Example MachineConfiguration One'
+    conf.created.should == "2011-11-14"
+    conf.cpu.should == "2"
+    conf.memory.size.should == 1
+    conf.memory[0]['quantity'].should == '1'
+    conf.memory[0]['units'].should == 'gigabyte'
+    conf.disk.size.should == 1
+    conf.disk[0].respond_to?(:capacity).should be_true
+    conf.disk[0].capacity.size.should == 1
+    conf.disk[0].capacity[0]['format'] == 'ext4'
+    conf.disk[0].capacity[0]['quantity'] == '1'
+    conf.disk[0].capacity[0]['attachmentPoint'] == '/'
+    conf.disk[0].capacity[0]['units'] == 'terabyte'
+    conf.operations.size.should == 2
+    conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
+    conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
+    conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
+    conf.should serialize_to @xml, :fmt => :xml
+  end
+
+  it "should convert strings in keys to symbols when contructed from XML" do
+    conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
+    conf.should_not be_nil
+    conf.attribute_values.keys.each { |key| key.should be_a(Symbol) }
+  end
+
+  it "can be constructed from JSON" do
+    conf = CIMI::Model::MachineConfiguration.from_json(@json)
+    conf.should_not be_nil
+    conf.name.should == 'MachineConfiguration1'
+    conf.uri == 'http://cimi.example.org/machine_configurations/1'
+    conf.description == 'Example MachineConfiguration One'
+    conf.created.should == "2011-11-14"
+    conf.cpu.should == "2"
+    conf.memory.size.should == 1
+    conf.memory[0]['quantity'].should == '1'
+    conf.memory[0]['units'].should == 'gigabyte'
+    conf.disk.size.should == 1
+    conf.disk[0].respond_to?(:capacity).should be_true
+    conf.disk[0].capacity.size.should == 1
+    conf.disk[0].capacity[0]['format'] == 'ext4'
+    conf.disk[0].capacity[0]['quantity'] == '1'
+    conf.disk[0].capacity[0]['attachmentPoint'] == '/'
+    conf.disk[0].capacity[0]['units'] == 'terabyte'
+    conf.operations.size.should == 2
+    conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
+    conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
+    conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
+    conf.should serialize_to @json, :fmt => :json
+  end
+end
-- 
1.7.4.4


Re: [PATCH core 5/5] CIMI: Registred new model in model.rb. Small bugfix in machine_image JSON

Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK

On 14/11/11 17:09, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
>  server/lib/cimi/model.rb                 |    2 ++
>  server/spec/cimi/data/machine_image.json |   13 +++++++------
>  2 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/server/lib/cimi/model.rb b/server/lib/cimi/model.rb
> index fcc6e17..1e4a34a 100644
> --- a/server/lib/cimi/model.rb
> +++ b/server/lib/cimi/model.rb
> @@ -23,3 +23,5 @@ end
>  require 'cimi/model/schema'
>  require 'cimi/model/base'
>  require 'cimi/model/machine_template'
> +require 'cimi/model/machine_image'
> +require 'cimi/model/machine_configuration'
> diff --git a/server/spec/cimi/data/machine_image.json b/server/spec/cimi/data/machine_image.json
> index e037144..8b1f476 100644
> --- a/server/spec/cimi/data/machine_image.json
> +++ b/server/spec/cimi/data/machine_image.json
> @@ -3,11 +3,12 @@
>    "name": "My First image",
>    "description": "A image for testing",
>    "created": "2011-11-14",
> -  "imageLocation": { "href": "nfs://cimi.example.com/images/1.img"}
> -  "properties": [ {"name": "status", "value": "build"}, { "name": "locked", "value": "true" } ]
> +  "imageLocation": { "href": "nfs://cimi.example.com/images/1.img" },
> +  "properties": [ { "name": "status", "value": "build"}, { "name": "locked", "value": "true" } ],
>    "operations": [
> -    { "rel": "edit",
> -      "href": "http://cimi.example.org/machine_images/1/edit" },
> -    { "rel": "delete",
> -      "href": "http://cimi.example.org/machine_images/1/delete" }]
> +  { "rel": "edit",
> +    "href": "http://cimi.example.org/machine_images/1/edit" },
> +  { "rel": "delete",
> +    "href": "http://cimi.example.org/machine_images/1/delete" }
> +  ]
>  }


[PATCH core 5/5] CIMI: Registred new model in model.rb. Small bugfix in machine_image JSON

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


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/cimi/model.rb                 |    2 ++
 server/spec/cimi/data/machine_image.json |   13 +++++++------
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/server/lib/cimi/model.rb b/server/lib/cimi/model.rb
index fcc6e17..1e4a34a 100644
--- a/server/lib/cimi/model.rb
+++ b/server/lib/cimi/model.rb
@@ -23,3 +23,5 @@ end
 require 'cimi/model/schema'
 require 'cimi/model/base'
 require 'cimi/model/machine_template'
+require 'cimi/model/machine_image'
+require 'cimi/model/machine_configuration'
diff --git a/server/spec/cimi/data/machine_image.json b/server/spec/cimi/data/machine_image.json
index e037144..8b1f476 100644
--- a/server/spec/cimi/data/machine_image.json
+++ b/server/spec/cimi/data/machine_image.json
@@ -3,11 +3,12 @@
   "name": "My First image",
   "description": "A image for testing",
   "created": "2011-11-14",
-  "imageLocation": { "href": "nfs://cimi.example.com/images/1.img"}
-  "properties": [ {"name": "status", "value": "build"}, { "name": "locked", "value": "true" } ]
+  "imageLocation": { "href": "nfs://cimi.example.com/images/1.img" },
+  "properties": [ { "name": "status", "value": "build"}, { "name": "locked", "value": "true" } ],
   "operations": [
-    { "rel": "edit",
-      "href": "http://cimi.example.org/machine_images/1/edit" },
-    { "rel": "delete",
-      "href": "http://cimi.example.org/machine_images/1/delete" }]
+  { "rel": "edit",
+    "href": "http://cimi.example.org/machine_images/1/edit" },
+  { "rel": "delete",
+    "href": "http://cimi.example.org/machine_images/1/delete" }
+  ]
 }
-- 
1.7.4.4


Re: [PATCH core 3/5] CIMI: Added MachineImage model

Posted by Michal Fojtik <mf...@redhat.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

marios@redhat.com wrote:

> minor comments inline (otherwise ACK):

Thanks!

> 
> On 14/11/11 17:09, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mf...@redhat.com> +# 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::MachineImage < CIMI::Model::Base + +  scalar
>> :image_location
> 
> could also have :image_data instead of :image_location (either-or,
> but not both)... :image_data is a byte array, but represented as
> string in json and xml, so scalar?
> 
> JSON: "imageData": string, ? XML: <imageData> xs:string </imageData>
> ?

Yes, that's right. I'll add this before push. Thanks!

>> + +  array :operations do +    scalar :rel, :href +  end +end diff
>> --git a/server/spec/cimi/data/machine_image.json
>> b/server/spec/cimi/data/machine_image.json new file mode 100644 
>> index 0000000..e037144 --- /dev/null +++
>> b/server/spec/cimi/data/machine_image.json @@ -0,0 +1,13 @@ +{ +
>> "uri": "http://cimi.example.org/machine_images/1", +  "name": "My
>> First image", +  "description": "A image for testing", +
>> "created": "2011-11-14", +  "imageLocation": { "href":
>> "nfs://cimi.example.com/images/1.img"} +  "properties": [ {"name":
>> "status", "value": "build"}, { "name": "locked", "value": "true" }
>> ]
> 
> I think this is gonna be more like
> 
> +  "properties": [ {"status": "build", "locked": "true" } ]

Right, I misinterpreted the example from spec. Will fix it before commit.


>> +  "operations": [ +    { "rel": "edit", +      "href":
>> "http://cimi.example.org/machine_images/1/edit" }, +    { "rel":
>> "delete", +      "href":
>> "http://cimi.example.org/machine_images/1/delete" }] +} diff --git
>> a/server/spec/cimi/data/machine_image.xml
>> b/server/spec/cimi/data/machine_image.xml new file mode 100644 
>> index 0000000..a02bc36 --- /dev/null +++
>> b/server/spec/cimi/data/machine_image.xml @@ -0,0 +1,11 @@ 
>> +<MachineImage xmlns="http://www.dmtf.org/cimi"> +
>> <uri>http://cimi.example.org/machine_image/1</uri> +
>> <name>img1</name> +  <description>Machine Image One</description> +
>> <created>2011-11-14</created> +  <property
>> name="status">BUILD</property> +  <property
>> name="locked">true</property>
> 
> properties are (for now :) ) :key="status" instead of :name
> 
> <property key="xs:string"> xs:string </property> *

I hope this is the same thing as above.

> 
>> +  <imageLocation href="nfs://cimi.example.com/images/1.img"/> +
>> <operation rel="edit"
>> href="http://cimi.example.org/machine_image/1/edit"/> +  <operation
>> rel="delete"
>> href="http://cimi.example.org/machine_image/1/delete"/> 
>> +</MachineImage>

- -- 
- --
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOw6MsAAoJEEnFpmY+LvFRocEH/AnxwD16ksTv6DoGfYKr3Ahd
8eE5YUMCw5w1PMkiDlmQmkXqsfAQ1GFf4Uj55EFNqvhOdyCgVJG0Et1TLN7blZtW
Q3iW/DKktLLS7Us3zGlx+DT+LEaWUrYKKMn2E8mHsL9lS5mjVHI0GoGCNg/pUR3w
LCS4q1rfBsYm9M3bokAQs/SXMIUjYzW7SidIy+dUQS+D9WBpjkgiyuubRuhd98XV
D0u6Z9BWJWM2eGELSOKvBmCue+ZEepronFrshxhyIxnX1ZTHVtr/U6rJ0u2v5o64
sidzUeLZPXG3TsNFS5rprO0gl6i7tLq4HvrCc2AzA2bVGVKffGwCXGkvE2GkR3k=
=nhcC
-----END PGP SIGNATURE-----

Re: [PATCH core 3/5] CIMI: Added MachineImage model

Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2011-11-16 at 13:21 +0200, marios@redhat.com wrote:
> minor comments inline (otherwise ACK):
> 
> On 14/11/11 17:09, mfojtik@redhat.com wrote:
> > From: Michal Fojtik <mf...@redhat.com>
> > +# 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::MachineImage < CIMI::Model::Base
> > +
> > +  scalar :image_location
> 
> could also have :image_data instead of :image_location (either-or, but
> not both)... :image_data is a byte array, but represented as string in
> json and xml, so scalar?

We can't express 'either or' in the DSL (yet) Adding Rails-style
validation is one of the things I'd like to do. In terms of lifecycle, I
think validations should run right after from_{xml,json} and just before
to_{xml,json}

But we can hold off on that for a little bit, I'd rather get to start
machines first ;)

David



Re: [PATCH core 3/5] CIMI: Added MachineImage model

Posted by "marios@redhat.com" <ma...@redhat.com>.
minor comments inline (otherwise ACK):

On 14/11/11 17:09, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> +# 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::MachineImage < CIMI::Model::Base
> +
> +  scalar :image_location

could also have :image_data instead of :image_location (either-or, but
not both)... :image_data is a byte array, but represented as string in
json and xml, so scalar?

JSON: "imageData": string, ?
XML: <imageData> xs:string </imageData> ?

> +
> +  array :operations do
> +    scalar :rel, :href
> +  end
> +end
> diff --git a/server/spec/cimi/data/machine_image.json b/server/spec/cimi/data/machine_image.json
> new file mode 100644
> index 0000000..e037144
> --- /dev/null
> +++ b/server/spec/cimi/data/machine_image.json
> @@ -0,0 +1,13 @@
> +{
> +  "uri": "http://cimi.example.org/machine_images/1",
> +  "name": "My First image",
> +  "description": "A image for testing",
> +  "created": "2011-11-14",
> +  "imageLocation": { "href": "nfs://cimi.example.com/images/1.img"}
> +  "properties": [ {"name": "status", "value": "build"}, { "name": "locked", "value": "true" } ]

I think this is gonna be more like

 +  "properties": [ {"status": "build", "locked": "true" } ]

> +  "operations": [
> +    { "rel": "edit",
> +      "href": "http://cimi.example.org/machine_images/1/edit" },
> +    { "rel": "delete",
> +      "href": "http://cimi.example.org/machine_images/1/delete" }]
> +}
> diff --git a/server/spec/cimi/data/machine_image.xml b/server/spec/cimi/data/machine_image.xml
> new file mode 100644
> index 0000000..a02bc36
> --- /dev/null
> +++ b/server/spec/cimi/data/machine_image.xml
> @@ -0,0 +1,11 @@
> +<MachineImage xmlns="http://www.dmtf.org/cimi">
> +  <uri>http://cimi.example.org/machine_image/1</uri>
> +  <name>img1</name>
> +  <description>Machine Image One</description>
> +  <created>2011-11-14</created>
> +  <property name="status">BUILD</property>
> +  <property name="locked">true</property>

properties are (for now :) ) :key="status" instead of :name

<property key="xs:string"> xs:string </property> *

> +  <imageLocation href="nfs://cimi.example.com/images/1.img"/>
> +  <operation rel="edit" href="http://cimi.example.org/machine_image/1/edit"/>
> +  <operation rel="delete" href="http://cimi.example.org/machine_image/1/delete"/>
> +</MachineImage>

Re: [PATCH core 3/5] CIMI: Added MachineImage model

Posted by David Lutterkort <lu...@redhat.com>.
On Mon, 2011-11-14 at 16:09 +0100, mfojtik@redhat.com wrote:
> diff --git a/server/lib/cimi/model/machine_image.rb b/server/lib/cimi/model/machine_image.rb
> new file mode 100644
> index 0000000..dd3c960
> --- /dev/null
> +++ b/server/lib/cimi/model/machine_image.rb
> @@ -0,0 +1,23 @@

> +class CIMI::Model::MachineImage < CIMI::Model::Base
> +
> +  scalar :image_location

This should be 'href', not 'scalar'. 'href' is syntactic sugar for
  struct :image_location do
    scalar :href
  end

David



[PATCH core 3/5] CIMI: Added MachineImage model

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


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/cimi/model/machine_image.rb       |   23 +++++++++
 server/spec/cimi/data/machine_image.json     |   13 +++++
 server/spec/cimi/data/machine_image.xml      |   11 ++++
 server/spec/cimi/model/machine_image_spec.rb |   66 ++++++++++++++++++++++++++
 4 files changed, 113 insertions(+), 0 deletions(-)
 create mode 100644 server/lib/cimi/model/machine_image.rb
 create mode 100644 server/spec/cimi/data/machine_image.json
 create mode 100644 server/spec/cimi/data/machine_image.xml
 create mode 100644 server/spec/cimi/model/machine_image_spec.rb

diff --git a/server/lib/cimi/model/machine_image.rb b/server/lib/cimi/model/machine_image.rb
new file mode 100644
index 0000000..dd3c960
--- /dev/null
+++ b/server/lib/cimi/model/machine_image.rb
@@ -0,0 +1,23 @@
+# 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::MachineImage < CIMI::Model::Base
+
+  scalar :image_location
+
+  array :operations do
+    scalar :rel, :href
+  end
+end
diff --git a/server/spec/cimi/data/machine_image.json b/server/spec/cimi/data/machine_image.json
new file mode 100644
index 0000000..e037144
--- /dev/null
+++ b/server/spec/cimi/data/machine_image.json
@@ -0,0 +1,13 @@
+{
+  "uri": "http://cimi.example.org/machine_images/1",
+  "name": "My First image",
+  "description": "A image for testing",
+  "created": "2011-11-14",
+  "imageLocation": { "href": "nfs://cimi.example.com/images/1.img"}
+  "properties": [ {"name": "status", "value": "build"}, { "name": "locked", "value": "true" } ]
+  "operations": [
+    { "rel": "edit",
+      "href": "http://cimi.example.org/machine_images/1/edit" },
+    { "rel": "delete",
+      "href": "http://cimi.example.org/machine_images/1/delete" }]
+}
diff --git a/server/spec/cimi/data/machine_image.xml b/server/spec/cimi/data/machine_image.xml
new file mode 100644
index 0000000..a02bc36
--- /dev/null
+++ b/server/spec/cimi/data/machine_image.xml
@@ -0,0 +1,11 @@
+<MachineImage xmlns="http://www.dmtf.org/cimi">
+  <uri>http://cimi.example.org/machine_image/1</uri>
+  <name>img1</name>
+  <description>Machine Image One</description>
+  <created>2011-11-14</created>
+  <property name="status">BUILD</property>
+  <property name="locked">true</property>
+  <imageLocation href="nfs://cimi.example.com/images/1.img"/>
+  <operation rel="edit" href="http://cimi.example.org/machine_image/1/edit"/>
+  <operation rel="delete" href="http://cimi.example.org/machine_image/1/delete"/>
+</MachineImage>
diff --git a/server/spec/cimi/model/machine_image_spec.rb b/server/spec/cimi/model/machine_image_spec.rb
new file mode 100644
index 0000000..6336660
--- /dev/null
+++ b/server/spec/cimi/model/machine_image_spec.rb
@@ -0,0 +1,66 @@
+# 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.
+#
+
+describe "MachineImage model" do
+
+  before(:all) do
+    @xml = IO::read(File::join(DATA_DIR, "machine_image.xml"))
+    @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
+  end
+
+  it "can be constructed from XML" do
+    img = CIMI::Model::MachineImage.from_xml(@xml)
+    img.should_not be_nil
+    img.created.should == "2011-11-14"
+    img.name.should == "img1"
+    img.description.should == "Machine Image One"
+    img.uri.should == "http://cimi.example.org/machine_image/1"
+    img.image_location.size == 1
+    img.image_location[0]['href'].should == 'nfs://cimi.example.com/images/1.img'
+    img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
+    img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
+    img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
+    img.should serialize_to @xml, :fmt => :xml
+  end
+
+  it "should parse properties correctly in XML" do
+    img = CIMI::Model::MachineImage.from_xml(@xml)
+    img.property.any? { |p| p.name == 'status' }.should be_true
+    img.property.any? { |p| p.name == 'locked' }.should be_true
+    img.property.size.should == 2
+  end
+
+  it "should convert strings in keys to symbols when contructed from XML" do
+    imgl = CIMI::Model::MachineImage.from_xml(@xml)
+    imgl.should_not be_nil
+    imgl.attribute_values.keys.each { |key| key.should be_a(Symbol) }
+  end
+
+  it "can be constructed from JSON" do
+    templ = CIMI::Model::MachineTemplate.from_json(@json)
+    templ.should_not be_nil
+    templ.created.should == "2011-11-01"
+    templ.should serialize_to @json, :fmt => :json
+  end
+
+  it "should parse properties correctly in JSON" do
+    img = CIMI::Model::MachineImage.from_json(@json)
+    # TODO: Fix this
+    # img.property.any? { |p| p.name == 'status' }.should be_true
+    # img.property.any? { |p| p.name == 'locked' }.should be_true
+    # img.property.size.should == 2
+  end
+end
-- 
1.7.4.4


Re: [PATCH core 1/5] CIMI: Replaced elsif by case, switched block syntax

Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2011-11-16 at 13:21 +0200, marios@redhat.com wrote:
> minor comment inline:
> 
> On 14/11/11 17:09, mfojtik@redhat.com wrote:
> > From: Michal Fojtik <mf...@redhat.com>
> > diff --git a/server/lib/cimi/model/base.rb b/server/lib/cimi/model/base.rb
> > index 0ef2b27..de6529b 100644
> > --- a/server/lib/cimi/model/base.rb
> > +++ b/server/lib/cimi/model/base.rb
> > @@ -163,7 +163,7 @@ class CIMI::Model::Base
> >    text :uri, :name, :description, :created
> >  
> >    # FIXME: this doesn't match with JSON
> > -  array :properties, :content => :value do
> > -    scalar :key
> > +  array :property, :content => :value do
> > +    scalar :name
> 
> This was changed to :key and I think it makes more sense for it to be
> :properties since it's meant to be a 'set of properties'.
> 
> JSON:  "properties": { "key": string, + }, ?
> XML: <property key="xs:string"> xs:string </property> *

The DSL doesn't have a way to deal with properties right now; we'll need
to add something that handles what is a hash in JSON, and the encoding
of a hash as a sequence of tags in XML. Just put a big FIXME next to
properties for now - they are not critical.

David




Re: [PATCH core 1/5] CIMI: Replaced elsif by case, switched block syntax

Posted by "marios@redhat.com" <ma...@redhat.com>.
minor comment inline:

On 14/11/11 17:09, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> diff --git a/server/lib/cimi/model/base.rb b/server/lib/cimi/model/base.rb
> index 0ef2b27..de6529b 100644
> --- a/server/lib/cimi/model/base.rb
> +++ b/server/lib/cimi/model/base.rb
> @@ -163,7 +163,7 @@ class CIMI::Model::Base
>    text :uri, :name, :description, :created
>  
>    # FIXME: this doesn't match with JSON
> -  array :properties, :content => :value do
> -    scalar :key
> +  array :property, :content => :value do
> +    scalar :name

This was changed to :key and I think it makes more sense for it to be
:properties since it's meant to be a 'set of properties'.

JSON:  "properties": { "key": string, + }, ?
XML: <property key="xs:string"> xs:string </property> *

otherwise ACK

[PATCH core 1/5] CIMI: Replaced elsif by case, switched block syntax

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


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/cimi/model.rb        |    2 +
 server/lib/cimi/model/base.rb   |    4 +-
 server/lib/cimi/model/schema.rb |   42 +++++++++++++--------------------------
 3 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/server/lib/cimi/model.rb b/server/lib/cimi/model.rb
index c1d7f02..fcc6e17 100644
--- a/server/lib/cimi/model.rb
+++ b/server/lib/cimi/model.rb
@@ -14,6 +14,8 @@
 # under the License.
 #
 
+# Declare namespace for CIMI model
+#
 module CIMI
   module Model; end
 end
diff --git a/server/lib/cimi/model/base.rb b/server/lib/cimi/model/base.rb
index 0ef2b27..de6529b 100644
--- a/server/lib/cimi/model/base.rb
+++ b/server/lib/cimi/model/base.rb
@@ -163,7 +163,7 @@ class CIMI::Model::Base
   text :uri, :name, :description, :created
 
   # FIXME: this doesn't match with JSON
-  array :properties, :content => :value do
-    scalar :key
+  array :property, :content => :value do
+    scalar :name
   end
 end
diff --git a/server/lib/cimi/model/schema.rb b/server/lib/cimi/model/schema.rb
index e470121..d8520d5 100644
--- a/server/lib/cimi/model/schema.rb
+++ b/server/lib/cimi/model/schema.rb
@@ -60,23 +60,19 @@ class CIMI::Model::Schema
     def nested_text?; @text == :nested; end
 
     def from_xml(xml, model)
-      if @text == :nested
-        model[@name] = xml[@xml_name].first["content"] if xml[@xml_name]
-      elsif @text == :direct
-        model[@name] = xml["content"]
-      else
-        model[@name] = xml[@xml_name]
+      case @text
+        when :nested : model[@name] = xml[@xml_name].first["content"] if xml[@xml_name]
+        when :direct : model[@name] = xml["content"]
+        else model[@name] = xml[@xml_name]
       end
     end
 
     def to_xml(model, xml)
       return unless model[@name]
-      if @text == :nested
-        xml[@xml_name] = [{ "content" => model[@name] }]
-      elsif @text == :direct
-        xml["content"] = model[@name]
-      else
-        xml[@xml_name] = model[@name]
+      case @text
+        when :nested : xml[@xml_name] = [{ "content" => model[@name] }]
+        when :direct : xml["content"] = model[@name]
+        else xml[@xml_name] = model[@name]
       end
     end
   end
@@ -84,7 +80,7 @@ class CIMI::Model::Schema
   class Struct < Attribute
     def initialize(name, opts, &block)
       content = opts[:content]
-      super(name)
+      super(name, opts)
       @schema = CIMI::Model::Schema.new
       @schema.instance_eval(&block) if block_given?
       @schema.scalar(content, :text => :direct) if content
@@ -156,15 +152,11 @@ class CIMI::Model::Schema
     end
 
     def from_xml(xml, model)
-      model[name] = (xml[xml_name] || []).map do |elt|
-        @struct.convert_from_xml(elt)
-      end
+      model[name] = (xml[xml_name] || []).map { |elt| @struct.convert_from_xml(elt) }
     end
 
     def from_json(json, model)
-      model[name] = (json[json_name] || []).map do |elt|
-        @struct.convert_from_json(elt)
-      end
+      model[name] = (json[json_name] || []).map { |elt| @struct.convert_from_json(elt) }
     end
 
     def to_xml(model, xml)
@@ -220,9 +212,7 @@ class CIMI::Model::Schema
   # +add_attributes!+ method
   module DSL
     def href(*args)
-      args.each do |arg|
-        struct(arg) { scalar :href }
-      end
+      args.each { |arg| struct(arg) { scalar :href } }
     end
 
     def text(*args)
@@ -246,12 +236,8 @@ class CIMI::Model::Schema
   include DSL
 
   def add_attributes!(args, attr_klass, &block)
-    if @attributes.frozen?
-      raise "The schema has already been used to convert objects"
-    end
+    raise "The schema has already been used to convert objects" if @attributes.frozen?
     opts = args.extract_opts!
-    args.each do |arg|
-      @attributes << attr_klass.new(arg, opts, &block)
-    end
+    args.each { |arg| @attributes << attr_klass.new(arg, opts, &block) }
   end
 end
-- 
1.7.4.4