267f5f8d499a0b11678103256c9bb2c6c247bb8a
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / serializers / vnf_lcm_op_occ.py
1 # Copyright (C) 2018 Verizon. 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
16 from rest_framework import serializers
17
18 from affected_vnfcs import AffectedVnfcsSerializer
19 from affected_vls import AffectedVLsSerializer
20 from affected_storages import AffectedStoragesSerializer
21 from link import linkSerializer
22 from response import ProblemDetailsSerializer
23 from ext_virtual_link_info import ExtVirtualLinkInfoSerializer
24 from vnf_info_modifications import VnfInfoModificationsSerializer
25
26
27 LCM_OPERATION_TYPES = [
28     "INSTANTIATE",
29     "SCALE",
30     "SCALE_TO_LEVEL",
31     "CHANGE_FLAVOUR",
32     "TERMINATE",
33     "HEAL",
34     "OPERATE",
35     "CHANGE_EXT_CONN",
36     "MODIFY_INFO"
37 ]
38
39 LCM_OPERATION_STATE_TYPES = [
40     "STARTING",
41     "PROCESSING",
42     "COMPLETED",
43     "FAILED_TEMP",
44     "FAILED",
45     "ROLLING_BACK",
46     "ROLLED_BACK"
47 ]
48
49
50 class ResourceChangesSerializer(serializers.Serializer):
51     affectedVnfcs = AffectedVnfcsSerializer(
52         help_text="Information about VNFC instances that were affected " +
53         "during the lifecycle operation.",
54         required=False,
55         many=True
56     )
57     affectedVirtualLinks = AffectedVLsSerializer(
58         help_text="Information about VL instances that were affected " +
59         "during the lifecycle operation. ",
60         required=False,
61         many=True
62     )
63     affectedVirtualStorages = AffectedStoragesSerializer(
64         help_text="Information about virtualised storage instances that " +
65         "were affected during the lifecycle operation",
66         required=False,
67         many=True
68     )
69
70
71 class LcmOpLinkSerializer(serializers.Serializer):
72     self = linkSerializer(
73         help_text="URI of this resource.",
74         required=True,
75         allow_null=False)
76     vnfInstance = serializers.CharField(
77         help_text="Link to the VNF instance that the operation applies to.",
78         required=True)
79     grant = serializers.CharField(
80         help_text="Link to the grant for this operation, if one exists.",
81         required=False)
82     cancel = serializers.CharField(
83         help_text="Link to the task resource that represents the 'cancel' " +
84         "operation for this VNF LCM operation occurrence.",
85         required=False)
86     retry = serializers.CharField(
87         help_text="Link to the task resource that represents the 'retry' " +
88         "operation for this VNF LCM operation occurrence, if" +
89         " retrying is currently allowed",
90         required=False)
91     rollback = serializers.CharField(
92         help_text="Link to the task resource that represents the 'cancel' " +
93         "operation for this VNF LCM operation occurrence.",
94         required=False)
95     fail = serializers.CharField(
96         help_text="Link to the task resource that represents the 'fail' " +
97         "operation for this VNF LCM operation occurrence.",
98         required=False)
99
100
101 class VNFLCMOpOccSerializer(serializers.Serializer):
102     id = serializers.CharField(
103         help_text="Identifier of this VNF lifecycle management operation" +
104         "occurrence,",
105         max_length=255,
106         required=True,
107         allow_null=False
108     )
109     operationState = serializers.ChoiceField(
110         help_text="The state of the VNF LCM operation occurrence. ",
111         required=True,
112         choices=LCM_OPERATION_STATE_TYPES
113     )
114     stateEnteredTime = serializers.CharField(
115         help_text="Date-time when the current state was entered.",
116         max_length=50
117     )
118     startTime = serializers.CharField(
119         help_text="Date-time of the start of the operation.",
120         max_length=50
121     )
122     vnfInstanceId = serializers.UUIDField(
123         help_text="Identifier of the VNF instance to which the operation" +
124         "applies"
125     )
126     grantId = serializers.UUIDField(
127         help_text="Identifier of the grant related to this VNF LCM operation " +
128                   "occurrence, if such grant exists.",
129         allow_null=True
130     )
131     operation = serializers.ChoiceField(
132         help_text="The lifecycle management operation",
133         required=True,
134         choices=LCM_OPERATION_TYPES
135     )
136     isAutomaticInvocation = serializers.BooleanField(
137         help_text="Set to true if this VNF LCM operation occurrence has " +
138         "been triggered by an automated procedure inside the VNFM. " +
139         "Set to False otherwise.",
140         default=False
141     )
142     operationParams = serializers.DictField(
143         help_text="Input parameters of the LCM operation. This attribute " +
144         "shall be formatted according to the request data type of the " +
145         "related LCM operation. The following mapping between operationType and the " +
146         "data type of this attribute shall apply: " +
147         "1. INSTANTIATE: InstantiateVnfRequest" +
148         "2. SCALE: ScaleVnfRequest " +
149         "3. SCALE_TO_LEVEL: ScaleVnfToLevelRequest " +
150         "4. CHANGE_FLAVOUR: ChangeVnfFlavourRequest " +
151         "5. OPERATE: OperateVnfRequest " +
152         "6. HEAL: HealVnfRequest " +
153         "7. CHANGE_EXT_CONN: ChangeExtVnfConnectivityRequest " +
154         "8. TERMINATE: TerminateVnfRequest " +
155         "9. MODIFY_INFO: VnfInfoModifications",
156         required=True,
157         allow_null=False
158     )
159     isCancelPending = serializers.BooleanField(
160         help_text="If the VNF LCM operation occurrence is in 'STARTING'" +
161         "'PROCESSING' or 'ROLLING_BACK' state and the operation is being" +
162         " cancelled, this attribute shall be set to True. Otherwise, " +
163         " it shall be set to False.",
164         required=True
165     )
166     cancelMode = serializers.CharField(
167         help_text="The mode of an ongoing cancellation. Shall be present " +
168         "when isCancelPending=true, and shall be None otherwise.",
169         allow_null=True,
170         required=False
171     )
172     error = ProblemDetailsSerializer(
173         help_text="If 'operationState' is 'FAILED_TEMP' or 'FAILED' or " +
174         "'PROCESSING' or 'ROLLING_BACK' and previous value of 'operationState' " +
175         "was 'FAILED_TEMP'  this attribute shall be present ",
176         allow_null=True,
177         required=False
178     )
179     resourceChanges = ResourceChangesSerializer(
180         help_text="It contains information about the cumulative changes " +
181         "to virtualised resources that were performed so far by the LCM " +
182         "operation since its start, if applicable.",
183         required=False,
184         allow_null=True)
185     changedInfo = VnfInfoModificationsSerializer(
186         help_text="Information about the changed VNF instance information, " +
187         "including VNF configurable properties",
188         required=False,
189         allow_null=True)
190     changedExtConnectivity = ExtVirtualLinkInfoSerializer(
191         help_text="Information about changed external connectivity, if this " +
192         "notification represents the result of a lifecycle operation occurrence. " +
193         "Shall be present if the 'notificationStatus' is set to 'RESULT' and the " +
194         "'operation' is set to 'CHANGE_EXT_CONN'. Shall be absent otherwise.",
195         many=True,
196         required=False,
197         allow_null=True)
198     _links = LcmOpLinkSerializer(
199         help_text="Links to resources related to this resource.",
200         required=True)