Return-Path: X-Original-To: apmail-deltacloud-dev-archive@www.apache.org Delivered-To: apmail-deltacloud-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0EE9CE56C for ; Mon, 7 Jan 2013 13:41:47 +0000 (UTC) Received: (qmail 64751 invoked by uid 500); 7 Jan 2013 13:41:47 -0000 Delivered-To: apmail-deltacloud-dev-archive@deltacloud.apache.org Received: (qmail 64690 invoked by uid 500); 7 Jan 2013 13:41:46 -0000 Mailing-List: contact dev-help@deltacloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltacloud.apache.org Delivered-To: mailing list dev@deltacloud.apache.org Received: (qmail 64670 invoked by uid 99); 7 Jan 2013 13:41:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Jan 2013 13:41:46 +0000 X-ASF-Spam-Status: No, hits=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of mandreou@redhat.com designates 209.132.183.28 as permitted sender) Received: from [209.132.183.28] (HELO mx1.redhat.com) (209.132.183.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Jan 2013 13:41:40 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r07DfIah008262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 7 Jan 2013 08:41:18 -0500 Received: from [10.36.112.21] (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r07DfFgh002332; Mon, 7 Jan 2013 08:41:16 -0500 Message-ID: <50EAD07A.8020603@redhat.com> Date: Mon, 07 Jan 2013 15:41:14 +0200 From: "marios@redhat.com" User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: dev@deltacloud.apache.org CC: mfojtik@redhat.com Subject: Re: [PATCH core 2/2] CIMI: Added 'constraints' to resourceMetadata attributes for realms References: <1357563463-26707-1-git-send-email-mfojtik@redhat.com> <1357563463-26707-2-git-send-email-mfojtik@redhat.com> In-Reply-To: <1357563463-26707-2-git-send-email-mfojtik@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Virus-Checked: Checked by ClamAV on apache.org ack - solution looks good. only issue is to clarify the format (i.e. array of constraints with for each?) On 07/01/13 14:57, mfojtik@redhat.com wrote: > From: Michal Fojtik > > 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 > --- > 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 >