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 2/2] CIMI: Added 'constraints' to resourceMetadata attributes for realms
Date Mon, 07 Jan 2013 13:41:14 GMT

ack - solution looks good. only issue is to clarify the format (i.e.
array of constraints with <value> for each?)

On 07/01/13 14:57, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mfojtik@redhat.com>
> 
> Currently there is now way how to advertise available 'realms to
> the client. This patch will make it possible through 'constraints'
> defined for the 'realm' resourceMetadata atrribute defined for
> the Machine resource.
> 
> This will allow to pass ':constraints' option to 'resource_attr' like:
> 
>   resource_attr :realm, :required => false,
>     :constraints => lambda { |c| c.driver.realms(c.credentials).map { |r| r.id } }
> 
> The 'lamda' function must always return 'array' of possible values.
> 
> Signed-off-by: Michal fojtik <mfojtik@redhat.com>
> ---
>  server/lib/cimi/models/machine.rb           | 4 +++-
>  server/lib/cimi/models/resource_metadata.rb | 8 +++++++-
>  2 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb
> index 1b1c77e..7ac8f83 100644
> --- a/server/lib/cimi/models/machine.rb
> +++ b/server/lib/cimi/models/machine.rb
> @@ -17,7 +17,9 @@ class CIMI::Model::Machine < CIMI::Model::Base
>  
>    acts_as_root_entity
>  
> -  resource_attr :realm, :required => false
> +  resource_attr :realm, :required => false,
> +    :constraints => lambda { |c| c.driver.realms(c.credentials).map { |r| r.id }
}
> +
>    resource_attr :machine_image, :required => false, :type => :href
>  
>    text :state
> diff --git a/server/lib/cimi/models/resource_metadata.rb b/server/lib/cimi/models/resource_metadata.rb
> index 6976515..30e65d6 100644
> --- a/server/lib/cimi/models/resource_metadata.rb
> +++ b/server/lib/cimi/models/resource_metadata.rb
> @@ -95,13 +95,19 @@ class CIMI::Model::ResourceMetadata < CIMI::Model::Base
>    def self.rm_attributes_for(resource_class, context)
>      return [] if resource_attributes[resource_class.name].nil?
>      resource_attributes[resource_class.name].map do |attr_name, attr_def|
> +      if attr_def.has_key? :constraints
> +        constraints = attr_def[:constraints].call(context)
> +      else
> +        constraints = []
> +      end
>        {
>          :name => attr_name.to_s,
>          # TODO: We need to make this URI return description of this 'non-CIMI'
>          # attribute
>          :namespace => "http://deltacloud.org/cimi/#{resource_class.name.split('::').last}/#{attr_name}",
>          :type => translate_attr_type(attr_def[:type]),
> -        :required => attr_def[:required] ? 'true' : 'false'
> +        :required => attr_def[:required] ? 'true' : 'false',
> +        :constraints => constraints.map { |v| { :value => v }}
>        }
>      end
>    end
> 


Mime
View raw message