1 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 from rest_framework import serializers
18 from affected_vnfs import AffectedVnfsSerializer
19 from affected_pnfs import AffectedPnfsSerializer
20 from affected_vls import AffectedVLsSerializer
21 from affected_vnffgs import AffectedVnffgsSerializer
22 from affected_nss import AffectedNssSerializer
23 from affected_saps import AffectedSapsSerializer
25 from link import LinkSerializer
26 from response import ProblemDetailsSerializer
27 from lcm.ns import const
30 class ResourceChangesSerializer(serializers.Serializer):
31 affectedVnfs = AffectedVnfsSerializer(
32 help_text="Information about VNFC instances that were affected during the lifecycle operation.",
36 affectedPnfs = AffectedPnfsSerializer(
37 help_text="Information about the PNF instances that were affected during the lifecycle operation.",
41 affectedVls = AffectedVLsSerializer(
42 help_text="Information about the VL instances that were affected during the lifecycle operation",
46 affectedVnffgs = AffectedVnffgsSerializer(
47 help_text="Information about the VNFFG instances that were affected during the lifecycle operation.",
51 affectedNss = AffectedNssSerializer(
52 help_text="Information about the nested NS instances that were affected during the lifecycle operation.",
56 affectedSaps = AffectedSapsSerializer(
57 help_text="Information about the SAP instances that were affected during the lifecycle operation.",
63 class LcmOpLinkSerializer(serializers.Serializer):
64 self = LinkSerializer(
65 help_text="URI of this resource.",
68 nsInstance = serializers.CharField(
69 help_text="Link to the NS instance that the operation applies to.",
71 cancel = serializers.CharField(
72 help_text="Link to the task resource that represents the 'cancel' operation for this LCM operation occurrence.",
74 retry = serializers.CharField(
75 help_text="Link to the task resource that represents the 'retry' operation for this LCM operation occurrence, "
76 "if retrying is currently allowed",
78 rollback = serializers.CharField(
79 help_text="Link to the task resource that represents the 'cancel' operation for this LCM operation occurrence.",
81 fail = serializers.CharField(
82 help_text="Link to the task resource that represents the 'fail' operation for this LCM operation occurrence.",
86 class NSLCMOpOccSerializer(serializers.Serializer):
87 id = serializers.CharField(
88 help_text="Identifier of this NS lifecycle management operation occurrence,",
93 operationState = serializers.ChoiceField(
94 help_text="The state of the VNF LCM operation occurrence. ",
96 choices=const.LCM_OPERATION_STATE_TYPES
98 stateEnteredTime = serializers.CharField(
99 help_text="Date-time when the current state was entered.",
102 startTime = serializers.CharField(
103 help_text="Date-time of the start of the operation.",
106 nsInstanceId = serializers.UUIDField(
107 help_text="Identifier of the ns instance to which the operation applies"
109 operation = serializers.ChoiceField(
110 help_text="The lifecycle management operation",
112 choices=const.NS_LCM_OP_TYPES
114 isAutomaticInvocation = serializers.BooleanField(
115 help_text="Set to true if this NS LCM operation occurrence has been automatically triggered by the NFVO.",
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 ",
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 "
136 cancelMode = serializers.CharField(
137 help_text="The mode of an ongoing cancellation. Shall be present when isCancelPending=true, and shall be None "
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 ",
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.",
153 _links = LcmOpLinkSerializer(
154 help_text="Links to resources related to this resource.",