summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEthan Lynn <ethanlynnl@vmware.com>2019-03-21 16:31:41 +0800
committerEthan Lynn <ethanlynnl@vmware.com>2019-03-21 16:37:04 +0800
commit04ad05f0302fa1e059b3c3ab3470759dc333e33e (patch)
tree0bae0987ee2be82a8ce2ec8ff428600d8e429935
parente6d3b542e4fc228108b39d514e994b5582d6a073 (diff)
Add execute to fakeplugin
Add an execute function to fakeplugin Change-Id: I15353c1f8e4c5514c5bf10600723cc51bbaebaac Issue-ID: MULTICLOUD-488 Signed-off-by: Ethan Lynn <ethanlynnl@vmware.com>
-rw-r--r--vio/requirements.txt1
-rw-r--r--vio/vio/swagger/urls.py3
-rw-r--r--vio/vio/swagger/views/fakeplugin/execute/__init__.py0
-rw-r--r--vio/vio/swagger/views/fakeplugin/execute/views.py56
4 files changed, 60 insertions, 0 deletions
diff --git a/vio/requirements.txt b/vio/requirements.txt
index eec60b7..e7f743c 100644
--- a/vio/requirements.txt
+++ b/vio/requirements.txt
@@ -35,3 +35,4 @@ PyYAML>=3.1.0
pyvmomi
pyvim
fire
+requests
diff --git a/vio/vio/swagger/urls.py b/vio/vio/swagger/urls.py
index 568b018..795eb1e 100644
--- a/vio/vio/swagger/urls.py
+++ b/vio/vio/swagger/urls.py
@@ -121,6 +121,7 @@ from vio.swagger.views.fakeplugin.heat.views import FakeHeatService
from vio.swagger.views.fakeplugin.heat.views import FakeHeatServicePreview
from vio.swagger.views.fakeplugin.heat.views import FakeInfraWorkloadAPIGet
from vio.swagger.views.fakeplugin.heat.views import FakeInfraWorkloadAPIPost
+from vio.swagger.views.fakeplugin.execute.views import FakeExecute
urlpatterns = [
@@ -222,6 +223,8 @@ urlpatterns = [
url(r'api/multicloud-vio/v[01]/vmware[_/]fake/infra_workload$'
r'/(?P<workload_id>[0-9a-z-A-Z\-\_]+)$',
FakeInfraWorkloadAPIGet.as_view()),
+ url(r'api/multicloud-vio/v[01]/vmware[_/]fake/extensions/execute$',
+ FakeExecute.as_view()),
# vio
url(r'^api/multicloud-vio/v0/(?P<vimid>[0-9a-zA-Z_-]+)/'
diff --git a/vio/vio/swagger/views/fakeplugin/execute/__init__.py b/vio/vio/swagger/views/fakeplugin/execute/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/vio/vio/swagger/views/fakeplugin/execute/__init__.py
diff --git a/vio/vio/swagger/views/fakeplugin/execute/views.py b/vio/vio/swagger/views/fakeplugin/execute/views.py
new file mode 100644
index 0000000..925735a
--- /dev/null
+++ b/vio/vio/swagger/views/fakeplugin/execute/views.py
@@ -0,0 +1,56 @@
+# Copyright (c) 2019 VMware, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+
+from rest_framework import status
+from rest_framework.views import APIView
+from rest_framework.response import Response
+
+import json
+import requests
+
+
+class FakeExecute(APIView):
+
+ def post(self, request):
+ try:
+ reqbody = json.loads(request.body)
+ kwargs = {
+ "verify": False,
+ }
+ url = reqbody["url"]
+ method = reqbody.get("method", "get").lower()
+ kwargs['headers'] = {
+ "Accept": "application/json",
+ "Content-Type": "application/json",
+ "x-hm-authorization": "3d1f2ab6:8073:4da4:8f1a:eb2c349ba24",
+ }
+ kwargs['headers'].update(reqbody.get("headers", {}))
+ if reqbody.get("body"):
+ kwargs['json'] = reqbody["body"]
+ resp = requests.request(method, url, **kwargs)
+ respHeaders = resp.headers
+ for k in ["Connection", "Keep-Alive", "Transfer-Encoding"]:
+ if k in respHeaders:
+ del respHeaders[k]
+ try:
+ respData = resp.json()
+ except Exception as ex:
+ respData = resp.content
+ except Exception as ex:
+ return Response(
+ data={"error": str(ex)},
+ status=status.HTTP_400_BAD_REQUEST)
+ return Response(
+ data=respData,
+ status=resp.status_code,
+ headers=respHeaders,
+ content_type=respHeaders.get("Content-Type"))