diff options
Diffstat (limited to 'windriver')
-rw-r--r-- | windriver/titanium_cloud/registration/views/registration.py | 4 | ||||
-rw-r--r-- | windriver/titanium_cloud/resource/views/infra_workload.py | 153 | ||||
-rw-r--r-- | windriver/titanium_cloud/urls.py | 3 |
3 files changed, 158 insertions, 2 deletions
diff --git a/windriver/titanium_cloud/registration/views/registration.py b/windriver/titanium_cloud/registration/views/registration.py index 9d052472..b1bb42ed 100644 --- a/windriver/titanium_cloud/registration/views/registration.py +++ b/windriver/titanium_cloud/registration/views/registration.py @@ -508,10 +508,10 @@ class APIv1Registry(Registry): #create cloud region with composed AAI cloud_region_id except for the one onboarded externally (e.g. ESR) gen_cloud_region_id = cloud_region_id + "." + regionid if region_specified != regionid else cloud_region_id self._update_cloud_region(cloud_owner, gen_cloud_region_id, regionid, viminfo) - return super(RegistryV1, self).post(request, vimid) + return super(APIv1Registry, self).post(request, vimid) else: self._update_cloud_region(cloud_owner, cloud_region_id, region_specified, viminfo) - return super(RegistryV1, self).post(request, vimid) + return super(APIv1Registry, self).post(request, vimid) 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<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/vesagent/?$', vesagent_ctrl.APIv1VesAgentCtrl.as_view()), + url(r'^api/multicloud-titanium_cloud/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/infra_workload/?$', + infra_workload.APIv1InfraWorkload.as_view()), ] |