Fix bug of capacity_check for ocata 61/39361/1
authorYun Huang <yun.huang@windriver.com>
Wed, 28 Mar 2018 03:00:39 +0000 (11:00 +0800)
committerYun Huang <yun.huang@windriver.com>
Wed, 28 Mar 2018 03:00:39 +0000 (11:00 +0800)
Change-Id: I945a06451647324edcf7bcb86e664479311e4ed0
Issue-ID: MULTICLOUD-168
Signed-off-by: Yun Huang <yun.huang@windriver.com>
ocata/ocata/resource/views/capacity.py

index d73cc0f..8ea3706 100644 (file)
@@ -77,20 +77,20 @@ class CapacityCheck(APIView):
 
             # compute actual available resource for this tenant
             remainVCPU = compute_limits['maxTotalCores'] - compute_limits['totalCoresUsed']
+            remainHypervisorVCPU = hypervisor_statistics['vcpus'] - hypervisor_statistics['vcpus_used']
 
-            if (compute_limits['maxTotalCores'] > hypervisor_statistics['vcpus']):
-                if hypervisor_statistics['vcpus'] > compute_limits['totalCoresUsed']:
-                    remainVCPU = hypervisor_statistics['vcpus'] - compute_limits['totalCoresUsed']
-                else:
-                    remainVCPU = 0
+            if (remainVCPU > remainHypervisorVCPU):
+                remainVCPU = remainHypervisorVCPU
 
             remainMEM = compute_limits['maxTotalRAMSize'] - compute_limits['totalRAMUsed']
-            if hypervisor_statistics['free_ram_mb'] > remainMEM:
-                remainMEM = hypervisor_statistics['free_ram_mb']
+            remainHypervisorMEM = hypervisor_statistics['free_ram_mb']
+            if remainMEM > remainHypervisorMEM:
+                remainMEM = remainHypervisorMEM
 
             remainStorage = storage_limits['maxTotalVolumeGigabytes'] - storage_limits['totalGigabytesUsed']
-            if (remainStorage < hypervisor_statistics['free_disk_gb']):
-                remainStorage = hypervisor_statistics['free_disk_gb']
+            remainHypervisorStorage = hypervisor_statistics['free_disk_gb']
+            if (remainStorage > remainHypervisorStorage):
+                remainStorage = remainHypervisorStorage
 
             # compare resource demanded with available
             if (int(resource_demand['vCPU']) >= remainVCPU):