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 3/6] CIMI: Added all_uri() helper to map links from various CIMI entities to URI hash
Date Tue, 17 Jan 2012 15:58:21 GMT
ack - all_uri is a nice idea - though it does make the code a little
harder to follow for first timers... (passing context to model base
class and calling the find(:all) from there...)

On 17/01/12 13:52, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mfojtik@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mfojtik@redhat.com>
> ---
>  server/lib/cimi/model/base.rb                      |    5 +++++
>  server/lib/cimi/model/cloud_entry_point.rb         |    8 --------
>  .../lib/cimi/model/entity_metadata_collection.rb   |    2 +-
>  server/lib/cimi/model/machine_admin_collection.rb  |    2 +-
>  server/lib/cimi/model/machine_collection.rb        |    2 +-
>  .../cimi/model/machine_configuration_collection.rb |    2 +-
>  server/lib/cimi/model/machine_image_collection.rb  |    2 +-
>  .../lib/cimi/model/machine_template_collection.rb  |    2 +-
>  server/lib/cimi/model/volume_collection.rb         |    2 +-
>  .../cimi/model/volume_configuration_collection.rb  |    2 +-
>  server/lib/cimi/model/volume_image_collection.rb   |    2 +-
>  .../lib/cimi/model/volume_template_collection.rb   |    2 +-
>  12 files changed, 15 insertions(+), 18 deletions(-)
> 
> diff --git a/server/lib/cimi/model/base.rb b/server/lib/cimi/model/base.rb
> index 30ee240..88c7c6a 100644
> --- a/server/lib/cimi/model/base.rb
> +++ b/server/lib/cimi/model/base.rb
> @@ -128,6 +128,11 @@ class CIMI::Model::Base
>          define_method(:"#{name}=") { |newval| @attribute_values[name] = newval }
>        end
>      end
> +
> +    # Return Array of links to current CIMI object
> +    def all_uri(context)
> +      self.all(context).map { |e| { :href => e.uri } }
> +    end
>    end
>  
>    extend CIMI::Model::Schema::DSL
> diff --git a/server/lib/cimi/model/cloud_entry_point.rb b/server/lib/cimi/model/cloud_entry_point.rb
> index e14678d..7d76cfe 100644
> --- a/server/lib/cimi/model/cloud_entry_point.rb
> +++ b/server/lib/cimi/model/cloud_entry_point.rb
> @@ -39,14 +39,6 @@ class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
>      end
>    end
>  
> -  # Return an Hash of links to the EntityMetadata objects
> -  def root_entity_metadata(context)
> -    entity_metadata = EntityMetadata.all(context)
> -    entity_metadata.map do |m|
> -      { :href => m.uri }
> -    end
> -  end
> -
>    private
>  
>    def self.href_defined?(entity)
> diff --git a/server/lib/cimi/model/entity_metadata_collection.rb b/server/lib/cimi/model/entity_metadata_collection.rb
> index a395829..e5ce3cb 100644
> --- a/server/lib/cimi/model/entity_metadata_collection.rb
> +++ b/server/lib/cimi/model/entity_metadata_collection.rb
> @@ -24,7 +24,7 @@ class CIMI::Model::EntityMetadataCollection < CIMI::Model::Base
>        :uri => context.entity_metadata_url,
>        :name => 'default',
>        :created => Time.now,
> -      :entity_metadata => EntityMetadata.all(context).map{|em| {:href => em.uri}}
> +      :entity_metadata => EntityMetadata.all_uri
>     )
>    end
>  
> diff --git a/server/lib/cimi/model/machine_admin_collection.rb b/server/lib/cimi/model/machine_admin_collection.rb
> index b5f5e49..775f7f8 100644
> --- a/server/lib/cimi/model/machine_admin_collection.rb
> +++ b/server/lib/cimi/model/machine_admin_collection.rb
> @@ -27,7 +27,7 @@ class CIMI::Model::MachineAdminCollection < CIMI::Model::Base
>        :name => 'default',
>        :created => Time.now,
>        :description => "#{context.driver.name.capitalize} MachineAdminCollection",
> -      :machine_admins => MachineAdmin.all(context).map { |c| { :href => c.uri
} }
> +      :machine_admins => MachineAdmin.all_uri(context)
>      )
>    end
>  
> diff --git a/server/lib/cimi/model/machine_collection.rb b/server/lib/cimi/model/machine_collection.rb
> index 9697ede..65815d8 100644
> --- a/server/lib/cimi/model/machine_collection.rb
> +++ b/server/lib/cimi/model/machine_collection.rb
> @@ -27,7 +27,7 @@ class CIMI::Model::MachineCollection < CIMI::Model::Base
>        :name => 'default',
>        :created => Time.now,
>        :description => "#{context.driver.name.capitalize} MachineCollection",
> -      :machines => Machine.all(context).map { |c| { :href => c.uri } }
> +      :machines => Machine.all_uri(context)
>      )
>    end
>  
> diff --git a/server/lib/cimi/model/machine_configuration_collection.rb b/server/lib/cimi/model/machine_configuration_collection.rb
> index ef68133..c916bcb 100644
> --- a/server/lib/cimi/model/machine_configuration_collection.rb
> +++ b/server/lib/cimi/model/machine_configuration_collection.rb
> @@ -27,7 +27,7 @@ class CIMI::Model::MachineConfigurationCollection < CIMI::Model::Base
>        :name => 'default',
>        :created => Time.now,
>        :description => "#{context.driver.name.capitalize} MachineConfigurationCollection",
> -      :machine_configurations => MachineConfiguration.all(context).map { |c| { :href
=> c.uri } }
> +      :machine_configurations => MachineConfiguration.all_uri(context)
>      )
>    end
>  
> diff --git a/server/lib/cimi/model/machine_image_collection.rb b/server/lib/cimi/model/machine_image_collection.rb
> index 7ce5623..b5db633 100644
> --- a/server/lib/cimi/model/machine_image_collection.rb
> +++ b/server/lib/cimi/model/machine_image_collection.rb
> @@ -27,7 +27,7 @@ class CIMI::Model::MachineImageCollection < CIMI::Model::Base
>        :name => 'default',
>        :created => Time.now,
>        :description => "#{context.driver.name.capitalize} MachineImageCollection",
> -      :machine_images => MachineImage.all(context).map { |c| { :href => c.uri
} }
> +      :machine_images => MachineImage.all_uri(context)
>      )
>    end
>  
> diff --git a/server/lib/cimi/model/machine_template_collection.rb b/server/lib/cimi/model/machine_template_collection.rb
> index 4838625..5aca625 100644
> --- a/server/lib/cimi/model/machine_template_collection.rb
> +++ b/server/lib/cimi/model/machine_template_collection.rb
> @@ -27,7 +27,7 @@ class CIMI::Model::MachineTemplateCollection < CIMI::Model::Base
>        :name => 'default',
>        :created => Time.now,
>        :description => "#{context.driver.name.capitalize} MachineTemplateCollection",
> -      :machine_templates => MachineTemplate.all(context).map { |c| { :href =>
c.uri } }
> +      :machine_templates => MachineTemplate.all_uri(context)
>      )
>    end
>  
> diff --git a/server/lib/cimi/model/volume_collection.rb b/server/lib/cimi/model/volume_collection.rb
> index 43c4ee3..385ee0a 100644
> --- a/server/lib/cimi/model/volume_collection.rb
> +++ b/server/lib/cimi/model/volume_collection.rb
> @@ -27,7 +27,7 @@ class CIMI::Model::VolumeCollection < CIMI::Model::Base
>        :name => 'default',
>        :created => Time.now,
>        :description => "#{context.driver.name.capitalize} VolumeCollection",
> -      :volumes => Volume.all(context).map { |c| { :href => c.uri } }
> +      :volumes => Volume.all_uri(context)
>      )
>    end
>  
> diff --git a/server/lib/cimi/model/volume_configuration_collection.rb b/server/lib/cimi/model/volume_configuration_collection.rb
> index 27678dc..2dae421 100644
> --- a/server/lib/cimi/model/volume_configuration_collection.rb
> +++ b/server/lib/cimi/model/volume_configuration_collection.rb
> @@ -27,7 +27,7 @@ class CIMI::Model::VolumeConfigurationCollection < CIMI::Model::Base
>        :name => 'default',
>        :created => Time.now,
>        :description => "#{context.driver.name.capitalize} VolumeConfigurationCollection",
> -      :volume_configurations => VolumeConfiguration.all(context).map { |c| { :href
=> c.uri } }
> +      :volume_configurations => VolumeConfiguration.all_uri(context)
>      )
>    end
>  
> diff --git a/server/lib/cimi/model/volume_image_collection.rb b/server/lib/cimi/model/volume_image_collection.rb
> index 074db5e..f2ee5cb 100644
> --- a/server/lib/cimi/model/volume_image_collection.rb
> +++ b/server/lib/cimi/model/volume_image_collection.rb
> @@ -27,7 +27,7 @@ class CIMI::Model::VolumeImageCollection < CIMI::Model::Base
>        :name => 'default',
>        :created => Time.now,
>        :description => "#{context.driver.name.capitalize} VolumeImageCollection",
> -      :volume_images => VolumeImage.all(context).map { |c| { :href => c.uri }
}
> +      :volume_images => VolumeImage.all_uri(context)
>      )
>    end
>  
> diff --git a/server/lib/cimi/model/volume_template_collection.rb b/server/lib/cimi/model/volume_template_collection.rb
> index 05140f0..47ca480 100644
> --- a/server/lib/cimi/model/volume_template_collection.rb
> +++ b/server/lib/cimi/model/volume_template_collection.rb
> @@ -27,7 +27,7 @@ class CIMI::Model::VolumeTemplateCollection < CIMI::Model::Base
>        :name => 'default',
>        :created => Time.now,
>        :description => "#{context.driver.name.capitalize} VolumeTemplateCollection",
> -      :volume_templates => VolumeTemplate.all(context).map { |c| { :href => c.uri
} }
> +      :volume_templates => VolumeTemplate.all_uri(context)
>      )
>    end
>  


Mime
View raw message