summaryrefslogtreecommitdiffstats
path: root/windriver/titanium_cloud/resource
diff options
context:
space:
mode:
authorYun Huang <yun.huang@windriver.com>2018-05-24 13:11:27 +0800
committerYun Huang <yun.huang@windriver.com>2018-05-24 13:11:27 +0800
commit5b67d58f7d59eaf81f15c21eef12a46c9d7e7688 (patch)
tree472f350ae918d1fd20ed7b3a0724aeab539354ea /windriver/titanium_cloud/resource
parent7fdff724bcc99855b9949a524530e3934346f847 (diff)
Fix non-administator check capacity exception
Change-Id: I6c27713a1c36abeacb37ab6012ec23587a262e5d Issue-ID: MULTICLOUD-168 Signed-off-by: Yun Huang <yun.huang@windriver.com>
Diffstat (limited to 'windriver/titanium_cloud/resource')
-rw-r--r--windriver/titanium_cloud/resource/views/capacity.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/windriver/titanium_cloud/resource/views/capacity.py b/windriver/titanium_cloud/resource/views/capacity.py
index 11c831fd..0dde5994 100644
--- a/windriver/titanium_cloud/resource/views/capacity.py
+++ b/windriver/titanium_cloud/resource/views/capacity.py
@@ -66,13 +66,26 @@ class CapacityCheck(APIView):
self._logger.debug("check limits> resp data:%s" % content)
#get total resource of this cloud region
- req_resouce = "/os-hypervisors/statistics"
- self._logger.info("check os-hypervisors statistics> URI:%s" % req_resouce)
- resp = sess.get(req_resouce, endpoint_filter=service)
- self._logger.info("check os-hypervisors statistics> status:%s" % resp.status_code)
- content = resp.json()
- hypervisor_statistics = content['hypervisor_statistics']
- self._logger.debug("check os-hypervisors statistics> resp data:%s" % content)
+ try:
+ req_resouce = "/os-hypervisors/statistics"
+ self._logger.info("check os-hypervisors statistics> URI:%s" % req_resouce)
+ resp = sess.get(req_resouce, endpoint_filter=service)
+ self._logger.info("check os-hypervisors statistics> status:%s" % resp.status_code)
+ content = resp.json()
+ hypervisor_statistics = content['hypervisor_statistics']
+ self._logger.debug("check os-hypervisors statistics> resp data:%s" % content)
+ except HttpError as e:
+ if e.http_status == status.HTTP_403_FORBIDDEN:
+ # Due to non administrator account cannot get hypervisor data,
+ # so construct enough resource data
+ conVCPUS = int(resource_demand['vCPU']) + 2
+ conFreeRamMB = int(resource_demand['Memory']) + 2
+ conFreeDiskGB = int(resource_demand['Storage']) + 2
+ self._logger.info("Non administator forbidden to access hypervisor statistics data")
+ hypervisor_statistics = {'vcpus_used':0, 'vcpus':conVCPUS, 'free_ram_mb':conFreeRamMB, 'free_disk_gb':conFreeDiskGB}
+ else:
+ # non forbiden exeption will be redirected
+ raise e
#get storage limit for this tenant
service['service_type'] = 'volumev2'