diff options
author | Liang Ke <lokyse@163.com> | 2018-03-19 05:45:01 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-19 05:45:01 +0000 |
commit | dbbd44d10bcfc3143fb2d227a702ab5588ad0702 (patch) | |
tree | f23e82a53603c52d685b5a24b4fa30b4bd946ae2 /multivimbroker | |
parent | f95806997450109cebe9bcc03398eeb648b749ae (diff) | |
parent | 6f2db75d1596630c1f1d4671c5b15ab137e0fb31 (diff) |
Merge "Add check_vim_capacity"
Diffstat (limited to 'multivimbroker')
-rw-r--r-- | multivimbroker/multivimbroker/forwarder/urls.py | 3 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/forwarder/views.py | 34 |
2 files changed, 35 insertions, 2 deletions
diff --git a/multivimbroker/multivimbroker/forwarder/urls.py b/multivimbroker/multivimbroker/forwarder/urls.py index 6a60df4..771f052 100644 --- a/multivimbroker/multivimbroker/forwarder/urls.py +++ b/multivimbroker/multivimbroker/forwarder/urls.py @@ -16,6 +16,7 @@ from django.conf.urls import url from rest_framework.urlpatterns import format_suffix_patterns +from multivimbroker.forwarder.views import CheckCapacity from multivimbroker.forwarder.views import Extension from multivimbroker.forwarder.views import Forward from multivimbroker.forwarder.views import Identity @@ -27,6 +28,8 @@ from multivimbroker.forwarder.views import VIMTypes urlpatterns = [ url(r'^api/multicloud/v0/vim_types$', VIMTypes.as_view()), + url(r'^api/multicloud/v0/check_vim_capacity$', + CheckCapacity.as_view()), url(r'^api/multicloud/v0/(?P<vimid>[0-9a-zA-Z_-]+)/identity/v3$', Identity.as_view()), url(r'^api/multicloud/v0/(?P<vimid>[0-9a-zA-Z_-]+)/identity/v3' diff --git a/multivimbroker/multivimbroker/forwarder/views.py b/multivimbroker/multivimbroker/forwarder/views.py index 7935642..cea4134 100644 --- a/multivimbroker/multivimbroker/forwarder/views.py +++ b/multivimbroker/multivimbroker/forwarder/views.py @@ -21,8 +21,6 @@ from rest_framework.views import Response from rest_framework.views import status from multivimbroker.forwarder.base import BaseHandler -# - class BaseServer(BaseHandler, APIView): @@ -96,6 +94,38 @@ class VIMTypes(BaseServer): return Response(data=ret, status=status.HTTP_200_OK) +class CheckCapacity(BaseServer): + + def post(self, request): + try: + body = json.loads(request.body) + except json.JSONDecodeError as e: + return Response( + data={'error': 'Invalidate request body %s.' % e}, + status=status.HTTP_400_BAD_REQUEST) + + ret = {"VIMs": []} + newbody = { + "vCPU": body.get("vCPU", 0), + "Memory": body.get("Memory", 0), + "Storage": body.get("Storage", 0) + } + for vim in body.get("VIMs", []): + url = request.get_full_path().replace( + "check_vim_capacity", "%s/capacity_check" % vim) + resp = self.send(vim, url, newbody, "POST") + if resp.status_code != status.HTTP_200_OK: + continue + try: + resp_body = json.loads(resp.body) + except json.JSONDecodeError: + continue + if not resp_body.get("result", False): + continue + ret['VIMs'].append(vim) + return Response(data=ret, status=status.HTTP_200_OK) + + # forward handler class Forward(BaseServer): |