1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

Merge pull request #6628 from rooftopcellist/cap-fix

Capacity percentage fix
This commit is contained in:
Christian Adams 2017-06-20 11:47:32 -04:00 committed by GitHub
commit e7885edaa1

View File

@ -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()