fix nslcm middleware
[vfc/nfvo/lcm.git] / lcm / ns / serializers / sol / ns_lcm_op_occ.py
1 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
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
16 from rest_framework import serializers
17
18 from lcm.ns import const
19 from lcm.ns.serializers.sol.affected_nss import AffectedNssSerializer
20 from lcm.ns.serializers.sol.affected_pnfs import AffectedPnfsSerializer
21 from lcm.ns.serializers.sol.affected_saps import AffectedSapsSerializer
22 from lcm.ns.serializers.sol.affected_vls import AffectedVLsSerializer
23 from lcm.ns.serializers.sol.affected_vnffgs import AffectedVnffgsSerializer
24 from lcm.ns.serializers.sol.affected_vnfs import AffectedVnfsSerializer
25 from lcm.ns.serializers.sol.pub_serializers import LinkSerializer
26 from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer
27
28
29 class ResourceChangesSerializer(serializers.Serializer):
30     affectedVnfs = AffectedVnfsSerializer(
31         help_text="Information about VNFC instances that were affected during the lifecycle operation.",
32         required=False,
33         many=True
34     )
35     affectedPnfs = AffectedPnfsSerializer(
36         help_text="Information about the PNF instances that were affected during the lifecycle operation.",
37         required=False,
38         many=True
39     )
40     affectedVls = AffectedVLsSerializer(
41         help_text="Information about the VL instances that were affected during the lifecycle operation",
42         required=False,
43         many=True
44     )
45     affectedVnffgs = AffectedVnffgsSerializer(
46         help_text="Information about the VNFFG instances that were affected during the lifecycle operation.",
47         required=False,
48         many=True
49     )
50     affectedNss = AffectedNssSerializer(
51         help_text="Information about the nested NS instances that were affected during the lifecycle operation.",
52         required=False,
53         many=True
54     )
55     affectedSaps = AffectedSapsSerializer(
56         help_text="Information about the SAP instances that were affected during the lifecycle operation.",
57         required=False,
58         many=True
59     )
60
61
62 class LcmOpLinkSerializer(serializers.Serializer):
63     self = LinkSerializer(
64         help_text="URI of this resource.",
65         required=True,
66         allow_null=False)
67     nsInstance = serializers.CharField(
68         help_text="Link to the NS instance that the operation applies to.",
69         required=True)
70     cancel = serializers.CharField(
71         help_text="Link to the task resource that represents the 'cancel' operation for this LCM operation occurrence.",
72         required=False)
73     retry = serializers.CharField(
74         help_text="Link to the task resource that represents the 'retry' operation for this LCM operation occurrence, "
75                   "if retrying is currently allowed",
76         required=False)
77     rollback = serializers.CharField(
78         help_text="Link to the task resource that represents the 'cancel' operation for this LCM operation occurrence.",
79         required=False)
80     fail = serializers.CharField(
81         help_text="Link to the task resource that represents the 'fail' operation for this LCM operation occurrence.",
82         required=False)
83
84
85 class NSLCMOpOccSerializer(serializers.Serializer):
86     id = serializers.CharField(
87         help_text="Identifier of this NS lifecycle management operation occurrence,",
88         max_length=255,
89         required=True,
90         allow_null=False
91     )
92     operationState = serializers.ChoiceField(
93         help_text="The state of the VNF LCM operation occurrence. ",
94         required=True,
95         choices=const.LCM_OPERATION_STATE_TYPES
96     )
97     stateEnteredTime = serializers.CharField(
98         help_text="Date-time when the current state was entered.",
99         max_length=50
100     )
101     startTime = serializers.CharField(
102         help_text="Date-time of the start of the operation.",
103         max_length=50
104     )
105     nsInstanceId = serializers.UUIDField(
106         help_text="Identifier of the ns instance to which the operation applies"
107     )
108     operation = serializers.ChoiceField(
109         help_text="The lifecycle management operation",
110         required=True,
111         choices=const.NS_LCM_OP_TYPES
112     )
113     isAutomaticInvocation = serializers.BooleanField(
114         help_text="Set to true if this NS LCM operation occurrence has been automatically triggered by the NFVO.",
115         default=False
116     )
117     operationParams = serializers.DictField(
118         help_text="Input parameters of the LCM operation. This attribute shall be formatted according to the request "
119                   "data type of the related LCM operation. The following mapping between operationType and the data "
120                   "type of this attribute shall apply: "
121                   "1. INSTANTIATE: InstantiateVnfRequest "
122                   "2. SCALE: ScaleVnfRequest "
123                   "3. CHANGE_FLAVOUR: ChangeVnfFlavourRequest"
124                   "4. HEAL: HealVnfRequest "
125                   "5. TERMINATE: TerminateVnfRequest ",
126         required=True,
127         allow_null=False
128     )
129     isCancelPending = serializers.BooleanField(
130         help_text="If the NS LCM operation occurrence is in 'STARTING' or 'PROCESSING' or 'ROLLING_BACK' state and "
131                   "the operation is being cancelled, this attribute shall be set to True. Otherwise, it shall be set "
132                   "to False.",
133         required=True
134     )
135     cancelMode = serializers.CharField(
136         help_text="The mode of an ongoing cancellation. Shall be present when isCancelPending=true, and shall be None "
137                   "otherwise.",
138         allow_null=True,
139         required=False
140     )
141     error = ProblemDetailsSerializer(
142         help_text="If 'operationState' is 'FAILED_TEMP' or 'FAILED' or PROCESSING' or 'ROLLING_BACK' and previous "
143                   "value of 'operationState' was 'FAILED_TEMP'  this attribute shall be present ",
144         allow_null=True,
145         required=False
146     )
147     resourceChanges = ResourceChangesSerializer(
148         help_text="It contains information about the cumulative changes to virtualised resources that were performed "
149                   "so far by the LCM operation since its start, if applicable.",
150         required=False,
151         allow_null=True)
152     _links = LcmOpLinkSerializer(
153         help_text="Links to resources related to this resource.",
154         required=True)
155
156
157 class NSLCMOpOccsSerializer(serializers.ListSerializer):
158     child = NSLCMOpOccSerializer()