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.
15 from rest_framework import serializers
16 from lcm.ns.serializers.update_serializers import VnfInstanceDataSerializer
17 from lcm.ns.serializers.create_ns_serializers import NsScaleInfoSerializer
18 from lcm.ns.serializers.inst_ns_serializers import VnfLocationConstraintSerializer, ParamsForVnfSerializer
21 # class VnfInstanceDataSerializer(serializers.Serializer):
22 # vnfInstanceId = serializers.CharField(help_text="Identifier of the existing VNF instance to be used in"
23 # "the NS. ", required=True)
24 # vnfProfileId = serializers.CharField(help_text="Identifier of (Reference to) a vnfProfile defined in the "
25 # "NSD which the existing VNF instance shall be matched "
26 # "with. If not present", required=False, allow_null=True)
29 class ScaleNsByStepsDataSerializer(serializers.Serializer):
30 scalingDirection = serializers.ChoiceField(help_text="The scaling direction",
31 choices=["SCALE_IN", "SCALE_OUT"], required=True)
32 aspectId = serializers.CharField(help_text="The aspect of the NS that is requested to be scaled, as "
33 "declared in the NSD. ", required=True)
34 numberOfSteps = serializers.CharField(help_text="The number of scaling steps to be performed. Defaults "
35 "to 1. ", required=False, allow_null=True)
38 # class NsScaleInfoSerializer(serializers.Serializer):
39 # nsScalingAspectId = serializers.CharField(help_text="Identifier of the NS scaling aspect.", required=True)
40 # nsScaleLevelId = serializers.CharField(help_text="Identifier of the NS scale level.", required=True)
43 class ScaleNsToLevelDataSerializer(serializers.Serializer):
44 nsInstantiationLevel = serializers.CharField(help_text="Identifier of the target NS instantiation level "
45 "of the current DF to which the NS instance is "
46 "requested to be scaled.",
47 required=False, allow_null=True)
48 nsScaleInfo = serializers.ListField(help_text="For each NS scaling aspect of the current DF",
49 child=NsScaleInfoSerializer(
50 help_text="This type represents the target NS Scale level for "
51 "each NS scaling aspect of the current deployment "
52 "flavour.", required=True),
53 required=False, allow_null=True)
56 # class ParamsForVnfSerializer(serializers.Serializer):
57 # vnfProfileId = serializers.CharField(help_text="Identifier of (reference to) a vnfProfile to which the "
58 # "additional parameters apply.", required=True)
59 # additionalParams = serializers.DictField(help_text="Additional parameters that are applied for the VNF "
60 # "instance to be created.",
61 # child=serializers.CharField(help_text="KeyValue Pairs",
63 # required=False, allow_null=True)
66 # class LocationConstraintsSerializer(serializers.Serializer):
67 # countryCode = serializers.CharField(help_text="The two-letter ISO 3166 [29] country code in capital "
68 # "letters", required=True)
69 # civicAddressElement = serializers.ListField(help_text="Zero or more elements comprising the civic "
70 # "address.", required=False, allow_null=True)
73 # class VnfLocationConstraintSerializer(serializers.Serializer):
74 # vnfProfileId = serializers.CharField(help_text="Identifier (reference to) of a VnfProfile in the NSD used "
75 # "to manage the lifecycle of the VNF instance.",
78 # locationConstraints = LocationConstraintsSerializer(help_text="This type represents location constraints "
79 # "for a VNF to be instantiated. The location"
80 # " constraints shall be presented as a "
81 # "country code", required=True)
84 class ScaleNsDataSerializer(serializers.Serializer):
85 vnfInstanceToBeAdded = serializers.ListField(help_text="An existing VNF instance to be added to the NS "
86 "instance as part of the scaling operation. ",
87 child=VnfInstanceDataSerializer(
88 help_text="This type specifies an existing VNF instance "
89 "to be used in the NS instance and if needed",
90 required=True), required=False, allow_null=True)
91 vnfInstanceToBeRemoved = serializers.ListField(help_text="The VNF instance to be removed from the NS "
92 "instance as part of the scaling operation",
93 required=False, allow_null=True)
94 scaleNsByStepsData = ScaleNsByStepsDataSerializer(help_text="The information used to scale an NS "
95 "instance by one or more scaling steps",
96 required=False, allow_null=True)
97 scaleNsToLevelData = ScaleNsToLevelDataSerializer(help_text="The information used to scale an NS instance"
98 " to a target size. ",
99 required=False, allow_null=True)
100 additionalParamsForNs = serializers.DictField(help_text="Allows the OSS/BSS to provide additional "
101 "parameter(s) at the NS level necessary for the "
103 child=serializers.CharField(help_text="KeyValue Pairs",
105 required=False, allow_null=True)
106 additionalParamsForVnf = serializers.ListField(help_text="Allows the OSS/BSS to provide additional "
107 "parameter(s) per VNF instance",
108 child=ParamsForVnfSerializer(
109 help_text="This type defines the additional parameters"
110 " for the VNF instance to be created "
111 "associated with an NS instance.",
112 required=True), required=False, allow_null=True)
113 locationConstraints = serializers.ListField(help_text="The location constraints for the VNF to be "
114 "instantiated as part of the NS scaling.",
115 child=VnfLocationConstraintSerializer(
116 help_text="This type represents the association of "
117 "location constraints to a VNF instance to"
118 "be created according to a specific VNF "
119 "profile", required=True),
120 required=False, allow_null=True)
123 class VnfScaleInfoSerializer(serializers.Serializer):
124 aspectlId = serializers.Serializer(help_text="The scaling aspect", required=True)
125 scaleLevel = serializers.Serializer(help_text="The scale level for that aspect", required=True)
128 class ScaleToLevelDataSerializer(serializers.Serializer):
129 vnfInstantiationLevelId = serializers.CharField(help_text="Identifier of the target instantiation level "
130 "of the current deployment flavour to which "
131 "the VNF is requested to be scaled.",
132 required=False, allow_null=True)
133 vnfScaleInfo = serializers.ListField(help_text="For each scaling aspect of the current deployment "
135 child=VnfScaleInfoSerializer(help_text="This type describes the "
136 "provides information about"
137 " the scale level of a VNF"
138 " instance with respect to "
139 "one scaling aspect",
141 required=False, allow_null=True)
143 additionalParams = serializers.DictField(help_text="Additional parameters passed by the NFVO as input to "
144 "the scaling process", required=False, allow_null=True)
147 class ScaleByStepDataSerializer(serializers.Serializer):
148 aspectId = serializers.CharField(help_text="Identifier of (reference to) the aspect of the VNF that is "
149 "requested to be scaled", required=True)
150 numberOfSteps = serializers.CharField(help_text="Number of scaling steps.",
151 required=False, allow_null=True)
152 additionalParams = serializers.DictField(help_text="Additional parameters passed by the NFVO as input to"
153 "he scaling process", required=False, allow_null=True)
156 class ScaleVnfDataSerializer(serializers.Serializer):
157 vnfInstanceid = serializers.CharField(help_text="Identifier of the VNF instance being scaled.",
160 scaleVnfType = serializers.ChoiceField(help_text="Type of the scale VNF operation requested.",
161 choices=["SCALE_OUT", "SCALE_IN", "SCALE_TO_INSTANTIATION_LEVEL",
162 "SCALE_TO_SCALE_LEVEL(S)"], required=True)
164 scaleToLevelData = ScaleToLevelDataSerializer(help_text="The information used for scaling to a "
165 "given level.", required=False)
167 scaleByStepData = ScaleByStepDataSerializer(help_text="The information used for scaling by steps",
171 class ScaleNsRequestSerializer(serializers.Serializer):
172 scaleType = serializers.ChoiceField(help_text="Indicates the type of scaling to be performed",
173 choices=["SCALE_NS ", "SCALE_VNF"], required=True)
174 scaleNsData = ScaleNsDataSerializer(help_text="The necessary information to scale the referenced NS "
175 "instance. ", required=False, allow_null=True)
176 scaleVnfData = serializers.ListField(help_text="Timestamp indicating the scale time of the NS",
177 child=ScaleVnfDataSerializer(help_text="This type represents defines"
178 "the information to scale a "
179 "VNF instance to a given "
180 "level", required=True),
181 required=False, allow_null=True)
182 scaleTime = serializers.CharField(help_text="Timestamp indicating the scale time of the NS",
183 required=False, allow_null=True)
186 class ManualScaleNsReqSerializer(serializers.Serializer):
187 scaleType = serializers.CharField(help_text="Type of NS Scale", required=True)
188 scaleNsData = ScaleNsDataSerializer(help_text="Scale NS data", many=True)