You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2012/11/08 18:13:51 UTC
[5/15] git commit: CIMI: make $select work for collections
CIMI: make $select work for collections
It has to filter on the attributes of the collection members
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/a9215fcd
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/a9215fcd
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/a9215fcd
Branch: refs/heads/master
Commit: a9215fcd656c2a5292d3a6104526ea5e977cf5fe
Parents: ad1157a
Author: David Lutterkort <lu...@redhat.com>
Authored: Wed Nov 7 18:17:47 2012 -0800
Committer: David Lutterkort <lu...@redhat.com>
Committed: Thu Nov 8 09:11:18 2012 -0800
----------------------------------------------------------------------
server/lib/cimi/collections/address_templates.rb | 3 +-
server/lib/cimi/collections/addresses.rb | 3 +-
server/lib/cimi/collections/credentials.rb | 3 +-
.../cimi/collections/forwarding_group_templates.rb | 3 +-
server/lib/cimi/collections/forwarding_groups.rb | 3 +-
.../lib/cimi/collections/machine_configurations.rb | 3 +-
server/lib/cimi/collections/machine_images.rb | 3 +-
server/lib/cimi/collections/machines.rb | 3 +-
.../lib/cimi/collections/network_configurations.rb | 3 +-
.../collections/network_port_configurations.rb | 3 +-
.../lib/cimi/collections/network_port_templates.rb | 3 +-
server/lib/cimi/collections/network_ports.rb | 3 +-
server/lib/cimi/collections/network_templates.rb | 3 +-
server/lib/cimi/collections/networks.rb | 3 +-
.../lib/cimi/collections/volume_configurations.rb | 3 +-
server/lib/cimi/collections/volume_images.rb | 3 +-
server/lib/cimi/collections/volumes.rb | 3 +-
server/lib/cimi/models/base.rb | 18 ++++-----
server/lib/cimi/models/collection.rb | 7 ++++
.../tests/cimi/collections/machine_images_test.rb | 29 ++++++++++++---
20 files changed, 55 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/address_templates.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/address_templates.rb b/server/lib/cimi/collections/address_templates.rb
index 6501f03..2b55e63 100644
--- a/server/lib/cimi/collections/address_templates.rb
+++ b/server/lib/cimi/collections/address_templates.rb
@@ -22,9 +22,8 @@ module CIMI::Collections
operation :index, :with_capability => :address_templates do
description 'List all AddressTemplates in the AddressTemplateCollection'
- param :CIMISelect, :string, :optional
control do
- address_templates = AddressTemplate.list(self).filter_by(params[:CIMISelect])
+ address_templates = AddressTemplate.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml {address_templates.to_xml}
format.json {address_templates.to_json}
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/addresses.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/addresses.rb b/server/lib/cimi/collections/addresses.rb
index ea9af07..a5a5986 100644
--- a/server/lib/cimi/collections/addresses.rb
+++ b/server/lib/cimi/collections/addresses.rb
@@ -24,9 +24,8 @@ module CIMI::Collections
operation :index, :with_capability => :addresses do
description 'List all Addresses in the AddressCollection'
- param :CIMISelect, :string, :optional
control do
- addresses = Address.list(self).filter_by(params[:CIMISelect])
+ addresses = Address.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml {addresses.to_xml}
format.json {addresses.to_json}
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/credentials.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/credentials.rb b/server/lib/cimi/collections/credentials.rb
index 529cf0d..24c66c0 100644
--- a/server/lib/cimi/collections/credentials.rb
+++ b/server/lib/cimi/collections/credentials.rb
@@ -23,9 +23,8 @@ module CIMI::Collections
operation :index, :with_capability => :keys do
description "List all machine admins"
- param :CIMISelect, :string, :optional
control do
- credentials = Credential.list(self).filter_by(params[:CIMISelect])
+ credentials = Credential.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml { credentials.to_xml }
format.json { credentials.to_json }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/forwarding_group_templates.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/forwarding_group_templates.rb b/server/lib/cimi/collections/forwarding_group_templates.rb
index f258001..0791276 100644
--- a/server/lib/cimi/collections/forwarding_group_templates.rb
+++ b/server/lib/cimi/collections/forwarding_group_templates.rb
@@ -21,9 +21,8 @@ module CIMI::Collections
operation :index, :with_capability => :forwarding_groups do
description 'List all ForwardingGroupTemplates in the ForwardingGroupTemplateCollection'
- param :CIMISelect, :string, :optional
control do
- forwarding_group_templates = ForwardingGroupTemplate.list(self).filter_by(params[:CIMISelect])
+ forwarding_group_templates = ForwardingGroupTemplate.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml {forwarding_group_templates.to_xml}
format.json {forwarding_group_templates.to_json}
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/forwarding_groups.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/forwarding_groups.rb b/server/lib/cimi/collections/forwarding_groups.rb
index af316e9..3de1bd5 100644
--- a/server/lib/cimi/collections/forwarding_groups.rb
+++ b/server/lib/cimi/collections/forwarding_groups.rb
@@ -21,9 +21,8 @@ module CIMI::Collections
operation :index, :with_capability => :forwarding_groups do
description 'List all ForwardingGroups in the ForwardingGroupsCollection'
- param :CIMISelect, :string, :optional
control do
- forwarding_groups = ForwardingGroup.list(self).filter_by(params[:CIMISelect])
+ forwarding_groups = ForwardingGroup.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml {forwarding_groups.to_xml}
format.json {forwarding_groups.to_json}
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/machine_configurations.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machine_configurations.rb b/server/lib/cimi/collections/machine_configurations.rb
index 30471ac..eb7833a 100644
--- a/server/lib/cimi/collections/machine_configurations.rb
+++ b/server/lib/cimi/collections/machine_configurations.rb
@@ -22,10 +22,9 @@ module CIMI::Collections
description 'List all machine configurations'
operation :index, :with_capability => :hardware_profiles do
- param :CIMISelect, :string, :optional
description "List all machine configurations"
control do
- machine_configs = MachineConfiguration.list(self).filter_by(params[:CIMISelect])
+ machine_configs = MachineConfiguration.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml { machine_configs.to_xml }
format.json { machine_configs.to_json }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/machine_images.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machine_images.rb b/server/lib/cimi/collections/machine_images.rb
index 1fb81e2..822a7d5 100644
--- a/server/lib/cimi/collections/machine_images.rb
+++ b/server/lib/cimi/collections/machine_images.rb
@@ -23,9 +23,8 @@ module CIMI::Collections
operation :index, :with_capability => :images do
description "List all machine configurations"
- param :CIMISelect, :string, :optional
control do
- machine_images = MachineImage.list(self).filter_by(params[:CIMISelect])
+ machine_images = MachineImage.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml { machine_images.to_xml }
format.json { machine_images.to_json }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/machines.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machines.rb b/server/lib/cimi/collections/machines.rb
index d255064..9f904c1 100644
--- a/server/lib/cimi/collections/machines.rb
+++ b/server/lib/cimi/collections/machines.rb
@@ -22,10 +22,9 @@ module CIMI::Collections
description 'List all machine'
operation :index, :with_capability => :instances do
- param :CIMISelect, :string, :optional
description "List all machines"
control do
- machines = Machine.list(self).filter_by(params[:CIMISelect])
+ machines = Machine.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml { machines.to_xml }
format.json { machines.to_json }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/network_configurations.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/network_configurations.rb b/server/lib/cimi/collections/network_configurations.rb
index 5fb1d3d..54c8fff 100644
--- a/server/lib/cimi/collections/network_configurations.rb
+++ b/server/lib/cimi/collections/network_configurations.rb
@@ -22,9 +22,8 @@ module CIMI::Collections
operation :index, :with_capability => :network_configurations do
description 'List all NetworkConfigurations'
- param :CIMISelect, :string, :optional
control do
- network_configurations = NetworkConfiguration.list(self).filter_by(params[:CIMISelect])
+ network_configurations = NetworkConfiguration.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml { network_configurations.to_xml }
format.json { network_configurations.to_json }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/network_port_configurations.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/network_port_configurations.rb b/server/lib/cimi/collections/network_port_configurations.rb
index 5848134..59bc194 100644
--- a/server/lib/cimi/collections/network_port_configurations.rb
+++ b/server/lib/cimi/collections/network_port_configurations.rb
@@ -22,9 +22,8 @@ module CIMI::Collections
operation :index, :with_capability => :network_port_configurations do
description 'List all NetworkPortConfigurations in the NetworkPortConfigurationCollection'
- param :CIMISelect, :string, :optional
control do
- net_port_configs = NetworkPortConfiguration.list(self).filter_by(params[:CIMISelect])
+ net_port_configs = NetworkPortConfiguration.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml {net_port_configs.to_xml}
format.json {net_port_configs.to_json}
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/network_port_templates.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/network_port_templates.rb b/server/lib/cimi/collections/network_port_templates.rb
index f588813..4c70fe9 100644
--- a/server/lib/cimi/collections/network_port_templates.rb
+++ b/server/lib/cimi/collections/network_port_templates.rb
@@ -24,9 +24,8 @@ module CIMI::Collections
operation :index, :with_capability => :network_port_templates do
description 'List all NetworkPortTemplates in the NetworkPortTemplateCollection'
- param :CIMISelect, :string, :optional
control do
- network_port_templates = NetworkPortTemplate.list(self).filter_by(params[:CIMISelect])
+ network_port_templates = NetworkPortTemplate.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml {network_port_templates.to_xml}
format.json {network_port_templates.to_json}
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/network_ports.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/network_ports.rb b/server/lib/cimi/collections/network_ports.rb
index 905d7b7..1eb71c6 100644
--- a/server/lib/cimi/collections/network_ports.rb
+++ b/server/lib/cimi/collections/network_ports.rb
@@ -24,9 +24,8 @@ module CIMI::Collections
operation :index, :with_capability => :network_ports do
description 'List all NetworkPorts in the NetworkPortCollection'
- param :CIMISelect, :string, :optional
control do
- network_ports = NetworkPort.list(self).filter_by(params[:CIMISelect])
+ network_ports = NetworkPort.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml {network_ports.to_xml}
format.json {network_ports.to_json}
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/network_templates.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/network_templates.rb b/server/lib/cimi/collections/network_templates.rb
index 3aae129..4157875 100644
--- a/server/lib/cimi/collections/network_templates.rb
+++ b/server/lib/cimi/collections/network_templates.rb
@@ -22,9 +22,8 @@ module CIMI::Collections
operation :index, :with_capability => :network_templates do
description 'List all Network Templates in the NetworkTemplateCollection'
- param :CIMISelect, :string, :optional
control do
- network_templates = NetworkTemplate.list(self).filter_by(params[:CIMISelect])
+ network_templates = NetworkTemplate.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml {network_templates.to_xml}
format.json {network_templates.to_json}
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/networks.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/networks.rb b/server/lib/cimi/collections/networks.rb
index e006503..20b0b1b 100644
--- a/server/lib/cimi/collections/networks.rb
+++ b/server/lib/cimi/collections/networks.rb
@@ -23,9 +23,8 @@ module CIMI::Collections
operation :index, :with_capability => :networks do
description "List all Networks"
- param :CIMISelect, :string, :optional
control do
- networks = Network.list(self).filter_by(params[:CIMISelect])
+ networks = Network.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml { networks.to_xml }
format.json { networks.to_json }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/volume_configurations.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/volume_configurations.rb b/server/lib/cimi/collections/volume_configurations.rb
index 7195570..91ad6b0 100644
--- a/server/lib/cimi/collections/volume_configurations.rb
+++ b/server/lib/cimi/collections/volume_configurations.rb
@@ -22,9 +22,8 @@ module CIMI::Collections
operation :index, :with_capability => :storage_volumes do
description "Get list all VolumeConfigurations"
- param :CIMISelect, :string, :optional
control do
- volume_configuration = VolumeConfiguration.list(self).filter_by(params[:CIMISelect])
+ volume_configuration = VolumeConfiguration.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml { volume_configuration.to_xml }
format.json { volume_configuration.to_json }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/volume_images.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/volume_images.rb b/server/lib/cimi/collections/volume_images.rb
index 77040b4..2a7e1af 100644
--- a/server/lib/cimi/collections/volume_images.rb
+++ b/server/lib/cimi/collections/volume_images.rb
@@ -23,9 +23,8 @@ module CIMI::Collections
operation :index, :with_capability => :storage_snapshots do
description "List all volumes images"
- param :CIMISelect, :string, :optional
control do
- volume_images = VolumeImage.list(self).filter_by(params[:CIMISelect])
+ volume_images = VolumeImage.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml { volume_images.to_xml }
format.json { volume_images.to_json }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/collections/volumes.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/volumes.rb b/server/lib/cimi/collections/volumes.rb
index 7a8d58c..319390e 100644
--- a/server/lib/cimi/collections/volumes.rb
+++ b/server/lib/cimi/collections/volumes.rb
@@ -22,9 +22,8 @@ module CIMI::Collections
operation :index, :with_capability => :storage_volumes do
description "List all volumes"
- param :CIMISelect, :string, :optional
control do
- volumes = Volume.list(self).filter_by(params[:CIMISelect])
+ volumes = Volume.list(self).filter_by(params['$select'])
respond_to do |format|
format.xml { volumes.to_xml }
format.json { volumes.to_json }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/models/base.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/base.rb b/server/lib/cimi/models/base.rb
index 668fedb..bdaa860 100644
--- a/server/lib/cimi/models/base.rb
+++ b/server/lib/cimi/models/base.rb
@@ -256,16 +256,6 @@ class CIMI::Model::Resource
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]])
@@ -285,4 +275,12 @@ class CIMI::Model::Base < CIMI::Model::Resource
text :id, :name, :description, :created
hash :property
+
+ 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
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/lib/cimi/models/collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/collection.rb b/server/lib/cimi/models/collection.rb
index b099669..48c9ccb 100644
--- a/server/lib/cimi/models/collection.rb
+++ b/server/lib/cimi/models/collection.rb
@@ -62,6 +62,13 @@ module CIMI::Model
super(a, v)
end
+ def filter_attributes(attr_list)
+ self[self.class.entry_name] = entries.map do |e|
+ e.filter_attributes(attr_list)
+ end
+ self
+ end
+
def self.xml_tag_name
"Collection"
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a9215fcd/server/tests/cimi/collections/machine_images_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/cimi/collections/machine_images_test.rb b/server/tests/cimi/collections/machine_images_test.rb
index 7a085f1..41be710 100644
--- a/server/tests/cimi/collections/machine_images_test.rb
+++ b/server/tests/cimi/collections/machine_images_test.rb
@@ -33,12 +33,29 @@ describe CIMI::Collections::MachineImages do
xml.root.name.must_equal 'MachineImage'
end
- it 'should allow to filter using CIMISelect' do
- get root_url '/machine_images?CIMISelect=description'
- status.must_equal 200
- xml.root.name.must_equal 'Collection'
- (xml/'description').wont_be_empty
- (xml/'id').must_be_empty
+ describe "filtering with $select" do
+ def machines(*select)
+ url = "/machine_images"
+ url += "?$select=#{select.join(",")}" unless select.empty?
+ get root_url url
+ status.must_equal 200
+ end
+
+ it 'should filter collection members' do
+ machines :description
+ (xml/'id').wont_be_empty
+ nimages = (xml/'MachineImage').size
+ (xml/'MachineImage/description').size.must_equal nimages
+ (xml/'MachineImage/id').must_be_empty
+ end
+
+ it 'should filter by multiple attributes' do
+ machines :description, :id
+ (xml/'id').wont_be_empty
+ nimages = (xml/'MachineImage').size
+ (xml/'MachineImage/description').size.must_equal nimages
+ (xml/'MachineImage/id').size.must_equal nimages
+ end
end
end