[Ovirt-devel] [PATCH 3/5] API for Hardware Pools
Scott Seago
sseago at redhat.com
Thu Aug 7 20:02:08 UTC 2008
David Lutterkort wrote:
> - List and filter HW pools by name
> - CRUD of individual HW pool
> - Hosts and storgae pools for a HW pool are accessible as nested resources, e.g.
> /ovirt/hardware_pools/1/hosts?hostname=myhost.example.com
> ---
> .../controllers/rest/hardware_pools_controller.rb | 85 ++++++++++++++++++++
> wui/src/config/routes.rb | 4 +
> 2 files changed, 89 insertions(+), 0 deletions(-)
> create mode 100644 wui/src/app/controllers/rest/hardware_pools_controller.rb
>
> diff --git a/wui/src/app/controllers/rest/hardware_pools_controller.rb b/wui/src/app/controllers/rest/hardware_pools_controller.rb
> new file mode 100644
> index 0000000..49a8fcc
> --- /dev/null
> +++ b/wui/src/app/controllers/rest/hardware_pools_controller.rb
> @@ -0,0 +1,85 @@
> +class Rest::HardwarePoolsController < ApplicationController
> + OPTS = {
> + :include => [ :storage_pools, :hosts, :quota ]
> + }
> +
> + EQ_ATTRIBUTES = [ :name ]
> +
> + def index
> + conditions = []
> + EQ_ATTRIBUTES.each do |attr|
> + if params[attr]
> + conditions << "#{attr} = :#{attr}"
> + end
> + end
> +
> + @pools = HardwarePool.find(:all,
> + :conditions => [conditions.join(" and "), params],
> + :order => "id")
> +
> + respond_to do |format|
> + format.xml { render :xml => @pools.to_xml(OPTS) }
> + end
> + end
> +
> + def show
> + @pool = HardwarePool.find(params[:id])
> + respond_to do |format|
> + format.xml { render :xml => @pool.to_xml(OPTS) }
> + end
> + end
> +
> + def create
> + # FIXME: Why can't I just use HardwarePool.create here ?
> + # Shouldn't that find the parent_id param ?
>
parent is not a normal association. It's a method as part of the
betternestedset API. Since the API automatically readjusts the lft/rgt
parameters when a new pool is added to the hierarchy, you can't just set
parent_id. You've got to create the pool (and save it) without a parent,
and then call set_as_parent_of (or whatever the method is called) which
sets the parent_id. Since reparenting a pool requires all of the lft/rgt
parameters of the pools in the hierarchy to be reset, this must be done
by the API call.
> + @parent = Pool.find(params[:hardware_pool][:parent_id])
> + @pool = HardwarePool.new(params[:hardware_pool])
> + # FIXME: How do we check for errors here ?
> + @pool.create_with_parent(@parent)
> + respond_to do |format|
> + format.xml { render :xml => @pool.to_xml(OPTS),
> + :status => :created,
> + :location => rest_hardware_pool_url(@pool) }
> + end
> + end
> +
> + def update
> + # We allow updating direct attributes of the HW pool and moving
> + # hosts/storage into it here.
> + @pool = HardwarePool.find(params[:id])
> + [:hosts, :storage_pools].each do |k|
> + objs = params[:hardware_pool].delete(k)
> + ids = objs.reject{ |obj| obj[:hardware_pool_id] == @pool.id}.
> + collect{ |obj| obj[:id] }
> + if ids.size > 0
> + if k == :hosts
> + # FIXME: Why does move_hosts need an explicit pool_id ?
>
The pool_id specifies what pool we're moving the hosts to, although it
probably makes sense to default this to the current ID. i.e. move_hosts
without ID moves them _here_ -- move_hosts _with_ ID moves them _there_.
Scott
More information about the ovirt-devel
mailing list