refactor codes for instantiate vnf
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / views / instantiate_vnf_view.py
1 # Copyright 2017 ZTE Corporation.\r
2 #\r
3 # Licensed under the Apache License, Version 2.0 (the "License");\r
4 # you may not use this file except in compliance with the License.\r
5 # You may obtain a copy of the License at\r
6 #\r
7 #         http://www.apache.org/licenses/LICENSE-2.0\r
8 #\r
9 # Unless required by applicable law or agreed to in writing, software\r
10 # distributed under the License is distributed on an "AS IS" BASIS,\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 # See the License for the specific language governing permissions and\r
13 # limitations under the License.\r
14 \r
15 import logging\r
16 \r
17 from drf_yasg.utils import swagger_auto_schema\r
18 from rest_framework import status\r
19 from rest_framework.views import APIView\r
20 \r
21 from lcm.nf.serializers.instantiate_vnf_request import InstantiateVnfRequestSerializer\r
22 from lcm.nf.serializers.job_identifier import JobIdentifierSerializer\r
23 from lcm.nf.biz.instantiate_vnf import InstantiateVnf\r
24 from lcm.nf.const import VNF_STATUS\r
25 from lcm.nf.const import OPERATION_TYPE\r
26 from .common import view_safe_call_with_log\r
27 from .common import deal_vnf_action\r
28 \r
29 logger = logging.getLogger(__name__)\r
30 \r
31 \r
32 class InstantiateVnfView(APIView):\r
33     @swagger_auto_schema(\r
34         request_body=InstantiateVnfRequestSerializer(),\r
35         responses={\r
36             status.HTTP_202_ACCEPTED: JobIdentifierSerializer(),\r
37             status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"\r
38         }\r
39     )\r
40     @view_safe_call_with_log(logger=logger)\r
41     def post(self, request, instanceid):\r
42         return deal_vnf_action(\r
43             logger=logger,\r
44             opt_type=OPERATION_TYPE.INSTANTIATE,\r
45             opt_status=VNF_STATUS.INSTANTIATING,\r
46             instid=instanceid,\r
47             req=request,\r
48             req_serializer=InstantiateVnfRequestSerializer,\r
49             act_task=InstantiateVnf\r
50         )\r