[Ovirt-devel] [PATCH 2/6] API access to hosts
David Lutterkort
dlutter at redhat.com
Thu Aug 14 23:43:48 UTC 2008
- List hosts and filter the list by state, arch, hostname, uuid and
hardware_pool_id
- Retrieve an individual host
The routing maps this to /ovirt/hosts and /ovirt/hosts/#{id}
Signed-off-by: David Lutterkort <dlutter at redhat.com>
---
wui/src/app/controllers/host_controller.rb | 28 ++++++++++++++++++++++++----
wui/src/config/routes.rb | 7 +++++++
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/wui/src/app/controllers/host_controller.rb b/wui/src/app/controllers/host_controller.rb
index 4e4375a..5174c88 100644
--- a/wui/src/app/controllers/host_controller.rb
+++ b/wui/src/app/controllers/host_controller.rb
@@ -18,19 +18,36 @@
# also available at http://www.gnu.org/copyleft/gpl.html.
class HostController < ApplicationController
+
+ EQ_ATTRIBUTES = [ :state, :arch, :hostname, :uuid,
+ :hardware_pool_id ]
+
def index
list
- render :action => 'list'
+ respond_to do |format|
+ format.html { render :action => 'list' }
+ format.xml { render :xml => @hosts.to_xml }
+ end
end
before_filter :pre_action, :only => [:host_action, :enable, :disable, :clear_vms]
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
- verify :method => :post, :only => [ :destroy, :create, :update ],
+ verify :method => [:post, :put], :only => [ :create, :update ],
+ :redirect_to => { :action => :list }
+ verify :method => [:post, :delete], :only => :destroy,
:redirect_to => { :action => :list }
def list
- @hosts = Host.find(:all) if @hosts.nil?
+ conditions = []
+ EQ_ATTRIBUTES.each do |attr|
+ if params[attr]
+ conditions << "#{attr} = :#{attr}"
+ end
+ end
+ @hosts = Host.find(:all,
+ :conditions => [conditions.join(" and "), params],
+ :order => "id")
end
@@ -41,7 +58,10 @@ class HostController < ApplicationController
#perm errors for ajax should be done differently
redirect_to :controller => 'dashboard', :action => 'list'
end
- render :layout => 'selection'
+ respond_to do |format|
+ format.html { render :layout => 'selection' }
+ format.xml { render :xml => @host.to_xml }
+ end
end
def quick_summary
diff --git a/wui/src/config/routes.rb b/wui/src/config/routes.rb
index a93ba4b..241cac6 100644
--- a/wui/src/config/routes.rb
+++ b/wui/src/config/routes.rb
@@ -43,4 +43,11 @@ ActionController::Routing::Routes.draw do |map|
# Install the default route as the lowest priority.
map.connect ':controller/:action/:id.:format'
map.connect ':controller/:action/:id'
+
+ # We put routes for the REST API _after_ the default routes so that we
+ # don't disturb existing routes for the WUI
+ # FIXME: Eventually, we want to rename the controllers in a way that makes
+ # REST work out of the box, and use these as the default routes
+ map.resources :hosts, :controller => 'host'
+
end
--
1.5.5.1
More information about the ovirt-devel
mailing list