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

[Ovirt-devel] [patch] fix nil (unlimited) quota attribute behavior



This patch fixes quota-limiting behavior for omitted parameters. Proper quota enforcment only restricts resources on those parameters that are specified. If 'memory' ,for example, is left blank, then the quota shouldn't enforce memory limits. Empty strings were throwing off the unit conversion methods, resulting in empty values being reset to 0.

Scott
diff --git a/wui/src/app/util/ovirt.rb b/wui/src/app/util/ovirt.rb
index 36fd613..9024333 100644
--- a/wui/src/app/util/ovirt.rb
+++ b/wui/src/app/util/ovirt.rb
@@ -18,20 +18,28 @@
 # also available at http://www.gnu.org/copyleft/gpl.html.
 
 def gb_to_kb(val_in_gigs)
-  return nil if val_in_gigs.nil?
+  return nil if nil_or_empty(val_in_gigs)
   return val_in_gigs.to_i * 1024 * 1024
 end
  
 def kb_to_gb(val_in_kb)
-  return nil if val_in_kb.nil?
+  return nil if nil_or_empty(val_in_kb)
   return val_in_kb.to_i / 1024 / 1024
 end
 def mb_to_kb(val_in_mb)
-  return nil if val_in_mb.nil?
+  return nil if nil_or_empty(val_in_mb)
   return val_in_mb.to_i * 1024
 end
  
 def kb_to_mb(val_in_kb)
-  return nil if val_in_kb.nil?
+  return nil if nil_or_empty(val_in_kb)
   return val_in_kb.to_i / 1024
 end
+
+def nil_or_empty(val)
+  if val.nil? or (val.kind_of?(String) and val.empty?)
+    return true
+  else
+    return false
+  end
+end

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