diff options
author | ying.yunlong <ying.yunlong@zte.com.cn> | 2018-02-28 09:57:47 +0800 |
---|---|---|
committer | ying.yunlong <ying.yunlong@zte.com.cn> | 2018-02-28 09:57:47 +0800 |
commit | 29441850a745a9561c33c481f3752318a783f8da (patch) | |
tree | 1354b7426fc32a2e40c0d4d53e7f463664284f74 /lcm | |
parent | d6c22eca3725f64efd641b817af71b110cee3133 (diff) |
Interface alignment with ETSI for createVnf
Change-Id: I4b482b3e014a21957a61b03d7f771724df911061
Issue-ID: VFC-780
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r-- | lcm/lcm/v2/urls.py | 8 | ||||
-rw-r--r-- | lcm/lcm/v2/views.py | 45 |
2 files changed, 53 insertions, 0 deletions
diff --git a/lcm/lcm/v2/urls.py b/lcm/lcm/v2/urls.py index 342c2a8c..ea23519d 100644 --- a/lcm/lcm/v2/urls.py +++ b/lcm/lcm/v2/urls.py @@ -11,3 +11,11 @@ # 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. + +from django.conf.urls import url + +from lcm.v2.views import CreateVnfAndQueryVnfs + +urlpatterns = [ + url(r'^api/vnflcm/v2/vnf_instances$', CreateVnfAndQueryVnfs.as_view()), +] diff --git a/lcm/lcm/v2/views.py b/lcm/lcm/v2/views.py index 342c2a8c..1c66c1c0 100644 --- a/lcm/lcm/v2/views.py +++ b/lcm/lcm/v2/views.py @@ -11,3 +11,48 @@ # 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 traceback + +from drf_yasg.utils import swagger_auto_schema +from rest_framework import status +from rest_framework.response import Response +from rest_framework.views import APIView + +from lcm.nf.serializers import CreateVnfReqSerializer, CreateVnfRespSerializer +from lcm.nf.vnf_create.create_vnf_identifier import CreateVnf +from lcm.pub.exceptions import NFLCMException +from lcm.v2.serializers import VnfInstanceSerializer + +logger = logging.getLogger(__name__) + + +class CreateVnfAndQueryVnfs(APIView): + @swagger_auto_schema( + request_body=CreateVnfReqSerializer(), + responses={ + status.HTTP_201_CREATED: VnfInstanceSerializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" + } + ) + def post(self, request): + logger.debug("CreateVnfIdentifier--post::> %s" % request.data) + try: + req_serializer = CreateVnfReqSerializer(data=request.data) + if not req_serializer.is_valid(): + raise NFLCMException(req_serializer.errors) + + nf_inst_id = CreateVnf(req_serializer.data).do_biz() + + create_vnf_resp_serializer = CreateVnfRespSerializer(data={"vnfInstanceId": nf_inst_id}) + if not create_vnf_resp_serializer.is_valid(): + raise NFLCMException(create_vnf_resp_serializer.errors) + return Response(data=create_vnf_resp_serializer.data, status=status.HTTP_201_CREATED) + except NFLCMException as e: + logger.error(e.message) + return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + except Exception as e: + logger.error(e.message) + logger.error(traceback.format_exc()) + return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) |