From 805de22470e41705667d6df7a15c4fe7991b1063 Mon Sep 17 00:00:00 2001 From: Xiaohua Zhang Date: Mon, 27 Aug 2018 08:16:42 +0000 Subject: Add API handler stub for infra_workload API handler stub for API infra_workload Change-Id: Icad08493fdcc12c1bc8225e0c81567d7d3c156be Issue-ID: MULTICLOUD-338 Signed-off-by: Xiaohua Zhang --- .../resource/views/infra_workload.py | 153 +++++++++++++++++++++ windriver/titanium_cloud/urls.py | 3 + 2 files changed, 156 insertions(+) create mode 100644 windriver/titanium_cloud/resource/views/infra_workload.py diff --git a/windriver/titanium_cloud/resource/views/infra_workload.py b/windriver/titanium_cloud/resource/views/infra_workload.py new file mode 100644 index 00000000..08efcfd1 --- /dev/null +++ b/windriver/titanium_cloud/resource/views/infra_workload.py @@ -0,0 +1,153 @@ +# Copyright (c) 2017-2018 Wind River Systems, 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. +# See the License for the specific language governing permissions and +# limitations under the License. + +import logging +import json +import traceback + +from rest_framework import status + +from django.conf import settings +from common.exceptions import VimDriverNewtonException +from newton_base.util import VimDriverUtils + +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 + + +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/windriver/titanium_cloud/urls.py b/windriver/titanium_cloud/urls.py index d56be236..3be252a6 100644 --- a/windriver/titanium_cloud/urls.py +++ b/windriver/titanium_cloud/urls.py @@ -19,6 +19,7 @@ from newton_base.openoapi import tenants from titanium_cloud.resource.views import capacity from titanium_cloud.resource.views import events from titanium_cloud.vesagent import vesagent_ctrl +from titanium_cloud.resource.views import infra_workload urlpatterns = [ url(r'^', include('titanium_cloud.swagger.urls')), @@ -65,6 +66,8 @@ urlpatterns = [ # events.EventsCheck.as_view()), url(r'^api/multicloud-titanium_cloud/v1/(?P[0-9a-zA-Z_-]+)/(?P[0-9a-zA-Z_-]+)/vesagent/?$', vesagent_ctrl.APIv1VesAgentCtrl.as_view()), + url(r'^api/multicloud-titanium_cloud/v1/(?P[0-9a-zA-Z_-]+)/(?P[0-9a-zA-Z_-]+)/infra_workload/?$', + infra_workload.APIv1InfraWorkload.as_view()), ] -- cgit 1.2.3-korg