refactor codes for heal vnf
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / views / heal_vnf_view.py
1 # Copyright (C) 2018 Verizon. All Rights Reserved.\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.biz.heal_vnf import HealVnf\r
22 from lcm.nf.serializers.heal_vnf_req import HealVnfRequestSerializer\r
23 from lcm.nf.serializers.response import ProblemDetailsSerializer\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 HealVnfView(APIView):\r
33     @swagger_auto_schema(\r
34         request_body=HealVnfRequestSerializer(),\r
35         responses={\r
36             status.HTTP_202_ACCEPTED: "Success",\r
37             status.HTTP_404_NOT_FOUND: ProblemDetailsSerializer(),\r
38             status.HTTP_409_CONFLICT: ProblemDetailsSerializer(),\r
39             status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"\r
40         }\r
41     )\r
42     @view_safe_call_with_log(logger=logger)\r
43     def post(self, request, instanceid):\r
44         return deal_vnf_action(\r
45             logger=logger,\r
46             opt_type=OPERATION_TYPE.HEAL,\r
47             opt_status=VNF_STATUS.HEALING,\r
48             instid=instanceid,\r
49             req=request,\r
50             req_serializer=HealVnfRequestSerializer,\r
51             act_task=HealVnf\r
52         )\r