1 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
2 # Copyright (c) 2019, ZTE Corporation.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 from rest_framework import serializers
18 from lcm.ns.serializers.sol.inst_ns_serializers import VnfLocationConstraintSerializer, ParamsForVnfSerializer
19 from lcm.ns.serializers.sol.update_serializers import VnfInstanceDataSerializer
20 from lcm.ns.serializers.sol.ns_instance import NsScaleInfoSerializer, VnfScaleInfoSerializer
21 from lcm.ns.enum import SCALING_DIRECTION, SCALE_VNF_TYPE, SCALE_TYPE
22 from lcm.pub.utils.enumutil import enum_to_list
25 class ScaleNsByStepsDataSerializer(serializers.Serializer):
26 scalingDirection = serializers.ChoiceField(
27 help_text="The scaling direction",
28 choices=enum_to_list(SCALING_DIRECTION),
30 aspectId = serializers.CharField(
31 help_text="The aspect of the NS that is requested to be scaled, as declared in the NSD. ",
33 numberOfSteps = serializers.CharField(
34 help_text="The number of scaling steps to be performed. Defaults to 1. ",
39 class ScaleNsToLevelDataSerializer(serializers.Serializer):
40 nsInstantiationLevel = serializers.CharField(
41 help_text="Identifier of the target NS instantiation level "
42 "of the current DF to which the NS instance is requested to be scaled.",
45 nsScaleInfo = serializers.ListField(
46 help_text="For each NS scaling aspect of the current DF",
47 child=NsScaleInfoSerializer(
48 help_text="This type represents the target NS Scale level for "
49 "each NS scaling aspect of the current deployment flavour.",
55 class ScaleNsDataSerializer(serializers.Serializer):
56 vnfInstanceToBeAdded = serializers.ListField(
57 help_text="An existing VNF instance to be added to the NS instance as part of the scaling operation.",
58 child=VnfInstanceDataSerializer(
59 help_text="This type specifies an existing VNF instance to be used in the NS instance and if needed",
63 vnfInstanceToBeRemoved = serializers.ListField(
64 help_text="The VNF instance to be removed from the NS instance as part of the scaling operation",
67 scaleNsByStepsData = ScaleNsByStepsDataSerializer(
68 help_text="The information used to scale an NS instance by one or more scaling steps",
71 scaleNsToLevelData = ScaleNsToLevelDataSerializer(
72 help_text="The information used to scale an NS instance to a target size. ",
75 additionalParamsForNs = serializers.DictField(
76 help_text="Allows the OSS/BSS to provide additional parameter(s) at the NS level necessary for the NS scaling ",
77 child=serializers.CharField(help_text="KeyValue Pairs",
81 additionalParamsForVnf = serializers.ListField(
82 help_text="Allows the OSS/BSS to provide additional parameter(s) per VNF instance",
83 child=ParamsForVnfSerializer(
84 help_text="This type defines the additional parameters for the VNF instance to be created associated with an NS instance.",
88 locationConstraints = serializers.ListField(
89 help_text="The location constraints for the VNF to be instantiated as part of the NS scaling.",
90 child=VnfLocationConstraintSerializer(
91 help_text="This type represents the association of location constraints to a VNF instance to"
92 "be created according to a specific VNF profile",
98 class ScaleToLevelDataSerializer(serializers.Serializer):
99 vnfInstantiationLevelId = serializers.CharField(
100 help_text="Identifier of the target instantiation level of the current deployment flavour to which the VNF is requested to be scaled.",
103 vnfScaleInfo = serializers.ListField(
104 help_text="For each scaling aspect of the current deployment flavour",
105 child=VnfScaleInfoSerializer(
106 help_text="This type describes the provides information about the scale level of a VNF instance with respect to one scaling aspect",
110 additionalParams = serializers.DictField(
111 help_text="Additional parameters passed by the NFVO as input to the scaling process",
116 class ScaleByStepDataSerializer(serializers.Serializer):
117 aspectId = serializers.CharField(
118 help_text="Identifier of (reference to) the aspect of the VNF that is requested to be scaled.",
120 numberOfSteps = serializers.CharField(
121 help_text="Number of scaling steps.",
124 additionalParams = serializers.DictField(
125 help_text="Additional parameters passed by the NFVO as input to the scaling process.",
130 class ScaleVnfDataSerializers(serializers.Serializer):
131 vnfInstanceid = serializers.CharField(
132 help_text="Identifier of the VNF instance being scaled.",
135 scaleVnfType = serializers.ChoiceField(
136 help_text="Type of the scale VNF operation requested.",
137 choices=enum_to_list(SCALE_VNF_TYPE),
140 scaleToLevelData = ScaleToLevelDataSerializer(
141 help_text="The information used for scaling to a given level.",
144 scaleByStepData = ScaleByStepDataSerializer(
145 help_text="The information used for scaling by steps.",
149 class ScaleNsRequestSerializer(serializers.Serializer):
150 scaleType = serializers.ChoiceField(
151 help_text="Indicates the type of scaling to be performed",
152 choices=enum_to_list(SCALE_TYPE),
154 scaleNsData = ScaleNsDataSerializer(
155 help_text="The necessary information to scale the referenced NS instance.",
158 scaleVnfData = serializers.ListField(
159 help_text="Timestamp indicating the scale time of the NS",
160 child=ScaleVnfDataSerializers(
161 help_text="This type represents defines the information to scale a VNF instance to a given level",
165 scaleTime = serializers.CharField(
166 help_text="Timestamp indicating the scale time of the NS",