[Ovirt-devel] [PATCH 2/5] API for storage pools
David Lutterkort
dlutter at redhat.com
Thu Aug 7 00:00:16 UTC 2008
- List and filter storage pools by ipaddr, path, target and hardware_pool_id
- Show an individual storage pool
- Create a new storage pool
- Destroy a storage pool
---
.../controllers/rest/storage_pools_controller.rb | 60 ++++++++++++++++++++
wui/src/config/routes.rb | 1 +
2 files changed, 61 insertions(+), 0 deletions(-)
create mode 100644 wui/src/app/controllers/rest/storage_pools_controller.rb
diff --git a/wui/src/app/controllers/rest/storage_pools_controller.rb b/wui/src/app/controllers/rest/storage_pools_controller.rb
new file mode 100644
index 0000000..99eb158
--- /dev/null
+++ b/wui/src/app/controllers/rest/storage_pools_controller.rb
@@ -0,0 +1,60 @@
+class Rest::StoragePoolsController < ApplicationController
+
+ EQ_ATTRIBUTES = [ :ip_addr, :export_path, :target,
+ :hardware_pool_id ]
+
+ def index
+ conditions = []
+ EQ_ATTRIBUTES.each do |attr|
+ if params[attr]
+ conditions << "#{attr} = :#{attr}"
+ end
+ end
+
+ @storage = StoragePool.find(:all,
+ :conditions => [conditions.join(" and "), params],
+ :order => "id")
+
+ respond_to do |format|
+ format.xml { render :xml => @storage.to_xml }
+ end
+ end
+
+ def show
+ @storage = StoragePool.find(params[:id])
+ respond_to do |format|
+ format.xml { render :xml => @storage.to_xml }
+ end
+ end
+
+ def create
+ # Somehow the attribute 'type' never makes it through
+ # Maybe because there is a (deprecated) Object.type ?
+ pool = params[:storage_pool]
+ type = pool[:storage_type]
+ pool.delete(:storage_type)
+ @storage_pool = StoragePool.factory(type, pool)
+ respond_to do |format|
+ if @storage_pool
+ if @storage_pool.save
+ format.xml { render :xml => @storage_pool,
+ :status => :created,
+ :location => rest_storage_pool_url(@storage_pool) }
+ else
+ format.xml { render :xml => @storage_pool.errors,
+ :status => :unprocessable_entity }
+ end
+ else
+ format.xml { render :xml => "Illegal storage type #{params[:storage_type]}", :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ def destroy
+ @storage_pool = StoragePool.find(params[:id])
+ @storage_pool.destroy
+ respond_to do |format|
+ format.xml { head :ok }
+ end
+ end
+end
diff --git a/wui/src/config/routes.rb b/wui/src/config/routes.rb
index e7aa0be..993a885 100644
--- a/wui/src/config/routes.rb
+++ b/wui/src/config/routes.rb
@@ -21,6 +21,7 @@ ActionController::Routing::Routes.draw do |map|
map.namespace(:rest) do |rest|
rest.resources :hosts
+ rest.resources :storage_pools
end
--
1.5.5.1
More information about the ovirt-devel
mailing list