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/12/08 13:19:22 UTC
CIMI: CIMISelect filter added
Hi,
This patch add new parameter for all :index operations in CIMI.
CIMISelect is described as optional Collection paramter in 4.1.6.1.
Currently you can do:
curl -H 'Accept: application/xml' --user 'mockuser:mockpassword' 'http://localhost:3001/cimi/machines?CIMISelect=name'
The output will be limited to just 'name' element.
curl -H 'Accept: application/xml' --user 'mockuser:mockpassword' 'http://localhost:3001/cimi/machines?CIMISelect=machines'
Only machines array will be displayed in MachineCollection
curl -H 'Accept: application/xml' --user 'mockuser:mockpassword' 'http://localhost:3001/cimi/machines?CIMISelect=machines[1]'
Only first machine in array will be displayed in MachineCollection
curl -H 'Accept: application/xml' --user 'mockuser:mockpassword' 'http://localhost:3001/cimi/machines?CIMISelect=machines[1-10]'
Only first ten machines will be displayed (similar to Ruby Range, usefull for pagination, etc..)
I found some inconsistencies between JSON and XML. All filter names currently
work onyl with JSON names (machine_configurations, etc..) so the XML tag names
are ignored (machineConfiguration). There is no notion if in XML you should use
the xml tag name in filter name or not.
There is also secondary parameter 'CIMIExpand' that will expand the Entity in
Collection. Practically it will display a full Machine entity instead of
reference. Currently the Collection models are defined to hold only references.
I was thinking about adding something like:
array :machines do
scalar :href
inherit :machine
end
The 'inherit' method will 'copy' schema from Machine model to this Array, so
then the CIMIExpand parameter should be used properly (Collection entity will
contain a full entity with all properties).
Cheers,
Michal
Re: CIMI: CIMISelect filter added
Posted by Michal Fojtik <mf...@redhat.com>.
On Dec 12, 2011, at 5:07 PM, Tong Li wrote:
> Earlier I sent an email mentioned that no search or filter was specified in
> the spec. Which was true in earlier specs. Doug pointed out that in the
> newer CIMI spec section 4.1.1.6 actually does support it. Here is what the
> spec will do to address that.
>
> /machines?CIMISelect=*,machines[href.name=mine]
Right, I found this in CIMI 0.0.50 I think. To implement this kind of filters
we need update our models and add more descriptive relations between entities
in Collections. (Check /me and lutter earlier discussion). So far my patch adds
just basic filtering capabilities.
-- Michal
>
> Notice the bracket at the end of an attribute name, The above described
> mechanism was added somewhere between 0.0.50 and 0.0.55b.
>
> Thanks.
>
> Tong Li
> Emerging Technologies & Standards
> Building 501/B205
> litong01@us.ibm.com
>
> David Lutterkort <lu...@redhat.com> wrote on 12/09/2011 07:56:53 PM:
>
>> From: David Lutterkort <lu...@redhat.com>
>> To: dev@deltacloud.apache.org
>> Date: 12/09/2011 07:57 PM
>> Subject: Re: CIMI: CIMISelect filter added
>>
>> On Thu, 2011-12-08 at 13:19 +0100, mfojtik@redhat.com wrote:
>>> Practically it will display a full Machine entity instead of
>>> reference. Currently the Collection models are defined to hold
>> only references.
>>> I was thinking about adding something like:
>>>
>>> array :machines do
>>> scalar :href
>>> inherit :machine
>>> end
>>>
>>> The 'inherit' method will 'copy' schema from Machine model to
> thisArray, so
>>> then the CIMIExpand parameter should be used properly (Collection
>> entity will
>>> contain a full entity with all properties).
>>
>> I haven't thought through this in code, but my gut feeling says we need
>> to tie the href and the object that it references together more tightly,
>> i.e. I think we'd need something like
>>
>> array :machines do
>> reference :machine, :attribute => :href
>> end
>>
>> where :href is the default for :attribute. At that point, we should
>> probably copy Rails even farther and say
>>
>> has_many :machines, :attribute => :href, :class => Machine
>>
>> where :attribute and :class default to :href and Machine
>> (singularization of the association name)
>>
>> One of the advantages of tying things together like that is that it
>> gives us a lot of flexibility if the association itself should gain
>> attributes in a future draft, e.g. so that the collection of volumes
>> attached to a machine gets its own URL.
>>
>> And we probably want a has_one, too.
>>
>> David
>>
>>
>>
>
------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
Re: CIMI: CIMISelect filter added
Posted by Tong Li <li...@us.ibm.com>.
Earlier I sent an email mentioned that no search or filter was specified in
the spec. Which was true in earlier specs. Doug pointed out that in the
newer CIMI spec section 4.1.1.6 actually does support it. Here is what the
spec will do to address that.
/machines?CIMISelect=*,machines[href.name=mine]
Notice the bracket at the end of an attribute name, The above described
mechanism was added somewhere between 0.0.50 and 0.0.55b.
Thanks.
Tong Li
Emerging Technologies & Standards
Building 501/B205
litong01@us.ibm.com
David Lutterkort <lu...@redhat.com> wrote on 12/09/2011 07:56:53 PM:
> From: David Lutterkort <lu...@redhat.com>
> To: dev@deltacloud.apache.org
> Date: 12/09/2011 07:57 PM
> Subject: Re: CIMI: CIMISelect filter added
>
> On Thu, 2011-12-08 at 13:19 +0100, mfojtik@redhat.com wrote:
> > Practically it will display a full Machine entity instead of
> > reference. Currently the Collection models are defined to hold
> only references.
> > I was thinking about adding something like:
> >
> > array :machines do
> > scalar :href
> > inherit :machine
> > end
> >
> > The 'inherit' method will 'copy' schema from Machine model to
thisArray, so
> > then the CIMIExpand parameter should be used properly (Collection
> entity will
> > contain a full entity with all properties).
>
> I haven't thought through this in code, but my gut feeling says we need
> to tie the href and the object that it references together more tightly,
> i.e. I think we'd need something like
>
> array :machines do
> reference :machine, :attribute => :href
> end
>
> where :href is the default for :attribute. At that point, we should
> probably copy Rails even farther and say
>
> has_many :machines, :attribute => :href, :class => Machine
>
> where :attribute and :class default to :href and Machine
> (singularization of the association name)
>
> One of the advantages of tying things together like that is that it
> gives us a lot of flexibility if the association itself should gain
> attributes in a future draft, e.g. so that the collection of volumes
> attached to a machine gets its own URL.
>
> And we probably want a has_one, too.
>
> David
>
>
>
Re: CIMI: CIMISelect filter added
Posted by Tong Li <li...@us.ibm.com>.
CIMI does not define any search/filtering mechanism. To me this is a big
oversight especially considering this spec is really Cloud (large number of
entities by default) related. I would love to see if a design for getting
sources is search centric, that is, consider all the get operations are
search operations with various filtering conditions. The code specifically
looks for named attributes may not be flexible enough.
just my 2 cents.
Tong Li
Emerging Technologies & Standards
Building 501/B205
litong01@us.ibm.com
David Lutterkort <lu...@redhat.com> wrote on 12/09/2011 07:56:53 PM:
> From: David Lutterkort <lu...@redhat.com>
> To: dev@deltacloud.apache.org
> Date: 12/09/2011 07:57 PM
> Subject: Re: CIMI: CIMISelect filter added
>
> On Thu, 2011-12-08 at 13:19 +0100, mfojtik@redhat.com wrote:
> > Practically it will display a full Machine entity instead of
> > reference. Currently the Collection models are defined to hold
> only references.
> > I was thinking about adding something like:
> >
> > array :machines do
> > scalar :href
> > inherit :machine
> > end
> >
> > The 'inherit' method will 'copy' schema from Machine model to
thisArray, so
> > then the CIMIExpand parameter should be used properly (Collection
> entity will
> > contain a full entity with all properties).
>
> I haven't thought through this in code, but my gut feeling says we need
> to tie the href and the object that it references together more tightly,
> i.e. I think we'd need something like
>
> array :machines do
> reference :machine, :attribute => :href
> end
>
> where :href is the default for :attribute. At that point, we should
> probably copy Rails even farther and say
>
> has_many :machines, :attribute => :href, :class => Machine
>
> where :attribute and :class default to :href and Machine
> (singularization of the association name)
>
> One of the advantages of tying things together like that is that it
> gives us a lot of flexibility if the association itself should gain
> attributes in a future draft, e.g. so that the collection of volumes
> attached to a machine gets its own URL.
>
> And we probably want a has_one, too.
>
> David
>
>
>
Re: CIMI: CIMISelect filter added
Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2011-12-08 at 13:19 +0100, mfojtik@redhat.com wrote:
> Practically it will display a full Machine entity instead of
> reference. Currently the Collection models are defined to hold only references.
> I was thinking about adding something like:
>
> array :machines do
> scalar :href
> inherit :machine
> end
>
> The 'inherit' method will 'copy' schema from Machine model to this Array, so
> then the CIMIExpand parameter should be used properly (Collection entity will
> contain a full entity with all properties).
I haven't thought through this in code, but my gut feeling says we need
to tie the href and the object that it references together more tightly,
i.e. I think we'd need something like
array :machines do
reference :machine, :attribute => :href
end
where :href is the default for :attribute. At that point, we should
probably copy Rails even farther and say
has_many :machines, :attribute => :href, :class => Machine
where :attribute and :class default to :href and Machine
(singularization of the association name)
One of the advantages of tying things together like that is that it
gives us a lot of flexibility if the association itself should gain
attributes in a future draft, e.g. so that the collection of volumes
attached to a machine gets its own URL.
And we probably want a has_one, too.
David
Re: CIMI: CIMISelect filter added
Posted by Michal Fojtik <mf...@redhat.com>.
On Dec 8, 2011, at 4:09 PM, marios@redhat.com wrote:
> ACK - very nice - just 1 thought: looking at CIMISelect - not sure it
> applies only to *_Collection - so for example you want to GET Machine
> but only see the name and volumes attributes:
>
> GET /cimi/machines/my_machine?CIMISelect=name&CIMISelect=volumes
Thanks!
I put it into base model so it should be also available for other
entities. I haven't yet implemented all features for CIMISelect but we
can extend it later.
-- Michal
>
> marios
>
> On 08/12/11 14:19, mfojtik@redhat.com wrote:
>> Hi,
>>
>> This patch add new parameter for all :index operations in CIMI.
>> CIMISelect is described as optional Collection paramter in 4.1.6.1.
>>
>> Currently you can do:
>>
>> curl -H 'Accept: application/xml' --user 'mockuser:mockpassword' 'http://localhost:3001/cimi/machines?CIMISelect=name'
>>
>> The output will be limited to just 'name' element.
>>
>> curl -H 'Accept: application/xml' --user 'mockuser:mockpassword' 'http://localhost:3001/cimi/machines?CIMISelect=machines'
>>
>> Only machines array will be displayed in MachineCollection
>>
>> curl -H 'Accept: application/xml' --user 'mockuser:mockpassword' 'http://localhost:3001/cimi/machines?CIMISelect=machines[1]'
>>
>> Only first machine in array will be displayed in MachineCollection
>>
>> curl -H 'Accept: application/xml' --user 'mockuser:mockpassword' 'http://localhost:3001/cimi/machines?CIMISelect=machines[1-10]'
>>
>> Only first ten machines will be displayed (similar to Ruby Range, usefull for pagination, etc..)
>>
>> I found some inconsistencies between JSON and XML. All filter names currently
>> work onyl with JSON names (machine_configurations, etc..) so the XML tag names
>> are ignored (machineConfiguration). There is no notion if in XML you should use
>> the xml tag name in filter name or not.
>>
>> There is also secondary parameter 'CIMIExpand' that will expand the Entity in
>> Collection. Practically it will display a full Machine entity instead of
>> reference. Currently the Collection models are defined to hold only references.
>> I was thinking about adding something like:
>>
>> array :machines do
>> scalar :href
>> inherit :machine
>> end
>>
>> The 'inherit' method will 'copy' schema from Machine model to this Array, so
>> then the CIMIExpand parameter should be used properly (Collection entity will
>> contain a full entity with all properties).
>>
>> Cheers,
>> Michal
>>
>
------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
Re: CIMI: CIMISelect filter added
Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK - very nice - just 1 thought: looking at CIMISelect - not sure it
applies only to *_Collection - so for example you want to GET Machine
but only see the name and volumes attributes:
GET /cimi/machines/my_machine?CIMISelect=name&CIMISelect=volumes
marios
On 08/12/11 14:19, mfojtik@redhat.com wrote:
> Hi,
>
> This patch add new parameter for all :index operations in CIMI.
> CIMISelect is described as optional Collection paramter in 4.1.6.1.
>
> Currently you can do:
>
> curl -H 'Accept: application/xml' --user 'mockuser:mockpassword' 'http://localhost:3001/cimi/machines?CIMISelect=name'
>
> The output will be limited to just 'name' element.
>
> curl -H 'Accept: application/xml' --user 'mockuser:mockpassword' 'http://localhost:3001/cimi/machines?CIMISelect=machines'
>
> Only machines array will be displayed in MachineCollection
>
> curl -H 'Accept: application/xml' --user 'mockuser:mockpassword' 'http://localhost:3001/cimi/machines?CIMISelect=machines[1]'
>
> Only first machine in array will be displayed in MachineCollection
>
> curl -H 'Accept: application/xml' --user 'mockuser:mockpassword' 'http://localhost:3001/cimi/machines?CIMISelect=machines[1-10]'
>
> Only first ten machines will be displayed (similar to Ruby Range, usefull for pagination, etc..)
>
> I found some inconsistencies between JSON and XML. All filter names currently
> work onyl with JSON names (machine_configurations, etc..) so the XML tag names
> are ignored (machineConfiguration). There is no notion if in XML you should use
> the xml tag name in filter name or not.
>
> There is also secondary parameter 'CIMIExpand' that will expand the Entity in
> Collection. Practically it will display a full Machine entity instead of
> reference. Currently the Collection models are defined to hold only references.
> I was thinking about adding something like:
>
> array :machines do
> scalar :href
> inherit :machine
> end
>
> The 'inherit' method will 'copy' schema from Machine model to this Array, so
> then the CIMIExpand parameter should be used properly (Collection entity will
> contain a full entity with all properties).
>
> Cheers,
> Michal
>
[PATCH core] CIMI: Added CIMISelect query param to filter Collection output
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/cimi/model/base.rb | 32 ++++++++++++++++++++++++++++++++
server/lib/cimi/server.rb | 25 ++++++++++++++-----------
2 files changed, 46 insertions(+), 11 deletions(-)
diff --git a/server/lib/cimi/model/base.rb b/server/lib/cimi/model/base.rb
index cd49518..30ee240 100644
--- a/server/lib/cimi/model/base.rb
+++ b/server/lib/cimi/model/base.rb
@@ -209,4 +209,36 @@ class CIMI::Model::Base
end
def self.all(_self); find(:all, _self); end
+
+ def filter_by(filter_opts)
+ return self if filter_opts.nil?
+ return filter_attributes(filter_opts.split(',').map{ |a| a.intern }) if filter_opts.include? ','
+ case filter_opts
+ when /^([\w\_]+)$/ then filter_attributes([$1.intern])
+ when /^([\w\_]+)\[(\d+\-\d+)\]$/ then filter_by_arr_range($1.intern, $2)
+ when /^([\w\_]+)\[(\d+)\]$/ then filter_by_arr_index($1.intern, $2)
+ else self
+ end
+ end
+
+ private
+
+ def filter_attributes(attr_list)
+ attrs = attr_list.inject({}) do |result, attr|
+ result[attr] = self.send(attr) if self.respond_to?(attr)
+ result
+ end
+ self.class.new(attrs)
+ end
+
+ def filter_by_arr_index(attr, filter)
+ return self unless self.respond_to?(attr)
+ self.class.new(attr => [self.send(attr)[filter.to_i]])
+ end
+
+ def filter_by_arr_range(attr, filter)
+ return self unless self.respond_to?(attr)
+ filter = filter.split('-').inject { |s,e| s.to_i..e.to_i }
+ self.class.new(attr => self.send(attr)[filter])
+ end
end
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index 746587c..296e29b 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -92,9 +92,10 @@ global_collection :machine_configurations do
description 'List all machine configurations'
operation :index do
+ param :CIMISelect, :string, :optional
description "List all machine configurations"
control do
- machine_configs = MachineConfigurationCollection.default(self)
+ machine_configs = MachineConfigurationCollection.default(self).filter_by(params[:CIMISelect])
respond_to do |format|
format.xml { machine_configs.to_xml }
format.json { machine_configs.to_json }
@@ -125,8 +126,9 @@ global_collection :machine_images do
operation :index do
description "List all machine configurations"
+ param :CIMISelect, :string, :optional
control do
- machine_images = MachineImageCollection.default(self)
+ machine_images = MachineImageCollection.default(self).filter_by(params[:CIMISelect])
respond_to do |format|
format.xml { machine_images.to_xml }
format.json { machine_images.to_json }
@@ -153,9 +155,10 @@ global_collection :machine_admins do
operation :index do
description "List all machine admins"
+ param :CIMISelect, :string, :optional
with_capability :keys
control do
- machine_admins = MachineAdminCollection.default(self)
+ machine_admins = MachineAdminCollection.default(self).filter_by(params[:CIMISelect])
respond_to do |format|
format.xml { machine_admins.to_xml }
format.json { machine_admins.to_json }
@@ -208,9 +211,10 @@ global_collection :machines do
description 'List all machine'
operation :index do
+ param :CIMISelect, :string, :optional
description "List all machines"
control do
- machines = MachineCollection.default(self)
+ machines = MachineCollection.default(self).filter_by(params[:CIMISelect])
respond_to do |format|
format.xml { machines.to_xml }
format.json { machines.to_json }
@@ -313,8 +317,9 @@ global_collection :volumes do
operation :index do
description "List all volumes"
+ param :CIMISelect, :string, :optional
control do
- volumes = VolumeCollection.default(self)
+ volumes = VolumeCollection.default(self).filter_by(params[:CIMISelect])
respond_to do |format|
format.xml { volumes.to_xml }
format.json { volumes.to_json }
@@ -334,7 +339,6 @@ global_collection :volumes do
end
end
-
operation :create do
description "Create a new Volume."
control do
@@ -361,9 +365,6 @@ global_collection :volumes do
end
end
-
-
-
end
global_collection :volume_configurations do
@@ -371,8 +372,9 @@ global_collection :volume_configurations do
operation :index do
description "Get list all VolumeConfigurations"
+ param :CIMISelect, :string, :optional
control do
- volume_configuration = VolumeConfigurationCollection.default(self)
+ volume_configuration = VolumeConfigurationCollection.default(self).filter_by(params[:CIMISelect])
respond_to do |format|
format.xml { volume_configuration.to_xml }
format.json { volume_configuration.to_json }
@@ -397,8 +399,9 @@ global_collection :volume_images do
operation :index do
description "List all volumes images"
+ param :CIMISelect, :string, :optional
control do
- volume_images = VolumeImageCollection.default(self)
+ volume_images = VolumeImageCollection.default(self).filter_by(params[:CIMISelect])
respond_to do |format|
format.xml { volume_images.to_xml }
format.json { volume_images.to_json }
--
1.7.4.4