deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "marios@redhat.com" <mandr...@redhat.com>
Subject Re: [PATCH core] CIMI: Wrapped all collections to Collection entity with entries
Date Mon, 13 Aug 2012 14:47:30 GMT
nack - inline:

On 13/08/12 13:49, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mfojtik@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mfojtik@redhat.com>
> ---
>  server/lib/cimi/models/address_collection.rb       |    2 +-
>  .../lib/cimi/models/address_template_collection.rb |    2 +-
>  server/lib/cimi/models/base.rb                     |   12 +++--
>  server/lib/cimi/models/cloud_entry_point.rb        |    1 +
>  .../lib/cimi/models/entity_metadata_collection.rb  |    2 +-
>  server/lib/cimi/models/machine_admin_collection.rb |    2 +-
>  server/lib/cimi/models/machine_collection.rb       |    2 +-
>  .../models/machine_configuration_collection.rb     |    2 +-
>  server/lib/cimi/models/machine_image_collection.rb |    2 +-
>  .../lib/cimi/models/machine_template_collection.rb |    2 +-
>  server/lib/cimi/models/network_collection.rb       |    2 +-
>  .../models/network_configuration_collection.rb     |    2 +-
>  .../lib/cimi/models/network_template_collection.rb |    2 +-
>  server/lib/cimi/models/routing_group_collection.rb |    2 +-
>  .../models/routing_group_template_collection.rb    |    2 +-
>  server/lib/cimi/models/schema.rb                   |   47 ++++++++++++++++++++
>  server/lib/cimi/models/volume_collection.rb        |    2 +-
>  .../cimi/models/volume_configuration_collection.rb |    2 +-
>  server/lib/cimi/models/volume_image_collection.rb  |    2 +-
>  .../lib/cimi/models/volume_template_collection.rb  |    2 +-
>  server/lib/cimi/models/vsp_collection.rb           |    2 +-
>  .../cimi/models/vsp_configuration_collection.rb    |    2 +-
>  server/lib/cimi/models/vsp_template_collection.rb  |    2 +-
>  23 files changed, 77 insertions(+), 23 deletions(-)
> 
> diff --git a/server/lib/cimi/models/address_collection.rb b/server/lib/cimi/models/address_collection.rb
> index eef6c51..141ab16 100644
> --- a/server/lib/cimi/models/address_collection.rb
> +++ b/server/lib/cimi/models/address_collection.rb
> @@ -17,7 +17,7 @@ class CIMI::Model::AddressCollection < CIMI::Model::Base
>  
>    act_as_root_entity :address
>  
> -  array :addresses do
> +  collection :addresses do
>      scalar :href
>    end

The :href (i.e. self pointer to any resource) is now known as 'id' - and
is also 'text' by our DSL... i.e. <id> http://foo/bar </id>

Also, the above is the 'old' way of doing collections. If I've
understood the collections stuff, each FOOCollection contains a list of
complete FOO items, e.g.:

<Collection resourceURI="http://schemas.dmtf.org/cimi/1/MachineCollection"
xmlns="http://schemas.dmtf.org/cimi/1">
<id> xs:anyURI </id>
<count> xs:integer </count>
<Machine>
<id> xs:anyURI </id>
... remaining Machine attributes ...
</Machine> *
<operation rel="add" href="xs:anyURI"/> ?
<xs:any>*
</Collection>

so we have to put all Machine attributes, not just the <id>. These
points apply to all the collections here. One more point below (I think
typo):

8<-----------------SNIP-----8<---------------------
>  
>  
>  
> diff --git a/server/lib/cimi/models/schema.rb b/server/lib/cimi/models/schema.rb
> index fa0d11a..6f9ac1a 100644
> --- a/server/lib/cimi/models/schema.rb
> +++ b/server/lib/cimi/models/schema.rb
> @@ -171,6 +171,49 @@ class CIMI::Model::Schema
>      end
>    end
>  
> +  class Collection < Array
> +
> +    def from_xml(xml, model)
> +      model[name] = xml['Entry'].inject([]) do |result, entry|
> +        result << entry[xml_name].map { |elt| @struct.convert_from_xml(elt) }
> +        result
> +      end.flatten
> +    end
> +
> +    def from_json(xml, model)
> +      model[name] = json['entries'].inject([]) do |result, entry|
> +        result << entry[json_name].map { |elt| @struct.convert_from_json(elt)
}
> +        result
> +      end.flatten
> +    end
> +
> +    def from_json(json, model)
> +      model[name] = (json[json_name] || []).map { |elt| @struct.convert_from_json(elt)
}
> +    end
> +

duplicate method name here?

marios


> +    def to_xml(model, xml)
> +      xml['Entry'] = []
> +      (model[name] || []).each do |elt|
> +        xml['Entry'] << {
> +          "resourceURI" => "http://schemas.dmtf.org/cimi/1/#{model.class.name.split('::').last}Entry",
> +          :id => elt[:href].scan(/\/([\w\-\_]+)$/).first,
> +          xml_name => @struct.convert_to_xml(elt),
> +        }
> +      end
> +    end
> +
> +    def to_json(model, json)
> +      json['entries'] = []
> +      (model[name] || []).each do |elt|
> +        json['entries'] << {
> +          :id => elt[:href].scan(/\/(\w+)$/).first,
> +          json_name => @struct.convert_to_json(elt),
> +        }
> +      end
> +    end
> +
> +  end
> +
>    class Hash < Attribute
>  
>      def initialize(name, opts = {}, &block)
> @@ -259,6 +302,10 @@ class CIMI::Model::Schema
>        add_attributes!([name, opts], Array, &block)
>      end
>  
> +    def collection(name, opts={}, &block)
> +      add_attributes!([name, opts], Collection, &block)
> +    end
> +
>      def struct(name, opts={}, &block)
>        add_attributes!([name, opts], Struct, &block)
>      end
> diff --git a/server/lib/cimi/models/volume_collection.rb b/server/lib/cimi/models/volume_collection.rb
> index 1f4152e..5c00cb6 100644
> --- a/server/lib/cimi/models/volume_collection.rb
> +++ b/server/lib/cimi/models/volume_collection.rb
> @@ -17,7 +17,7 @@ class CIMI::Model::VolumeCollection < CIMI::Model::Base
>  
>    act_as_root_entity :volume
>  
> -  array :volumes do
> +  collection :volumes do
>      scalar :href
>    end
>  
> diff --git a/server/lib/cimi/models/volume_configuration_collection.rb b/server/lib/cimi/models/volume_configuration_collection.rb
> index 2120ae6..36940aa 100644
> --- a/server/lib/cimi/models/volume_configuration_collection.rb
> +++ b/server/lib/cimi/models/volume_configuration_collection.rb
> @@ -17,7 +17,7 @@ class CIMI::Model::VolumeConfigurationCollection < CIMI::Model::Base
>  
>    act_as_root_entity :volume_configuration
>  
> -  array :volume_configurations do
> +  collection :volume_configurations do
>      scalar :href
>    end
>  
> diff --git a/server/lib/cimi/models/volume_image_collection.rb b/server/lib/cimi/models/volume_image_collection.rb
> index f3da877..b3b697b 100644
> --- a/server/lib/cimi/models/volume_image_collection.rb
> +++ b/server/lib/cimi/models/volume_image_collection.rb
> @@ -17,7 +17,7 @@ class CIMI::Model::VolumeImageCollection < CIMI::Model::Base
>  
>    act_as_root_entity :volume_image
>  
> -  array :volume_images do
> +  collection :volume_images do
>      scalar :href
>    end
>  
> diff --git a/server/lib/cimi/models/volume_template_collection.rb b/server/lib/cimi/models/volume_template_collection.rb
> index f53547c..7b637c0 100644
> --- a/server/lib/cimi/models/volume_template_collection.rb
> +++ b/server/lib/cimi/models/volume_template_collection.rb
> @@ -17,7 +17,7 @@ class CIMI::Model::VolumeTemplateCollection < CIMI::Model::Base
>  
>    act_as_root_entity :volume_template
>  
> -  array :volume_templates do
> +  collection :volume_templates do
>      scalar :href
>    end
>  
> diff --git a/server/lib/cimi/models/vsp_collection.rb b/server/lib/cimi/models/vsp_collection.rb
> index fc72024..c5ba51a 100644
> --- a/server/lib/cimi/models/vsp_collection.rb
> +++ b/server/lib/cimi/models/vsp_collection.rb
> @@ -17,7 +17,7 @@ class CIMI::Model::VSPCollection < CIMI::Model::Base
>  
>    CIMI::Model.register_as_root_entity! "VSPs"
>  
> -  array :vsps do
> +  collection :vsps do
>      scalar :href
>    end
>  
> diff --git a/server/lib/cimi/models/vsp_configuration_collection.rb b/server/lib/cimi/models/vsp_configuration_collection.rb
> index d4927e7..f387469 100644
> --- a/server/lib/cimi/models/vsp_configuration_collection.rb
> +++ b/server/lib/cimi/models/vsp_configuration_collection.rb
> @@ -17,7 +17,7 @@ class CIMI::Model::VSPConfigurationCollection < CIMI::Model::Base
>  
>    CIMI::Model.register_as_root_entity! "VSPConfigurations"
>  
> -  array :vsp_configurations do
> +  collection :vsp_configurations do
>      scalar :href
>    end
>  
> diff --git a/server/lib/cimi/models/vsp_template_collection.rb b/server/lib/cimi/models/vsp_template_collection.rb
> index 61d5311..403e4c0 100644
> --- a/server/lib/cimi/models/vsp_template_collection.rb
> +++ b/server/lib/cimi/models/vsp_template_collection.rb
> @@ -17,7 +17,7 @@ class CIMI::Model::VSPTemplateCollection < CIMI::Model::Base
>  
>    CIMI::Model.register_as_root_entity! "VSPTemplates"
>  
> -  array :vsp_templates do
> +  collection :vsp_templates do
>      scalar :href
>    end
>  
> 



Mime
View raw message