From: martyntaylor mtaylor@redhat.com
--- src/app/controllers/pool_controller.rb | 7 +++ src/app/views/pool/quota.html.erb | 55 +++++++++++++++++++++++++++ src/app/views/pool/show.html.erb | 1 + src/features/pool.feature | 27 +++++++++++++ src/features/step_definitions/pool_steps.rb | 10 +++++ src/spec/factories/quota.rb | 2 +- 6 files changed, 101 insertions(+), 1 deletions(-) create mode 100644 src/app/views/pool/quota.html.erb
diff --git a/src/app/controllers/pool_controller.rb b/src/app/controllers/pool_controller.rb index d557d57..d5fc8af 100644 --- a/src/app/controllers/pool_controller.rb +++ b/src/app/controllers/pool_controller.rb @@ -140,4 +140,11 @@ class PoolController < ApplicationController end redirect_to :action => 'show', :id => @pool.id end + + def quota + @pool = Pool.find(params[:id]) + puts @pool.id + @quota = Quota.find(:first, :conditions => { :pool_id => @pool }) + end + end diff --git a/src/app/views/pool/quota.html.erb b/src/app/views/pool/quota.html.erb new file mode 100644 index 0000000..edd4463 --- /dev/null +++ b/src/app/views/pool/quota.html.erb @@ -0,0 +1,55 @@ +<% if @quota == nil %> +<h1>There is no quota associated with this pool</h1> +<% else %> + <table> + <thead> + <tr> + <th scope="col">Resource</th> + <th scope="col">Max Capacity</th> + <th scope="col">Used Capacity</th> + <th scope="col">Free Capacity</th> + <th scope="col">% Used</th> + </tr> + </thead> + <tbody> + <tr> + <td>Running Instances</td> + <td><%= @quota.maximum_running_instances %></td> + <td><%= @quota.running_instances %></td> + <td><%= @quota.maximum_running_instances - @quota.running_instances %></td> + <td><%= percentage = (100.to_f / @quota.maximum_running_instances) * @quota.running_instances + sprintf("%.2f", percentage) %></td> + </tr> + <tr> + <td>Running Memory</td> + <td><%= @quota.maximum_running_memory %></td> + <td><%= @quota.running_memory %></td> + <td><%= @quota.maximum_running_memory - @quota.running_memory %></td> + <td><%= percentage = (100.to_f / @quota.maximum_running_memory) * @quota.running_memory + sprintf("%.2f", percentage) %></td> + <td></td> + </tr> + <tr> + <td>Running CPUs</td> + <td><%= @quota.maximum_running_cpus %></td> + <td><%= @quota.running_cpus %></td> + <td><%= @quota.maximum_running_cpus - @quota.running_cpus %></td> + <td><%= sprintf("%.2f", (100.to_f / @quota.maximum_running_cpus) * @quota.running_cpus) %></td> + </tr> + <tr> + <td>Total Instances</td> + <td><%= @quota.maximum_total_instances %></td> + <td><%= @quota.total_instances %></td> + <td><%= @quota.maximum_total_instances - @quota.total_instances %></td> + <td><%= sprintf("%.2f", (100.to_f / @quota.maximum_total_instances) * @quota.total_instances) %></td> + </tr> + <tr> + <td>Total Storage</td> + <td><%= @quota.maximum_total_storage %></td> + <td><%= @quota.total_storage %></td> + <td><%= @quota.maximum_total_storage - @quota.total_storage %></td> + <td><%= sprintf("%.2f", (100.to_f / @quota.maximum_total_storage) * @quota.total_storage) %></td> + </tr> + </tbody> + </table> +<% end %> \ No newline at end of file diff --git a/src/app/views/pool/show.html.erb b/src/app/views/pool/show.html.erb index 1230c64..2b46781 100644 --- a/src/app/views/pool/show.html.erb +++ b/src/app/views/pool/show.html.erb @@ -39,3 +39,4 @@ <%= link_to "User access", {:controller => "permissions", :action => "list", :pool_id => @pool.id}, :class=>"actionlink" if has_view_perms? %> <%= link_to "Hardware Profiles", {:action => "hardware_profiles", :id => @pool.id}, :class=>"actionlink"%> <%= link_to "Realms", {:action => "realms", :id => @pool.id}, :class=>"actionlink"%> +<%= link_to "Quota", {:action => "quota", :id => @pool}, :class=>"actionlink"%> diff --git a/src/features/pool.feature b/src/features/pool.feature index 5d8f219..7308dd4 100644 --- a/src/features/pool.feature +++ b/src/features/pool.feature @@ -45,3 +45,30 @@ Feature: Manage Pools When I follow "Realms" Then I should see "Europe" And I should see "United States" + + @tag + Scenario: View Pool's Quota Usage + Given I own a pool named "mockpool" + And the Pool has a quota with following capacities: + | resource | capacity | + | maximum_running_instances | 10 | + | maximum_running_memory | 10240 | + | maximum_running_cpus | 20 | + | maximum_total_instances | 15 | + | maximum_total_storage | 8500 | + | running_instances | 8 | + | running_memory | 9240 | + | running_cpus | 16 | + | total_instances | 15 | + | total_storage | 8400 | + And I am on the homepage + When I follow "mockpool" + Then I should be on the show pool page + When I follow "Quota" + Then I should see the following: + | Resource | Max Capacity | Used Capacity | Free Capacity | % Used | + | Running Instances | 10 | 8 | 2 | 80.00 | + | Running Memory | 10240 | 9240 | 1000 | 90.23 | + | Running CPUs | 20 | 16 | 4 | 80.00 | + | Total Instances | 15 | 15 | 0 | 100.00 | + | Total Storage | 8500 | 8400 | 100 | 98.82 | \ No newline at end of file diff --git a/src/features/step_definitions/pool_steps.rb b/src/features/step_definitions/pool_steps.rb index 3d97da6..3be5808 100644 --- a/src/features/step_definitions/pool_steps.rb +++ b/src/features/step_definitions/pool_steps.rb @@ -48,3 +48,13 @@ Then /^I should see the following:$/ do |table| end end end + +Given /^the Pool has a quota with following capacities:$/ do |table| + quota_hash = { "pool_id" => @pool, "pool" => @pool} + table.hashes.each do |hash| + quota_hash[hash["resource"]] = hash["capacity"] + end + + @quota = Factory(:quota, quota_hash) + puts @quota.pool_id +end \ No newline at end of file diff --git a/src/spec/factories/quota.rb b/src/spec/factories/quota.rb index fd0f514..ce29b9f 100644 --- a/src/spec/factories/quota.rb +++ b/src/spec/factories/quota.rb @@ -1,7 +1,7 @@ Factory.define :quota do |f| f.association :pool f.maximum_running_instances 10 - f.maximum_running_memory 102400 + f.maximum_running_memory 10240 f.maximum_running_cpus 20 f.maximum_total_instances 15 f.maximum_total_storage 8500