From: martyntaylor <[email protected]>
---
src/app/services/data_service.rb | 44 ++++++++++++++++++++++---------------
1 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/src/app/services/data_service.rb b/src/app/services/data_service.rb
index 9343fb1..d741574 100644
--- a/src/app/services/data_service.rb
+++ b/src/app/services/data_service.rb
@@ -62,24 +62,28 @@ class DataService
# Returns the Used and Maximum Resource Usage
def self.quota_utilisation(parent, resource_name)
- quota = parent.quota
-
- case resource_name
- when Quota::RESOURCE_RUNNING_INSTANCES
- return QuotaUsagePoint.new(quota.running_instances,
quota.maximum_running_instances)
- when Quota::RESOURCE_RUNNING_MEMORY
- return QuotaUsagePoint.new(quota.running_memory.to_f,
quota.maximum_running_memory.to_f)
- when Quota::RESOURCE_RUNNING_CPUS
- return QuotaUsagePoint.new(quota.running_cpus.to_f,
quota.maximum_running_cpus.to_f)
- when Quota::RESOURCE_TOTAL_INSTANCES
- return QuotaUsagePoint.new(quota.total_instances,
quota.maximum_total_instances)
- when Quota::RESOURCE_TOTAL_STORAGE
- return QuotaUsagePoint.new(quota.total_storage.to_f,
quota.maximum_total_storage.to_f)
- when Quota::RESOURCE_OVERALL
- return self.overall_usage(parent)
- else
- return nil
+ if parent
+ quota = parent.quota
+ if quota
+ case resource_name
+ when Quota::RESOURCE_RUNNING_INSTANCES
+ return QuotaUsagePoint.new(quota.running_instances,
quota.maximum_running_instances)
+ when Quota::RESOURCE_RUNNING_MEMORY
+ return QuotaUsagePoint.new(quota.running_memory.to_f,
quota.maximum_running_memory.to_f)
+ when Quota::RESOURCE_RUNNING_CPUS
+ return QuotaUsagePoint.new(quota.running_cpus.to_f,
quota.maximum_running_cpus.to_f)
+ when Quota::RESOURCE_TOTAL_INSTANCES
+ return QuotaUsagePoint.new(quota.total_instances,
quota.maximum_total_instances)
+ when Quota::RESOURCE_TOTAL_STORAGE
+ return QuotaUsagePoint.new(quota.total_storage.to_f,
quota.maximum_total_storage.to_f)
+ when Quota::RESOURCE_OVERALL
+ return self.overall_usage(parent)
+ else
+ return nil
+ end
+ end
end
+ return nil
end
def self.overall_usage(parent)
@@ -91,7 +95,11 @@ class DataService
worst_case = nil
usage_points.each do |usage_point|
if worst_case
- if ((100 / worst_case.max) * worst_case.used) < ((100 /
usage_point.max) * usage_point.used)
+ if worst_case.max == Quota::NO_LIMIT
+ worst_case = usage_point
+ elsif usage_point.max == Quota::NO_LIMIT
+ # DO Nothing
+ elsif ((100 / worst_case.max) * worst_case.used) < ((100 /
usage_point.max) * usage_point.used)
worst_case = usage_point
end
else
--
1.6.6.1
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel