[Ovirt-devel] [PATCH 4/5] Find hardware_pool by path; search by parent_id
David Lutterkort
dlutter at redhat.com
Thu Aug 7 00:00:18 UTC 2008
Get individual hardware pool with a path, e.g. with a GET to
/ovirt/hardware_pools?path=/default/foo/bar
Get children of a hardware pool from
/ovirt/hardware_pools?parent_id=1
Get specific child with
/ovirt/hardware_pools?parent_id=1&name=foo
---
.../controllers/rest/hardware_pools_controller.rb | 25 ++++++++++++-------
wui/src/app/models/hardware_pool.rb | 12 +++++++++
2 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/wui/src/app/controllers/rest/hardware_pools_controller.rb b/wui/src/app/controllers/rest/hardware_pools_controller.rb
index 49a8fcc..836d5f2 100644
--- a/wui/src/app/controllers/rest/hardware_pools_controller.rb
+++ b/wui/src/app/controllers/rest/hardware_pools_controller.rb
@@ -3,19 +3,26 @@ class Rest::HardwarePoolsController < ApplicationController
:include => [ :storage_pools, :hosts, :quota ]
}
- EQ_ATTRIBUTES = [ :name ]
+ EQ_ATTRIBUTES = [ :name, :parent_id ]
def index
- conditions = []
- EQ_ATTRIBUTES.each do |attr|
- if params[attr]
- conditions << "#{attr} = :#{attr}"
+ if params[:path]
+ @pools = []
+ pool = HardwarePool.find_by_path(params[:path])
+ @pools << pool if pool
+ logger.info "POOLS: #{@pools.inspect}"
+ else
+ conditions = []
+ EQ_ATTRIBUTES.each do |attr|
+ if params[attr]
+ conditions << "#{attr} = :#{attr}"
+ end
end
- end
- @pools = HardwarePool.find(:all,
- :conditions => [conditions.join(" and "), params],
- :order => "id")
+ @pools = HardwarePool.find(:all,
+ :conditions => [conditions.join(" and "), params],
+ :order => "id")
+ end
respond_to do |format|
format.xml { render :xml => @pools.to_xml(OPTS) }
diff --git a/wui/src/app/models/hardware_pool.rb b/wui/src/app/models/hardware_pool.rb
index 276779f..249d744 100644
--- a/wui/src/app/models/hardware_pool.rb
+++ b/wui/src/app/models/hardware_pool.rb
@@ -97,4 +97,16 @@ class HardwarePool < Pool
return {:total => total, :labels => labels}
end
+ def self.find_by_path(path)
+ segs = path.split("/")
+ unless segs.shift.empty?
+ raise "Path must be absolute, but is #{path}"
+ end
+ if segs.shift == "default"
+ segs.inject(get_default_pool) do |pool, seg|
+ pool.sub_hardware_pools.find { |p| p.name == seg } if pool
+ end
+ end
+ end
+
end
--
1.5.5.1
More information about the ovirt-devel
mailing list