update ns_create and ns_inst serializer
[vfc/nfvo/lcm.git] / lcm / ns / serializers / create_ns_serializers.py
1 # Copyright (c) 2018, 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
17 from lcm.ns.serializers.ns_serializers import IpAddress
18 from lcm.ns.serializers.common_Link import LinkSerializer
19
20
21 class ContextSerializer(serializers.Serializer):
22     globalCustomerId = serializers.CharField(help_text="Global customer ID", required=False, allow_null=True)
23     serviceType = serializers.CharField(help_text="Service type", required=False, allow_null=True)
24
25
26 class CreateNsReqSerializer(serializers.Serializer):
27     csarId = serializers.CharField(help_text="Package ID of NS", required=False, allow_null=True)
28     nsdId = serializers.CharField(help_text="Identifier of the NSD that defines the NS instance to be"
29                                             "created.", required=True, allow_null=False)
30     nsName = serializers.CharField(help_text="Name of NS", required=False, allow_null=True)
31     nsDescription = serializers.CharField(help_text="Description of NS", required=False, allow_null=True)
32     context = ContextSerializer(help_text="Context of NS", required=False)
33
34
35 class VnfInstanceSerializer(serializers.Serializer):
36     id = serializers.CharField(help_text="Identifier of the VNF instance.", required=True)
37     vnfInstanceName = serializers.CharField(help_text="Name of the VNF instance.", required=False,
38                                             allow_null=True)
39
40
41 class IpOverEthernetAddressDataSerializer(serializers.Serializer):
42     macAddress = serializers.CharField(help_text="Mac address", required=False, allow_null=True)
43     ipAddresses = serializers.ListField(help_text="List of IP addresses to assign to the extCP instance.",
44                                         child=IpAddress(
45                                             help_text="List of IP addresses to assign to the extCP instance.",
46                                             required=True), required=False, allow_null=True)
47
48
49 class cpProtocolDataSerializer(serializers.Serializer):
50     layerProtocol = serializers.ChoiceField(help_text="Identifier of layer(s) and protocol(s).",
51                                             choices=["IP_OVER_ETHERNET"], required=True)
52     ipOverEthernet = serializers.ListField(help_text="Network address data for IP over Ethernet to assign to"
53                                                      "the extCP instance.",
54                                            child=(IpOverEthernetAddressDataSerializer(
55                                                help_text="This typerepresents network address data for IP"
56                                                          "over Ethernet.", required=True)), required=True)
57
58
59 class PnfExtCpInfoSerializer(serializers.Serializer):
60     cpInstanceId = serializers.CharField(help_text="Identifier of the CP in the scope of the PNF.",
61                                          required=True)
62
63     cpdId = serializers.CharField(help_text="Identifier of (reference to) the Connection Point Descriptor"
64                                             "(CPD) for this CP.", required=True)
65
66     cpProtocolData = serializers.ListField(help_text="Parameters for configuring the network protocols on"
67                                                      "the CP.",
68                                            child=(cpProtocolDataSerializer(help_text="This type represents"
69                                                                                      "network protocol data",
70                                                                            required=True)), required=True)
71
72
73 class PnfInfoSerializer(serializers.Serializer):
74     pnfId = serializers.CharField(help_text="Identifier of the PNF.", required=True)
75     pnfName = serializers.CharField(help_text="Name of the PNF.", required=True)
76     pnfdId = serializers.CharField(help_text="Identifier of the PNFD on which the PNF is based.",
77                                    required=True)
78
79     pnfdInfoId = serializers.CharField(help_text="Identifier of the PNFD information onject related to this "
80                                                  "PNF.", required=True)
81     pnfProfileId = serializers.CharField(help_text="Identifier of the related PnfProfile in the NSD on which "
82                                                    "the PNF is based.", required=True)
83
84     cpInfo = serializers.ListField(help_text="Information on the external CP of the PNF",
85                                    child=(PnfExtCpInfoSerializer(help_text="This type represents the"
86                                                                            "information about the external "
87                                                                            "CP of the PNF.", required=True)),
88                                    required=True)
89
90
91 class ResourceHandleSerializer(serializers.Serializer):
92     vimId = serializers.CharField(help_text="Identifier of the VIM under whose control this resource is"
93                                             "placed.", required=False, allow_null=True)
94     resourceProviderId = serializers.CharField(help_text="Identifier of the entity responsible for the"
95                                                          "management of the resource", required=False,
96                                                allow_null=True)
97     resourceId = serializers.CharField(help_text="Identifier of the resource in the scope of the VIM or the "
98                                                  "resource provider.", required=True)
99     vimLevelResourceType = serializers.CharField(help_text="Type of the resource in the scope of the VIM or"
100                                                            "the resource provider",
101                                                  required=False, allow_null=True)
102
103
104 class NsVirtualLinkInfoSerializer(serializers.Serializer):
105     id = serializers.CharField(help_text="Identifier of the VL instance.", required=True)
106     nsVirtualLinkDescId = serializers.CharField(help_text="Identifier of the VLD in the NSD.", required=True)
107     resourceHandle = serializers.ListField(help_text="Identifier(s) of the virtualised network resource(s) "
108                                                      "realizing the VL instance",
109                                            child=(ResourceHandleSerializer(
110                                                help_text="This type represents the information that allows"
111                                                          "addressing a virtualised resource that is used by a"
112                                                          "VNF instance or by an NS instance.",
113                                                required=True)), required=True)
114
115
116 class NsCpHandleSerializer(serializers.Serializer):
117     vnfInstanceId = serializers.CharField(help_text="Identifier of the VNF instance associated to the CP"
118                                                     "instance.", required=False, allow_null=True)
119     vnfExtCpInstanceId = serializers.CharField(help_text="Identifier of the VNF external CP instance in the"
120                                                          "scope of the VNF instance.",
121                                                required=False, allow_null=True)
122     pnfInfoId = serializers.CharField(help_text="Identifier of the PNF instance associated to the CP"
123                                                 "instance.", required=False, allow_null=True)
124     pnfExtCpInstanceId = serializers.CharField(help_text="Identifier of the PNF external CP instance in the"
125                                                          "scope of the PNF.", required=False, allow_null=True)
126     nsInstanceId = serializers.CharField(help_text="Identifier of the NS instance associated to the SAP"
127                                                    "instance", required=False, allow_null=True)
128     nsSapInstanceId = serializers.CharField(help_text="Identifier of the SAP instance in the scope of the NS"
129                                                       "instance.", required=False, allow_null=True)
130
131
132 # end 167
133 class MaskSerializer(serializers.Serializer):
134     startingPoint = serializers.CharField(help_text="Indicates the offset between the last bit of the source"
135                                                     "mac address and the first bit of the sequence of bits"
136                                                     "to be matched.", required=True)
137     length = serializers.CharField(help_text="Indicates the number of bits to be matched", required=True)
138     value = serializers.CharField(help_text="Provide the sequence of bit values to be matched.",
139                                   required=True)
140
141
142 class NfpRuleSerializer(serializers.Serializer):
143     etherDestinationAddress = serializers.CharField(help_text="Indicates a destination Mac address",
144                                                     required=False, allow_null=True)
145     etherSourceAddress = serializers.CharField(help_text="Indicates a source Mac address",
146                                                required=False, allow_null=True)
147     etherType = serializers.ChoiceField(help_text="Indicates the protocol carried over the Ethernet layer",
148                                         choices=["IPV4", "IPV6"], required=False, allow_null=True)
149     vlanTag = serializers.ListField(help_text="ndicates a VLAN identifier in an IEEE 802.1Q-2014 tag",
150                                     required=False, allow_null=True)
151     protocol = serializers.ChoiceField(help_text="Indicates the L4 protocol, For IPv4 [7] this corresponds to"
152                                                  "the field called Protocol to identifythe next level "
153                                                  "protocol", choices=["TCP", "UDP", "ICMP"],
154                                        required=False, allow_null=True)
155     dscp = serializers.CharField(help_text="For IPv4 [7] a string of 0 and 1 digits that corresponds to the"
156                                            "6-bit Differentiated Services Code Point (DSCP) field of the"
157                                            "IP header.", required=False, allow_null=True)
158     sourcePortRange = serializers.CharField(help_text="Indicates a range of source ports",
159                                             required=False, allow_null=True)
160     destinationPortRange = serializers.CharField(help_text="Indicates a range of destination ports",
161                                                  required=False, allow_null=True)
162     sourceIpAddressPrefix = serializers.CharField(help_text="Indicates the source IP address range in CIDR"
163                                                             "format.", required=False, allow_null=True)
164     destinationIpAddressPrefix = serializers.CharField(help_text="Indicates the destination IP address range"
165                                                                  "in CIDRformat.",
166                                                        required=False, allow_null=True)
167     extendedCriteria = serializers.ListField(help_text="Indicates values of specific bits in a frame",
168                                              child=(MaskSerializer(help_text="The Mask data type identifies"
169                                                                              "the value to be matched for a"
170                                                                              "sequence of bits at a particular"
171                                                                              " location in a frame",
172                                                                    required=True)),
173                                              required=False, allow_null=True)
174
175
176 class NfpInfoSerializer(serializers.Serializer):
177     id = serializers.CharField(help_text="Identifier of this NFP instance.", required=True)
178     nfpdId = serializers.CharField(help_text="Identifier of the NFPD used to instantiate this NFP"
179                                              "instance.", required=False, allow_null=True)
180     nfpName = serializers.CharField(help_text="Human readable name for the NFP instance.",
181                                     required=False, allow_null=True)
182     description = serializers.CharField(help_text="Human readable description for the NFP instance.",
183                                         required=False, allow_null=True)
184     nscpHandle = serializers.ListField(help_text="Identifier(s) of the CPs and/or SAPs which the NFP "
185                                                  "passes by",
186                                        child=NsCpHandleSerializer(
187                                            help_text="This type represents an identifier of the CP or SAP"
188                                                      "instance"), required=True)
189     totalCp = serializers.CharField(help_text="Total number of CP and SAP instances in this NFP"
190                                               "instance.", required=False, allow_null=True)
191     nfpRule = NfpRuleSerializer(help_text="The NfpRule data type is an expression of the conditions that "
192                                           "shall be met in order for the NFP to be applicable to the packet",
193                                 required=True)
194     nfpState = serializers.ChoiceField(help_text="The state of the NFP instance.",
195                                        choices=["ENABLED", "DISABLED"], required=True)
196
197
198 class VnffgInfoSerializer(serializers.Serializer):
199     id = serializers.CharField(help_text="Identifier of this VNFFG instance.", required=True)
200     vnffgdId = serializers.CharField(help_text="Identifier of the VNFFGD in the NSD.", required=True)
201     vnfInstanceId = serializers.ListField(help_text="Identifier(s) of the constituent VNF instance(s) of this"
202                                                     "VNFFG instance.",
203                                           child=serializers.CharField(help_text="ID of vnf instance"),
204                                           required=True)
205     pnfInfoId = serializers.ListField(help_text="Identifier(s) of the constituent PNF instance(s) of this"
206                                                 "VNFFG instance",
207                                       child=serializers.CharField(help_text="ID of pnf info"),
208                                       required=False, allow_null=True)
209     nsVirtualLinkInfoId = serializers.ListField(help_text="Identifier(s) of the constituent VL instance(s) of"
210                                                           "thisVNFFG instance.",
211                                                 child=serializers.CharField(
212                                                     help_text="ID of ns virtual link info"), required=True)
213     nsCpHandle = serializers.ListField(help_text="Identifiers of the CP instances attached to the constituent"
214                                                  "VNFs and PNFs or the SAP instances of the VNFFG.",
215                                        child=NsCpHandleSerializer(help_text="This type represents an"
216                                                                             "identifier of the CP or SAP"
217                                                                             "instance", required=False),
218                                        required=True, allow_null=False)
219     nfpInfo = serializers.ListField(help_text="Information on the NFP instances.",
220                                     child=(NfpInfoSerializer(help_text="This type represents an NFP instance",
221
222                                                              required=True)), required=True, allow_null=False)
223
224
225 class AddressRange(serializers.Serializer):
226     minAddress = serializers.IPAddressField(help_text="Lowest IP address belonging to the range.",
227                                             required=True)
228     maxAddress = serializers.IPAddressField(help_text="Highest IP address belonging to the range.",
229                                             required=True)
230
231
232 class ipAddressesSerializer(serializers.Serializer):
233     type = serializers.ChoiceField(help_text="The type of the IP addresses.",
234                                    choices=["IPV4", "IPV6"], required=True)
235     addresses = serializers.ListField(help_text="Fixed addresses assigned (from the subnet defined by "
236                                                 "subnetId if provided)",
237                                       child=serializers.CharField(help_text="An IPV4 or IPV6 address."),
238                                       required=False, allow_null=True)
239 # question
240     isDynamic = serializers.BooleanField(help_text="Indicates whether this set of addresses was assigned "
241                                                    "dynamically (true) or based on address information "
242                                                    "provided as input from the API consumer (false).",
243                                          required=False, default=True)
244     addressRange = AddressRange(help_text="An IP address range used", required=False, allow_null=True)
245     subnetId = serializers.CharField(help_text="Subnet defined by the identifier of the subnet"
246                                                "resource in the VIM", required=False, allow_null=True)
247
248
249 class IpOverEthernetAddressInfoSerializer(serializers.Serializer):
250     macAddress = serializers.CharField(help_text="Assigned MAC address", required=True)
251     ipAddresses = serializers.ListField(help_text="Addresses assigned to the CP or SAP instance.",
252                                         child=(ipAddressesSerializer(help_text="Serializer of ip addresses",
253                                                                      required=True)),
254                                         required=False, allow_null=True)
255
256
257 class CpProtocolInfoSerializer(serializers.Serializer):
258     layerProtocol = serializers.ChoiceField(help_text="The identifier of layer(s) and protocol(s) associated"
259                                                       "to the network address information.",
260                                             choices=["IP_OVER_ETHERNET"], required=True)
261     ipOverEthernet = IpOverEthernetAddressInfoSerializer(help_text="IP addresses over Ethernet to assign to"
262                                                                    "the CPor SAP instance.",
263                                                          required=False, allow_null=True)
264
265
266 class SapInfoSerializer(serializers.Serializer):
267     id = serializers.CharField(help_text="Identifier of the SAP instance.", required=True)
268     sapdId = serializers.CharField(help_text="Identifier of the SAPD in the NSD.", required=True)
269     sapName = serializers.CharField(help_text="Human readable name for the SAP instance.", required=True)
270     description = serializers.CharField(help_text="Human readable description for the SAP instance.",
271                                         required=True)
272     sapProtocolInfo = serializers.ListField(help_text="Network protocol information for this SAP.",
273                                             child=(CpProtocolInfoSerializer(
274                                                 help_text="This type describes the protocol layer(s) that a"
275                                                           "CP or SAP uses together with protocol-related"
276                                                           "information", required=True)), required=True)
277
278
279 class NsScaleInfoSerializer(serializers.Serializer):
280     nsScalingAspectId = serializers.CharField(help_text="Identifier of the NS scaling aspect.", required=True)
281     nsScaleLevelId = serializers.CharField(help_text="Identifier of the NS scale level.", required=True)
282
283
284 class AffinityOrAntiAffinityRuleSerializer(serializers.Serializer):
285     vnfdId = serializers.ListField(help_text="Reference to a VNFD.",
286                                    child=serializers.CharField(help_text="Identifier of the vnfd"),
287                                    required=False, allow_null=True)
288     vnfProfileId = serializers.ListField(help_text="Reference to a vnfProfile defined in the NSD.",
289                                          child=serializers.CharField(
290                                              help_text="Identifier of the vnfProfile"), required=True)
291     vnfInstanceId = serializers.ListField(help_text="Reference to the existing VNF instance as the subject of"
292                                                     "the affinity or anti-affinity rule",
293                                           child=serializers.CharField(help_text="identifier of the"
294                                                                                 "vnfInstanceId"),
295                                           required=False, allow_null=True)
296     affinityOrAntiAffiinty = serializers.ChoiceField(help_text="The type of the constraint.",
297                                                      choices=["AFFINITY", "ANTI_AFFINITY"], required=True)
298     scope = serializers.ChoiceField(help_text="Specifies the scope of the rule where the placement"
299                                               "constraint applies.",
300                                     choices=["NFVI_POP", "ZONE", "ZONE_GROUP", "NFVI_NODE"], required=True)
301
302
303 class Links(serializers.Serializer):
304     self = LinkSerializer(help_text="URI of this resource.", required=True)
305     nestedNsInstances = LinkSerializer(help_text="Links to the nested NS instances of the present NS"
306                                                  "instance.", required=False, allow_null=True)
307     instantiate = LinkSerializer(help_text="Link to the 'instantiate' task resource", required=False,
308                                  allow_null=True)
309     terminate = LinkSerializer(help_text="Link to the 'terminate' task resource", required=False, allow_null=True)
310     update = LinkSerializer(help_text="Link to the 'update' task resource", required=False, allow_null=True)
311     scale = LinkSerializer(help_text="Link to the 'scale' task resource", required=False, allow_null=True)
312     heal = LinkSerializer(help_text="Link to the 'heal' task resource", required=False, allow_null=True)
313
314
315 class CreateNsRespSerializer(serializers.Serializer):
316     nsInstanceId = serializers.CharField(help_text="ID of NS instance", required=True)
317     nsInstanceName = serializers.CharField(help_text="Human readable name of the NS instance.", required=True)
318     nsInstanceDescription = serializers.CharField(help_text="Human readable description of the NS instance.",
319                                                   required=True)
320     nsdId = serializers.CharField(help_text="Identifier of the NSD on which the NS instance is based.",
321                                   required=True)
322     nsdInfoId = serializers.CharField(help_text="Identifier of the NSD information object on which the "
323                                                 "NS instance is based.", required=True)
324
325     flavourId = serializers.CharField(help_text="Identifier of the NS deployment flavour applied to "
326                                                 "the NS instance.", required=False, allow_null=True)
327     vnfInstance = serializers.ListField(help_text="Information on constituent VNF(s) of the NS instance.",
328                                         child=(VnfInstanceSerializer(help_text="This type represents a VNF"
329                                                                                "instance", required=True)),
330                                         required=False, allow_null=True)
331
332     pnfInfo = serializers.ListField(help_text="Information on the PNF(s) that are part of the NS instance.",
333                                     child=(PnfInfoSerializer(help_text="This type represents the information "
334                                            "about a PNF that is part of an NS instance.", required=True)),
335                                     required=False, allow_null=True)
336     virtualLinkInfo = serializers.ListField(help_text="Information on the VL(s) of the NS instance.",
337                                             child=(NsVirtualLinkInfoSerializer(help_text="This type specifies the"
338                                                                                          "information about an"
339                                                                                          "NS VL instance.",
340                                                                                required=True)), required=False,
341                                             allow_null=True)
342     vnffgInfo = serializers.ListField(help_text="Information on the VNFFG(s) of the NS instance",
343                                       child=(VnffgInfoSerializer(help_text="This type specifies the information"
344                                                                            "about a VNFFG instance.", required=True)),
345                                       required=False, allow_null=True)
346     sapInfo = serializers.ListField(help_text="Information on the SAP(s) of the NS instance",
347                                     child=(SapInfoSerializer(help_text="This type represents an SAP"
348                                                                        "instance.", required=True)),
349                                     required=False, allow_null=True)
350     nestedNsInstanceId = serializers.ListField(help_text="Identifier of the nested NS(s) of the NS instance.",
351                                                child=serializers.CharField(help_text="nested of the NS"
352                                                                                      "instance",),
353                                                required=False, allow_null=True)
354     nsState = serializers.ChoiceField(help_text="The state of the NS instance.", required=True,
355                                       choices=["NOT_INSTANTIATED", "INSTANTIATED"])
356     nsScaleStatus = serializers.ListField(help_text="Status of each NS scaling aspect declared in the"
357                                                     "applicable DF, how 'big' the NS instance has been"
358                                                     "scaled w.r.t. that aspect.",
359                                           child=(NsScaleInfoSerializer(help_text="This type represents the"
360                                                                                  "target NS Scale level for"
361                                                                                  "each NS scaling aspect of"
362                                                                                  "the current deployment"
363                                                                                  "flavour.")), required=False,
364                                           allow_null=True)
365     additionalAffinityOrAntiAffinityRule = serializers.ListField(help_text="Information on the additional"
366                                                                            "affinity or anti-affinity rule"
367                                                                            "from NS instantiation operation.",
368                                                                  child=(AffinityOrAntiAffinityRuleSerializer(
369                                                                      help_text="This type describes the "
370                                                                                "additional affinity or"
371                                                                                "anti-affinity rule applicable"
372                                                                                "between the VNF instances to"
373                                                                                "be instantiated in the NS"
374                                                                                "instantiation operation"
375                                                                                "request or between the VNF"
376                                                                                "instances to be instantiated"
377                                                                                "in the NS instantiation"
378                                                                                "operation request and the"
379                                                                                "existing VNF instances.",
380                                                                      required=True)), required=False,
381                                                                  allow_null=True)
382     _links = Links(help_text="Links to resources related to this resource.", required=True)