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