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