[Ovirt-devel] [PATCH 1/5] API access to hosts

David Lutterkort dlutter at redhat.com
Thu Aug 7 00:00:15 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/rest/hosts and /ovirt/rest/hosts/#{id}
---
 wui/src/app/controllers/rest/hosts_controller.rb   |   26 ++++++++++++++++++++
 wui/src/config/routes.rb                           |    5 ++++
 .../test/functional/rest/hosts_controller_test.rb  |    8 ++++++
 3 files changed, 39 insertions(+), 0 deletions(-)
 create mode 100644 wui/src/app/controllers/rest/hosts_controller.rb
 create mode 100644 wui/src/test/functional/rest/hosts_controller_test.rb

diff --git a/wui/src/app/controllers/rest/hosts_controller.rb b/wui/src/app/controllers/rest/hosts_controller.rb
new file mode 100644
index 0000000..2e85f65
--- /dev/null
+++ b/wui/src/app/controllers/rest/hosts_controller.rb
@@ -0,0 +1,26 @@
+class Rest::HostsController < ApplicationController
+
+    EQ_ATTRIBUTES = [ :state, :arch, :hostname, :uuid,
+                      :hardware_pool_id ]
+    def index
+        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")
+        respond_to do |format|
+            format.xml { render :xml => @hosts.to_xml }
+        end
+    end
+
+    def show
+        @host = Host.find(params[:id])
+        respond_to do |format|
+            format.xml { render :xml => @host.to_xml }
+        end
+    end
+end
diff --git a/wui/src/config/routes.rb b/wui/src/config/routes.rb
index a93ba4b..e7aa0be 100644
--- a/wui/src/config/routes.rb
+++ b/wui/src/config/routes.rb
@@ -19,6 +19,11 @@
 
 ActionController::Routing::Routes.draw do |map|
 
+    map.namespace(:rest) do |rest|
+        rest.resources :hosts
+    end
+
+
   # The priority is based upon order of creation: first created -> highest priority.
   
   # Sample of regular route:
diff --git a/wui/src/test/functional/rest/hosts_controller_test.rb b/wui/src/test/functional/rest/hosts_controller_test.rb
new file mode 100644
index 0000000..32e7931
--- /dev/null
+++ b/wui/src/test/functional/rest/hosts_controller_test.rb
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../../test_helper'
+
+class Rest::HostsControllerTest < ActionController::TestCase
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end
-- 
1.5.5.1




More information about the ovirt-devel mailing list