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 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
29 class ResourceChangesSerializer(serializers.Serializer):
30 affectedVnfs = AffectedVnfsSerializer(
31 help_text="Information about VNFC instances that were affected during the lifecycle operation.",
35 affectedPnfs = AffectedPnfsSerializer(
36 help_text="Information about the PNF instances that were affected during the lifecycle operation.",
40 affectedVls = AffectedVLsSerializer(
41 help_text="Information about the VL instances that were affected during the lifecycle operation",
45 affectedVnffgs = AffectedVnffgsSerializer(
46 help_text="Information about the VNFFG instances that were affected during the lifecycle operation.",
50 affectedNss = AffectedNssSerializer(
51 help_text="Information about the nested NS instances that were affected during the lifecycle operation.",
55 affectedSaps = AffectedSapsSerializer(
56 help_text="Information about the SAP instances that were affected during the lifecycle operation.",
62 class LcmOpLinkSerializer(serializers.Serializer):
63 self = LinkSerializer(
64 help_text="URI of this resource.",
67 nsInstance = serializers.CharField(
68 help_text="Link to the NS instance that the operation applies to.",
70 cancel = serializers.CharField(
71 help_text="Link to the task resource that represents the 'cancel' operation for this LCM operation occurrence.",
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",
77 rollback = serializers.CharField(
78 help_text="Link to the task resource that represents the 'cancel' operation for this LCM operation occurrence.",
80 fail = serializers.CharField(
81 help_text="Link to the task resource that represents the 'fail' operation for this LCM operation occurrence.",
85 class NSLCMOpOccSerializer(serializers.Serializer):
86 id = serializers.CharField(
87 help_text="Identifier of this NS lifecycle management operation occurrence,",
92 operationState = serializers.ChoiceField(
93 help_text="The state of the VNF LCM operation occurrence. ",
95 choices=const.LCM_OPERATION_STATE_TYPES
97 stateEnteredTime = serializers.CharField(
98 help_text="Date-time when the current state was entered.",
101 startTime = serializers.CharField(
102 help_text="Date-time of the start of the operation.",
105 nsInstanceId = serializers.UUIDField(
106 help_text="Identifier of the ns instance to which the operation applies"
108 operation = serializers.ChoiceField(
109 help_text="The lifecycle management operation",
111 choices=const.NS_LCM_OP_TYPES
113 isAutomaticInvocation = serializers.BooleanField(
114 help_text="Set to true if this NS LCM operation occurrence has been automatically triggered by the NFVO.",
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 ",
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 "
135 cancelMode = serializers.CharField(
136 help_text="The mode of an ongoing cancellation. Shall be present when isCancelPending=true, and shall be None "
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 ",
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.",
152 _links = LcmOpLinkSerializer(
153 help_text="Links to resources related to this resource.",
157 class NSLCMOpOccsSerializer(serializers.ListSerializer):
158 child = NSLCMOpOccSerializer()