summaryrefslogtreecommitdiffstats
path: root/pike
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2018-08-28 12:04:57 +0000
committerGerrit Code Review <gerrit@onap.org>2018-08-28 12:04:57 +0000
commit49a15ebb22c987cb7c99585dc0543f8878352040 (patch)
tree9cac1a03db9b2b267578ce6cee7e62d0b15b7e81 /pike
parentf3aad7aed9e4be99443f534c4e67298c7afeff22 (diff)
parente670001361e150a6c955737c5552122f54e7dfe2 (diff)
Merge "Add API handler stub for infra_workload in Pike"
Diffstat (limited to 'pike')
-rw-r--r--pike/pike/resource/views/infra_workload.py150
-rw-r--r--pike/pike/urls.py4
2 files changed, 153 insertions, 1 deletions
diff --git a/pike/pike/resource/views/infra_workload.py b/pike/pike/resource/views/infra_workload.py
new file mode 100644
index 00000000..9ef249d0
--- /dev/null
+++ b/pike/pike/resource/views/infra_workload.py
@@ -0,0 +1,150 @@
+# Copyright (c) 2018 Intel Corporation.
+#
+# 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.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import json
+import logging
+import traceback
+
+from django.conf import settings
+from keystoneauth1.exceptions import HttpError
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+from common.msapi import extsys
+from common.exceptions import VimDriverNewtonException
+from newton_base.util import VimDriverUtils
+
+logger = logging.getLogger(__name__)
+
+
+class InfraWorkload(APIView):
+
+ def __init__(self):
+ self._logger = logger
+
+ def post(self, request, vimid=""):
+ self._logger.info("vimid, data: %s, %s" % (vimid, request.data))
+ self._logger.debug("META: %s" % request.META)
+
+ try :
+
+ # stub response
+ resp_template = {
+ "template_type": "heat",
+ "workload_id": "3095aefc-09fb-4bc7-b1f0-f21a304e864c",
+ "template_response":
+ {
+ "stack": {
+ "id": "3095aefc-09fb-4bc7-b1f0-f21a304e864c",
+ "links": [
+ {
+ "href": "http://192.168.123.200:8004/v1/eb1c63a4f77141548385f113a28f0f52/stacks/teststack/3095aefc-09fb-4bc7-b1f0-f21a304e864c",
+ "rel": "self"
+ }
+ ]
+ }
+ }
+ }
+
+ self._logger.info("RESP with data> result:%s" % resp_template)
+ return Response(data=resp_template, status=status.HTTP_201_CREATED)
+ except VimDriverNewtonException as e:
+ self._logger.error("Plugin exception> status:%s,error:%s"
+ % (e.status_code, e.content))
+ return Response(data={'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()))
+ return Response(data=e.response.json(), status=e.http_status)
+ except Exception as e:
+ self._logger.error(traceback.format_exc())
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+ def get(self, request, vimid=""):
+ self._logger.info("vimid: %s" % (vimid))
+ self._logger.debug("META: %s" % request.META)
+
+ try :
+
+ # stub response
+ resp_template = {
+ "template_type": "heat",
+ "workload_id": "3095aefc-09fb-4bc7-b1f0-f21a304e864c",
+ "workload_status": "CREATE_IN_PROCESS",
+ }
+
+ self._logger.info("RESP with data> result:%s" % resp_template)
+ return Response(data=resp_template, 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={'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()))
+ return Response(data=e.response.json(), status=e.http_status)
+ except Exception as e:
+ self._logger.error(traceback.format_exc())
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+ def delete(self, request, vimid=""):
+ self._logger.info("vimid: %s" % (vimid))
+ self._logger.debug("META: %s" % request.META)
+
+ try :
+
+ # stub response
+ self._logger.info("RESP with data> result:%s" % "")
+ return Response(status=status.HTTP_204_NO_CONTENT)
+ except VimDriverNewtonException as e:
+ self._logger.error("Plugin exception> status:%s,error:%s"
+ % (e.status_code, e.content))
+ return Response(data={'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()))
+ return Response(data=e.response.json(), status=e.http_status)
+ except Exception as e:
+ self._logger.error(traceback.format_exc())
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+class APIv1InfraWorkload(InfraWorkload):
+
+ def __init__(self):
+ super(APIv1InfraWorkload, self).__init__()
+ # self._logger = logger
+
+ def post(self, request, cloud_owner="", cloud_region_id=""):
+ #self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data))
+ #self._logger.debug("META: %s" % request.META)
+
+ vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
+ return super(APIv1InfraWorkload, self).post(request, vimid)
+
+ def get(self, request, cloud_owner="", cloud_region_id=""):
+ #self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data))
+ #self._logger.debug("META: %s" % request.META)
+
+ vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
+ return super(APIv1InfraWorkload, self).get(request, vimid)
+
+ def delete(self, request, cloud_owner="", cloud_region_id=""):
+ #self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data))
+ #self._logger.debug("META: %s" % request.META)
+
+ vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
+ return super(APIv1InfraWorkload, self).delete(request, vimid)
diff --git a/pike/pike/urls.py b/pike/pike/urls.py
index e49eb1a3..3465a303 100644
--- a/pike/pike/urls.py
+++ b/pike/pike/urls.py
@@ -17,6 +17,7 @@ from django.conf.urls import include, url
from pike.registration.views import registration
from newton_base.openoapi import tenants
from pike.resource.views import capacity
+from pike.resource.views import infra_workload
urlpatterns = [
url(r'^', include('pike.swagger.urls')),
@@ -33,7 +34,8 @@ urlpatterns = [
'(?P<tenantid>[0-9a-zA-Z_-]{20,})/', include('pike.requests.urls')),
url(r'^api/multicloud-pike/v0/(?P<vimid>[0-9a-zA-Z_-]+)/capacity_check/?$',
capacity.CapacityCheck.as_view()),
-
+ url(r'^api/multicloud-pike/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/infra_workload/?$',
+ infra_workload.APIv1InfraWorkload.as_view()),
]