summaryrefslogtreecommitdiffstats
path: root/windriver/titanium_cloud/resource/views/capacity.py
diff options
context:
space:
mode:
Diffstat (limited to 'windriver/titanium_cloud/resource/views/capacity.py')
-rw-r--r--windriver/titanium_cloud/resource/views/capacity.py35
1 files changed, 17 insertions, 18 deletions
diff --git a/windriver/titanium_cloud/resource/views/capacity.py b/windriver/titanium_cloud/resource/views/capacity.py
index 25b29da8..669cb659 100644
--- a/windriver/titanium_cloud/resource/views/capacity.py
+++ b/windriver/titanium_cloud/resource/views/capacity.py
@@ -13,12 +13,12 @@
# limitations under the License.
import logging
-import json
+# import json
import traceback
-from rest_framework import status
+# from rest_framework import status
-from django.conf import settings
+# from django.conf import settings
from common.exceptions import VimDriverNewtonException
from newton_base.util import VimDriverUtils
@@ -28,12 +28,10 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from common.msapi import extsys
-
logger = logging.getLogger(__name__)
class CapacityCheck(APIView):
-
def __init__(self):
self._logger = logger
@@ -42,24 +40,24 @@ class CapacityCheck(APIView):
self._logger.debug("META> %s" % request.META)
hasEnoughResource = False
- try :
+ try:
resource_demand = request.data
tenant_name = None
vim = VimDriverUtils.get_vim_info(vimid)
sess = VimDriverUtils.get_session(vim, tenant_name)
- #get token:
+ # get token:
cloud_owner, regionid = extsys.decode_vim_id(vimid)
interface = 'public'
service = {'service_type': 'compute',
'interface': interface,
'region_name': vim['openstack_region_id']
- if vim.get('openstack_region_id')
- else vim['cloud_region_id']
+ if vim.get('openstack_region_id')
+ else vim['cloud_region_id']
}
- #get limit for this tenant
+ # get limit for this tenant
req_resouce = "/limits"
self._logger.info("check limits> URI:%s" % req_resouce)
resp = sess.get(req_resouce, endpoint_filter=service)
@@ -68,7 +66,7 @@ class CapacityCheck(APIView):
compute_limits = content['limits']['absolute']
self._logger.debug("check limits> resp data:%s" % content)
- #get total resource of this cloud region
+ # get total resource of this cloud region
try:
req_resouce = "/os-hypervisors/statistics"
self._logger.info("check os-hypervisors statistics> URI:%s" % req_resouce)
@@ -85,12 +83,15 @@ class CapacityCheck(APIView):
conFreeRamMB = int(resource_demand['Memory'])
conFreeDiskGB = int(resource_demand['Storage'])
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}
+ 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
+ # get storage limit for this tenant
service['service_type'] = 'volumev2'
req_resouce = "/limits"
self._logger.info("check volumev2 limits> URI:%s" % req_resouce)
@@ -131,8 +132,9 @@ class CapacityCheck(APIView):
return Response(data={'result': hasEnoughResource}, status=status.HTTP_200_OK)
except VimDriverNewtonException as e:
self._logger.error("Plugin exception> status:%s,error:%s"
- % (e.status_code, e.content))
- return Response(data={'result': hasEnoughResource,'error': e.content}, status=e.status_code)
+ % (e.status_code, e.content))
+ return Response(data={'result': hasEnoughResource,
+ 'error': e.content}, status=e.status_code)
except HttpError as e:
self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
resp = e.response.json()
@@ -144,9 +146,7 @@ class CapacityCheck(APIView):
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-
class APIv1CapacityCheck(CapacityCheck):
-
def __init__(self):
super(APIv1CapacityCheck, self).__init__()
# self._logger = logger
@@ -157,4 +157,3 @@ class APIv1CapacityCheck(CapacityCheck):
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
return super(APIv1CapacityCheck, self).post(request, vimid)
-