Skip to content

Instantly share code, notes, and snippets.

@dmamolina
Created December 16, 2011 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmamolina/93213ab62fce831b758f to your computer and use it in GitHub Desktop.
Save dmamolina/93213ab62fce831b758f to your computer and use it in GitHub Desktop.
diff --git a/src/authm_mad/remotes/quota/quota.rb b/src/authm_mad/remotes/quota/quota.rb
index 1f13234..947ef4e 100644
--- a/src/authm_mad/remotes/quota/quota.rb
+++ b/src/authm_mad/remotes/quota/quota.rb
@@ -63,7 +63,8 @@ class Quota
VM_USAGE = {
:cpu => {
:proc_info => lambda {|template| template['CPU']},
- :xpath => 'TEMPLATE/CPU'
+ :xpath => 'TEMPLATE/CPU',
+ :default => 1.0
},
:memory => {
:proc_info => lambda {|template| template['MEMORY']},
@@ -240,16 +241,21 @@ class Quota
resources.each{ |res|
pool = get_pool(res, user_id)
- base_xpath = "/#{res}_POOL/#{resource}"
- Quota.const_get("#{res}_USAGE".to_sym).each { |key, params|
- pool.each_xpath("#{base_xpath}/#{params[:xpath]}") { |elem|
- if elem
- usage[key] ||= 0
+
+ # Initialize usage
+ usage_params = Quota.const_get("#{res}_USAGE".to_sym)
+ usage_params.keys.each {|k| usage[k] = 0}
+
+ pool.each { |elem|
+ usage_params.each { |key, params|
+ if a = elem[params[:xpath]]
if params[:count]
usage[key] += 1
else
- usage[key] += send(DB_QUOTA_SCHEMA[key].name.to_sym, elem
+ usage[key] += send(DB_QUOTA_SCHEMA[key].name.to_sym, a)
end
+ else
+ usage[key] += params[:default]
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment