[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Ovirt-devel] [Patch] default quota UI for host collection



I've added default quota to the Host Collection UI. If a quota is set on the Host Collection, it will be applied, by default, to all VM Libraries in this collection -- any VM Library that sets or edits a quota will override the default quota.

Scott
diff --git a/wui/src/app/controllers/quota_controller.rb b/wui/src/app/controllers/quota_controller.rb
index 5563b40..ec842ff 100644
--- a/wui/src/app/controllers/quota_controller.rb
+++ b/wui/src/app/controllers/quota_controller.rb
@@ -25,7 +25,7 @@ class QuotaController < ApplicationController
   def set_perms
     @user = get_login_user
     if @quota.host_collection
-      @Is_admin = @quota.host_collection.is_admin(@user)
+      @is_admin = @quota.host_collection.is_admin(@user)
       @can_monitor = @quota.host_collection.can_monitor(@user)
       @can_delegate = @quota.host_collection.can_delegate(@user)
     elsif @quota.vm_library
@@ -41,7 +41,7 @@ class QuotaController < ApplicationController
 
   def redirect_to_parent
     if @quota.host_collection
-      redirect_to :controller => 'pool', :action => 'show', :id => @quota.host_collection
+      redirect_to :controller => 'collection', :action => 'show', :id => @quota.host_collection
     elsif @quota.vm_library
       redirect_to :controller => 'library', :action => 'show', :id => @quota.vm_library
     else
@@ -124,7 +124,7 @@ class QuotaController < ApplicationController
         flash[:notice] = 'destroying quota failed '
       end
       if pool_id
-        redirect_to :controller => 'pool', :action => 'show', :id => pool_id
+        redirect_to :controller => 'collection', :action => 'show', :id => pool_id
       elsif vm_library_id
         redirect_to :controller => 'library', :action => 'show', :id => vm_library_id
       else
diff --git a/wui/src/app/models/host_collection.rb b/wui/src/app/models/host_collection.rb
index 3d906c3..41ea00f 100644
--- a/wui/src/app/models/host_collection.rb
+++ b/wui/src/app/models/host_collection.rb
@@ -32,4 +32,34 @@ class HostCollection < HardwarePool
   def get_controller
     'collection'
   end
+
+  def total_resources
+    the_quota = nil
+    pool = self
+    while not(pool.nil?) and (pool[:type] == HostCollection.name)
+      if pool.quota
+        the_quota = pool.quota
+        pool = nil
+      else
+        pool = pool.superpool
+      end
+    end
+    if the_quota.nil?
+      Quota.get_resource_hash(nil, nil, nil, nil, nil)
+    else
+      the_quota.total_resources
+    end
+  end
+
+  def full_resources(exclude_vm = nil)
+    total = total_resources
+    labels = [["CPUs", :cpus, ""], 
+              ["Memory", :memory_in_mb, "(mb)"], 
+              ["NICs", :nics, ""], 
+              ["VMs", :vms, ""], 
+              ["Disk", :storage_in_gb, "(gb)"]]
+    return {:total => total, :labels => labels}
+  end
+
+
 end
diff --git a/wui/src/app/views/collection/show.html.erb b/wui/src/app/views/collection/show.html.erb
index 046199e..b2bfc2d 100644
--- a/wui/src/app/views/collection/show.html.erb
+++ b/wui/src/app/views/collection/show.html.erb
@@ -31,6 +31,32 @@
               </div>
             </div>
 
+            <div class="data-section">
+              <div class="data-section-header"><strong>Default VM Library Resources</strong></div>
+              <div class="data-section-stats">Statistics Data</div>
+              <div class="data-section-table">
+                <div class="inside">
+
+                <table>
+                  <tr>
+                  <th></th>
+                  <td> default values for VM Libraries</td>
+                  </tr>
+                <% resources = @collection.full_resources %>
+                <% for item in resources[:labels] %>
+                <% total_limit = resources[:total][item[1]]
+                   total_limit = "unlimited" if total_limit.nil? %>
+                  <tr>
+                  <th><%= item[0]%>:</th>
+                  <td><%= total_limit %>
+                      <%= item[2]%></td>
+                  </tr>
+                <% end %>
+                </table>
+
+                </div>
+              </div>
+            </div>
           </div> <!-- end #dataTableWrapper -->
 
       </div> <!-- end #data.inside -->
@@ -59,6 +85,12 @@
 
             <div class="actions">
               <div><%= link_to 'Edit Collection Properties', { :action => 'edit', :id => @collection }, { :class => "edit" } %></div>
+              <%if @collection.quota -%>
+                <%= link_to 'Edit default Quota', { :controller => 'quota', :action => 'edit', :id => @collection.quota }, { :class => "edit" } %>
+                <%= link_to 'Remove default Quota', { :controller => 'quota', :action => 'destroy', :id => @collection.quota }, :confirm => 'Are you sure?', :method=> :post, :class => "remove" %>
+              <% else -%>
+                <%= link_to 'Edit Quota', { :controller => 'quota', :action => 'new', :host_collection_id => @collection }, { :class => "edit" } %>
+              <% end -%>
               <div><%= link_to_if @can_delegate, 'User Permissions', { :controller => 'permission', :action => 'new', :hardware_pool_id => @collection }, { :class => "edit" } %></div>
               <table>
                 <tr><td><%= pluralize @collection.permissions.admins.size, "Admin" %></td></tr>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]