From fa5b18e4d3d3f7a7fb37db46a3d8b02969c08999 Mon Sep 17 00:00:00 2001 From: adamscmRH Date: Tue, 20 Jun 2017 10:43:08 -0400 Subject: [PATCH] Fix InsGroup Cap Calc --- awx/api/serializers.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 14dbd82c35..3c8ae05c75 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -3465,7 +3465,10 @@ class InstanceSerializer(BaseSerializer): return obj.consumed_capacity def get_percent_capacity_remaining(self, obj): - return float("{0:.2f}".format((float(obj.consumed_capacity) / float(obj.capacity)) * 100.0)) + if not obj.capacity or obj.consumed_capacity == obj.capacity: + return 0.0 + else: + return float("{0:.2f}".format(((float(obj.capacity) - float(obj.consumed_capacity)) / (float(obj.capacity))) * 100)) def get_jobs_running(self, obj): return UnifiedJob.objects.filter(execution_node=obj.hostname, status__in=('running', 'waiting',)).count() @@ -3494,7 +3497,10 @@ class InstanceGroupSerializer(BaseSerializer): return obj.consumed_capacity def get_percent_capacity_remaining(self, obj): - return float("{0:.2f}".format((float(obj.consumed_capacity) / float(obj.capacity)) * 100.0)) + if not obj.capacity or obj.consumed_capacity == obj.capacity: + return 0.0 + else: + return float("{0:.2f}".format(((float(obj.capacity) - float(obj.consumed_capacity)) / (float(obj.capacity))) * 100)) def get_jobs_running(self, obj): return UnifiedJob.objects.filter(instance_group=obj, status__in=('running', 'waiting',)).count()