diff options
author | Fu Jinhua <fu.jinhua@zte.com.cn> | 2018-03-06 09:14:06 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-06 09:14:06 +0000 |
commit | 96b9d1cc315663de99b2e86cfac7f92ca9070bc8 (patch) | |
tree | e700a6a58eeb17d11c32921e1ff963d1ae41aa38 | |
parent | 2f113b19f3271933a230cc759264fc204672b49e (diff) | |
parent | 0d5ebba6f8a52fb8afe56976944061e0b26676c0 (diff) |
Merge "Add vnf Grant bussiness logic"
-rw-r--r-- | lcm/v2/grant_vnf.py | 46 | ||||
-rw-r--r-- | lcm/v2/views.py | 14 |
2 files changed, 58 insertions, 2 deletions
diff --git a/lcm/v2/grant_vnf.py b/lcm/v2/grant_vnf.py new file mode 100644 index 00000000..832c7818 --- /dev/null +++ b/lcm/v2/grant_vnf.py @@ -0,0 +1,46 @@ +# Copyright 2018 ZTE 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 uuid + +logger = logging.getLogger(__name__) + + +class GrantVnf(object): + def __init__(self, grant_data): + self.data = grant_data + + def exec_grant(self): + if isinstance(self.data, (unicode, str)): + self.data = json.JSONDecoder().decode(self.data) + grant_resp = { + "id": str(uuid.uuid4()), + "vnfInstanceId": self.data.get("vnfInstanceId"), + "vnfLcmOpOccId": self.data.get("vnfLcmOpOccId"), + "_links": { + "self": { + "href": "/grants" + }, + "vnfLcmOpOcc": { + "href": self.data.get("_links").get("vnfLcmOpOcc") + }, + "vnfInstance": { + "href": self.data.get("_links").get("vnfInstance") + } + } + } + logger.debug("grant_resp=%s", grant_resp) + return grant_resp diff --git a/lcm/v2/views.py b/lcm/v2/views.py index 19f6740a..3fa240d9 100644 --- a/lcm/v2/views.py +++ b/lcm/v2/views.py @@ -21,6 +21,7 @@ from drf_yasg.utils import swagger_auto_schema from lcm.v2.serializers import GrantRequestSerializer from lcm.v2.serializers import GrantSerializer +from lcm.v2.grant_vnf import GrantVnf logger = logging.getLogger(__name__) @@ -29,7 +30,9 @@ class VnfGrantView(APIView): @swagger_auto_schema( request_body=GrantRequestSerializer(), responses={ - status.HTTP_201_CREATED: GrantSerializer(), + status.HTTP_201_CREATED: GrantSerializer( + help_text="The grant was created successfully (synchronous mode)." + ), status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" } ) @@ -39,8 +42,15 @@ class VnfGrantView(APIView): req_serializer = GrantRequestSerializer(data=request.data) if not req_serializer.is_valid(): raise Exception(req_serializer.errors) + + grant_resp = GrantVnf(request.data).exec_grant() + + resp_serializer = GrantSerializer(data=grant_resp) + if not resp_serializer.is_valid(): + raise Exception(resp_serializer.errors) + + return Response(data=resp_serializer.data, status=status.HTTP_201_CREATED) except Exception as e: logger.error(traceback.format_exc()) logger.error("Exception in VnfGrant: %s", e.message) return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - return Response(data={}, status=status.HTTP_201_CREATED) |