From: Michal Fojtik <[email protected]>

---
 src/app/controllers/pool_controller.rb     |  134 --------------------------
 src/app/controllers/pools_controller.rb    |  143 ++++++++++++++++++++++++++++
 src/app/views/pool/delete.haml             |    2 -
 src/app/views/pool/edit.haml               |    1 -
 src/app/views/pool/hardware_profiles.haml  |    1 -
 src/app/views/pool/index.haml              |    8 --
 src/app/views/pool/list.haml               |    3 -
 src/app/views/pool/new.haml                |   14 ---
 src/app/views/pool/realms.haml             |    1 -
 src/app/views/pool/show.haml               |   12 ---
 src/app/views/pools/delete.haml            |    2 +
 src/app/views/pools/edit.haml              |    1 +
 src/app/views/pools/hardware_profiles.haml |    1 +
 src/app/views/pools/index.haml             |   27 +++++
 src/app/views/pools/list.haml              |    3 +
 src/app/views/pools/new.haml               |   14 +++
 src/app/views/pools/realms.haml            |    1 +
 src/app/views/pools/show.haml              |   12 +++
 src/config/routes.rb                       |    2 +-
 19 files changed, 205 insertions(+), 177 deletions(-)
 delete mode 100644 src/app/controllers/pool_controller.rb
 create mode 100644 src/app/controllers/pools_controller.rb
 delete mode 100644 src/app/views/pool/delete.haml
 delete mode 100644 src/app/views/pool/edit.haml
 delete mode 100644 src/app/views/pool/hardware_profiles.haml
 delete mode 100644 src/app/views/pool/index.haml
 delete mode 100644 src/app/views/pool/list.haml
 delete mode 100644 src/app/views/pool/new.haml
 delete mode 100644 src/app/views/pool/realms.haml
 delete mode 100644 src/app/views/pool/show.haml
 create mode 100644 src/app/views/pools/delete.haml
 create mode 100644 src/app/views/pools/edit.haml
 create mode 100644 src/app/views/pools/hardware_profiles.haml
 create mode 100644 src/app/views/pools/index.haml
 create mode 100644 src/app/views/pools/list.haml
 create mode 100644 src/app/views/pools/new.haml
 create mode 100644 src/app/views/pools/realms.haml
 create mode 100644 src/app/views/pools/show.haml

diff --git a/src/app/controllers/pool_controller.rb 
b/src/app/controllers/pool_controller.rb
deleted file mode 100644
index 187da09..0000000
--- a/src/app/controllers/pool_controller.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-#
-# Copyright (C) 2009 Red Hat, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA  02110-1301, USA.  A copy of the GNU General Public License is
-# also available at http://www.gnu.org/copyleft/gpl.html.
-
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
-
-require 'util/taskomatic'
-require 'util/condormatic'
-
-class PoolController < ApplicationController
-  before_filter :require_user, :get_nav_items
-
-  def index
-    render :action => 'new'
-  end
-
-  def show
-    @pool = Pool.find(params[:id])
-  end
-
-  def edit
-    @pool = Pool.find(params[:id])
-  end
-
-  def list
-    #FIXME: clean this up, many error cases here
-    @pool = Pool.find(params[:id])
-    require_privilege(Privilege::INSTANCE_VIEW,@pool)
-    @pool.reload
-
-    @order_dir = params[:order_dir] == 'desc' ? 'desc' : 'asc'
-    @order = params[:order] || 'name'
-
-    @instances = Instance.search_filter(params[:search], 
Instance::SEARCHABLE_COLUMNS).paginate(
-      :page => params[:page] || 1,
-      :order => @order + ' ' + @order_dir,
-      :conditions => {:pool_id => @pool.id}
-    )
-
-    if request.xhr? and params[:partial]
-      render :partial => 'instance/instances'
-      return
-    end
-  end
-
-  def hardware_profiles
-    @pool = Pool.find(params[:id])
-    @hardware_profiles = @pool.hardware_profiles
-    require_privilege(Privilege::POOL_VIEW, @pool)
-  end
-
-  def realms
-    @pool = Pool.find(params[:id])
-    @realm_names = @pool.realms
-    require_privilege(Privilege::POOL_VIEW,@pool)
-  end
-
-  def new
-    require_privilege(Privilege::POOL_MODIFY)
-    @pools = Pool.list_for_user(@current_user, Privilege::POOL_MODIFY)
-    @pool = Pool.new
-  end
-
-  def create
-    require_privilege(Privilege::POOL_MODIFY)
-
-    #FIXME: owner is set to current user for self-service account creation,
-    # but in the more general case we need a way for the admin to pick
-    # a user
-    params[:pool][:owner_id] = @current_user.id
-
-    #FIXME: This should probably be in a transaction
-    @pool = Pool.new(params[:pool])
-    # FIXME: do we need any more handling around save failures? What if perm
-    #        creation fails?
-
-    quota = Quota.new
-    quota.save!
-
-    @pool.quota_id = quota.id
-
-    @pool.zone = Zone.default
-    @pool.save!
-    perm = Permission.new(:user => @pool.owner,
-                          :role => Role.find_by_name("Instance Creator and 
User"),
-                          :permission_object => @pool)
-    perm.save!
-
-    flash[:notice] = "Pool added."
-    redirect_to :action => 'show', :id => @pool.id
-  end
-
-  def delete
-  end
-
-  def accounts_for_pool
-    @pool =  Pool.find(params[:pool_id])
-    require_privilege(Privilege::ACCOUNT_VIEW,@pool)
-    @cloud_accounts = []
-    all_accounts = CloudAccount.list_for_user(@current_user, 
Privilege::ACCOUNT_ADD)
-    all_accounts.each {|account|
-      @cloud_accounts << account unless @pool.cloud_accounts.map{|x| 
x.id}.include?(account.id)
-    }
-  end
-
-  def add_account
-    @pool = Pool.find(params[:pool])
-    @cloud_account = CloudAccount.find(params[:cloud_account])
-    require_privilege(Privilege::ACCOUNT_ADD,@pool)
-    require_privilege(Privilege::ACCOUNT_ADD,@cloud_account)
-    Pool.transaction do
-      @pool.cloud_accounts << @cloud_account unless 
@pool.cloud_accounts.map{|x| x.id}.include?(@cloud_account.id)
-      @pool.save!
-      @pool.populate_realms_and_images([...@cloud_account])
-    end
-    redirect_to :action => 'show', :id => @pool.id
-  end
-  condormatic_classads_sync
-end
diff --git a/src/app/controllers/pools_controller.rb 
b/src/app/controllers/pools_controller.rb
new file mode 100644
index 0000000..f400a29
--- /dev/null
+++ b/src/app/controllers/pools_controller.rb
@@ -0,0 +1,143 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.  A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+require 'util/taskomatic'
+require 'util/condormatic'
+
+class PoolsController < ApplicationController
+  before_filter :require_user, :get_nav_items
+
+  def index
+    @header = [
+      { :name => "Pool name", :sort_attr => :name },
+      { :name => "% Quota used", :sortable => false },
+      { :name => "Quota (Instances)", :sort_attr => "quotas.total_instances"},
+      { :name => "Zone", :sort_attr => "zones.name" }
+    ]
+    @pools = Pool.paginate(:all, :include => [ :quota, :zone ],
+      :page => params[:page] || 1,
+      :order => (params[:order_field] || 'name') +' '+ (params[:order_dir] || 
'asc')
+    )
+  end
+
+  def show
+    @pool = Pool.find(params[:id])
+  end
+
+  def edit
+    @pool = Pool.find(params[:id])
+  end
+
+  def list
+    #FIXME: clean this up, many error cases here
+    @pool = Pool.find(params[:id])
+    require_privilege(Privilege::INSTANCE_VIEW,@pool)
+    @pool.reload
+
+    @order_dir = params[:order_dir] == 'desc' ? 'desc' : 'asc'
+    @order = params[:order] || 'name'
+
+    @instances = Instance.search_filter(params[:search], 
Instance::SEARCHABLE_COLUMNS).paginate(
+      :page => params[:page] || 1,
+      :order => @order + ' ' + @order_dir,
+      :conditions => {:pool_id => @pool.id}
+    )
+
+    if request.xhr? and params[:partial]
+      render :partial => 'instance/instances'
+      return
+    end
+  end
+
+  def hardware_profiles
+    @pool = Pool.find(params[:id])
+    @hardware_profiles = @pool.hardware_profiles
+    require_privilege(Privilege::POOL_VIEW, @pool)
+  end
+
+  def realms
+    @pool = Pool.find(params[:id])
+    @realm_names = @pool.realms
+    require_privilege(Privilege::POOL_VIEW,@pool)
+  end
+
+  def new
+    require_privilege(Privilege::POOL_MODIFY)
+    @pools = Pool.list_for_user(@current_user, Privilege::POOL_MODIFY)
+    @pool = Pool.new
+  end
+
+  def create
+    require_privilege(Privilege::POOL_MODIFY)
+
+    #FIXME: owner is set to current user for self-service account creation,
+    # but in the more general case we need a way for the admin to pick
+    # a user
+    params[:pool][:owner_id] = @current_user.id
+
+    #FIXME: This should probably be in a transaction
+    @pool = Pool.new(params[:pool])
+    # FIXME: do we need any more handling around save failures? What if perm
+    #        creation fails?
+
+    quota = Quota.new
+    quota.save!
+
+    @pool.quota_id = quota.id
+
+    @pool.zone = Zone.default
+    @pool.save!
+    perm = Permission.new(:user => @pool.owner,
+                          :role => Role.find_by_name("Instance Creator and 
User"),
+                          :permission_object => @pool)
+    perm.save!
+
+    flash[:notice] = "Pool added."
+    redirect_to :action => 'show', :id => @pool.id
+  end
+
+  def delete
+  end
+
+  def accounts_for_pool
+    @pool =  Pool.find(params[:pool_id])
+    require_privilege(Privilege::ACCOUNT_VIEW,@pool)
+    @cloud_accounts = []
+    all_accounts = CloudAccount.list_for_user(@current_user, 
Privilege::ACCOUNT_ADD)
+    all_accounts.each {|account|
+      @cloud_accounts << account unless @pool.cloud_accounts.map{|x| 
x.id}.include?(account.id)
+    }
+  end
+
+  def add_account
+    @pool = Pool.find(params[:pool])
+    @cloud_account = CloudAccount.find(params[:cloud_account])
+    require_privilege(Privilege::ACCOUNT_ADD,@pool)
+    require_privilege(Privilege::ACCOUNT_ADD,@cloud_account)
+    Pool.transaction do
+      @pool.cloud_accounts << @cloud_account unless 
@pool.cloud_accounts.map{|x| x.id}.include?(@cloud_account.id)
+      @pool.save!
+      @pool.populate_realms_and_images([...@cloud_account])
+    end
+    redirect_to :action => 'show', :id => @pool.id
+  end
+  condormatic_classads_sync
+end
diff --git a/src/app/views/pool/delete.haml b/src/app/views/pool/delete.haml
deleted file mode 100644
index 6727d77..0000000
--- a/src/app/views/pool/delete.haml
+++ /dev/null
@@ -1,2 +0,0 @@
-%h1 ProviderController#delete
-%p Find me in app/views/provider_controller/delete.html.erb
diff --git a/src/app/views/pool/edit.haml b/src/app/views/pool/edit.haml
deleted file mode 100644
index 755ecd9..0000000
--- a/src/app/views/pool/edit.haml
+++ /dev/null
@@ -1 +0,0 @@
-%h1 Edit Pool '#[email protected]}'
diff --git a/src/app/views/pool/hardware_profiles.haml 
b/src/app/views/pool/hardware_profiles.haml
deleted file mode 100644
index 96fe378..0000000
--- a/src/app/views/pool/hardware_profiles.haml
+++ /dev/null
@@ -1 +0,0 @@
-= render :partial => 'hardware_profiles/list'
diff --git a/src/app/views/pool/index.haml b/src/app/views/pool/index.haml
deleted file mode 100644
index 6b5432a..0000000
--- a/src/app/views/pool/index.haml
+++ /dev/null
@@ -1,8 +0,0 @@
-- if @pools.size == 0
-  %h1 There are no pools to display
-- else
-  - @pools.each {|pool|
-  = pool.name
-  %br/
-  - }
-= link_to "Add a pool", :controller => "pool", :action => "new", :provider => 
@provider
diff --git a/src/app/views/pool/list.haml b/src/app/views/pool/list.haml
deleted file mode 100644
index 2014ed9..0000000
--- a/src/app/views/pool/list.haml
+++ /dev/null
@@ -1,3 +0,0 @@
-= render :partial => "instance/instances"
-
-= link_to "Add a new instance", {:controller => "instance", :action => "new", 
"instance[pool_id]" => @pool}, :class=>"actionlink"
diff --git a/src/app/views/pool/new.haml b/src/app/views/pool/new.haml
deleted file mode 100644
index 119a4f2..0000000
--- a/src/app/views/pool/new.haml
+++ /dev/null
@@ -1,14 +0,0 @@
-.dcloud_form
-  = error_messages_for 'pool'
-  = error_messages_for 'account'
-  %h2 Create a new Pool
-  %br/
-  - form_tag :action => 'create' do
-    %legend Pool
-    %ul
-      %li
-        %label
-          Name
-          %span Provide a descriptive name for this pool.
-        = text_field :pool, :name
-    = submit_tag "Save", :class => "submit"
diff --git a/src/app/views/pool/realms.haml b/src/app/views/pool/realms.haml
deleted file mode 100644
index 31f7886..0000000
--- a/src/app/views/pool/realms.haml
+++ /dev/null
@@ -1 +0,0 @@
-= render :partial => 'realms/list'
diff --git a/src/app/views/pool/show.haml b/src/app/views/pool/show.haml
deleted file mode 100644
index 8f066d9..0000000
--- a/src/app/views/pool/show.haml
+++ /dev/null
@@ -1,12 +0,0 @@
-:javascript
-  $(document).ready(function() {
-    $("#pool-tabs").tabs();
-  });
-#pool-tabs
-  %ul
-    %li= link_to "Instances", {:action => "list", :id => @pool.id, :ajax => 
true}
-    - if has_view_perms?
-      %li= link_to "User access",  {:controller => "permissions", :action => 
"list", :pool_id => @pool.id, :ajax => true}
-    %li= link_to "Hardware Profiles",  {:action => "hardware_profiles", :id => 
@pool.id, :ajax => true}
-    %li= link_to "Realms",  {:action => "realms", :id => @pool.id, :ajax => 
true}
-    %li= link_to "Quota",  {:controller => "quota", :action => "show", :id => 
@pool, :parent_type => "pool", :ajax => true}
diff --git a/src/app/views/pools/delete.haml b/src/app/views/pools/delete.haml
new file mode 100644
index 0000000..6727d77
--- /dev/null
+++ b/src/app/views/pools/delete.haml
@@ -0,0 +1,2 @@
+%h1 ProviderController#delete
+%p Find me in app/views/provider_controller/delete.html.erb
diff --git a/src/app/views/pools/edit.haml b/src/app/views/pools/edit.haml
new file mode 100644
index 0000000..755ecd9
--- /dev/null
+++ b/src/app/views/pools/edit.haml
@@ -0,0 +1 @@
+%h1 Edit Pool '#[email protected]}'
diff --git a/src/app/views/pools/hardware_profiles.haml 
b/src/app/views/pools/hardware_profiles.haml
new file mode 100644
index 0000000..96fe378
--- /dev/null
+++ b/src/app/views/pools/hardware_profiles.haml
@@ -0,0 +1 @@
+= render :partial => 'hardware_profiles/list'
diff --git a/src/app/views/pools/index.haml b/src/app/views/pools/index.haml
new file mode 100644
index 0000000..3befc64
--- /dev/null
+++ b/src/app/views/pools/index.haml
@@ -0,0 +1,27 @@
+#pools_nav{:class => 'grid_3'}
+  %dl
+    %dt
+      Pools
+    %dd.create
+      =link_to 'New Pool', :action => :new
+    %dd.edit  
+      =link_to 'Edit Pool', :action => :edit
+    %dd.delete
+      =link_to 'Remove Pool', :action => :destroy
+#details{:class => 'grid_13'}
+  %h1 Manage Pools
+
+  %table
+    =sortable_table_header @header
+    %tbody
+    - @pools.each do |pool|
+      %tr
+        %td
+          =pool.name
+        %td
+          =((pool.quota.maximum_running_instances || 
0)/100)*pool.quota.total_instances
+          ='%'
+        %td
+          =pool.quota.total_instances
+        %td
+          =pool.zone.name
diff --git a/src/app/views/pools/list.haml b/src/app/views/pools/list.haml
new file mode 100644
index 0000000..2014ed9
--- /dev/null
+++ b/src/app/views/pools/list.haml
@@ -0,0 +1,3 @@
+= render :partial => "instance/instances"
+
+= link_to "Add a new instance", {:controller => "instance", :action => "new", 
"instance[pool_id]" => @pool}, :class=>"actionlink"
diff --git a/src/app/views/pools/new.haml b/src/app/views/pools/new.haml
new file mode 100644
index 0000000..119a4f2
--- /dev/null
+++ b/src/app/views/pools/new.haml
@@ -0,0 +1,14 @@
+.dcloud_form
+  = error_messages_for 'pool'
+  = error_messages_for 'account'
+  %h2 Create a new Pool
+  %br/
+  - form_tag :action => 'create' do
+    %legend Pool
+    %ul
+      %li
+        %label
+          Name
+          %span Provide a descriptive name for this pool.
+        = text_field :pool, :name
+    = submit_tag "Save", :class => "submit"
diff --git a/src/app/views/pools/realms.haml b/src/app/views/pools/realms.haml
new file mode 100644
index 0000000..31f7886
--- /dev/null
+++ b/src/app/views/pools/realms.haml
@@ -0,0 +1 @@
+= render :partial => 'realms/list'
diff --git a/src/app/views/pools/show.haml b/src/app/views/pools/show.haml
new file mode 100644
index 0000000..8f066d9
--- /dev/null
+++ b/src/app/views/pools/show.haml
@@ -0,0 +1,12 @@
+:javascript
+  $(document).ready(function() {
+    $("#pool-tabs").tabs();
+  });
+#pool-tabs
+  %ul
+    %li= link_to "Instances", {:action => "list", :id => @pool.id, :ajax => 
true}
+    - if has_view_perms?
+      %li= link_to "User access",  {:controller => "permissions", :action => 
"list", :pool_id => @pool.id, :ajax => true}
+    %li= link_to "Hardware Profiles",  {:action => "hardware_profiles", :id => 
@pool.id, :ajax => true}
+    %li= link_to "Realms",  {:action => "realms", :id => @pool.id, :ajax => 
true}
+    %li= link_to "Quota",  {:controller => "quota", :action => "show", :id => 
@pool, :parent_type => "pool", :ajax => true}
diff --git a/src/config/routes.rb b/src/config/routes.rb
index acb2b3f..b416b2f 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -33,7 +33,7 @@ ActionController::Routing::Routes.draw do |map|
   # -- just remember to delete public/index.html.
 
 
-  map.resources :pool
+  map.resources :pools
 
   map.connect '', :controller => 'dashboard'
 
-- 
1.7.2.3

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to