summaryrefslogtreecommitdiffstats
path: root/multivimbroker
diff options
context:
space:
mode:
Diffstat (limited to 'multivimbroker')
-rw-r--r--multivimbroker/multivimbroker/forwarder/urls.py3
-rw-r--r--multivimbroker/multivimbroker/forwarder/views.py34
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):