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