Merge "fix Sub error"
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / serializers / serializers.py
1 # Copyright 2018 ZTE Corporation.
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
18 class CreateVnfReqSerializer(serializers.Serializer):
19     vnfdId = serializers.CharField(
20         help_text="Identifier that identifies the VNFD which defines the VNF instance to be created.",
21         max_length=255,
22         required=True,
23         allow_null=True)
24     vnfInstanceName = serializers.CharField(
25         help_text="Human-readable name of the VNF instance to be created.",
26         max_length=255,
27         required=True,
28         allow_null=False)
29     vnfInstanceDescription = serializers.CharField(
30         help_text="Human-readable description of the VNF instance to be created.",
31         max_length=255,
32         required=False,
33         allow_null=True)
34
35
36 class CreateVnfRespSerializer(serializers.Serializer):
37     vnfInstanceId = serializers.CharField(
38         help_text="Identifier of the VNF instance",
39         required=True,
40         max_length=255,
41         allow_null=True)
42
43
44 class ResourceSerializer(serializers.Serializer):
45     resourceId = serializers.CharField(
46         help_text="resourceId",
47         required=True,
48         max_length=255,
49         allow_null=True)
50     vimId = serializers.CharField(
51         help_text="vimId",
52         required=True,
53         max_length=255,
54         allow_null=True)
55
56
57 class VirtualStorageResourceInfoSerializer(serializers.Serializer):
58     virtualStorageInstanceId = serializers.CharField(
59         help_text="virtualStorageInstanceId",
60         required=False,
61         allow_null=True,
62         max_length=255)
63     virtualStorageDescId = serializers.CharField(
64         help_text="virtualStorageDescId",
65         required=False,
66         max_length=255,
67         allow_null=True)
68     storageResource = ResourceSerializer(
69         help_text="storageResource",
70         required=False,
71         allow_null=True)
72
73
74 class VirtualLinkResourceInfoSerializer(serializers.Serializer):
75     virtualLinkInstanceId = serializers.CharField(
76         help_text="virtualLinkInstanceId",
77         required=False,
78         max_length=255,
79         allow_null=True)
80     virtualLinkDescId = serializers.CharField(
81         help_text="virtualLinkDescId",
82         required=False,
83         max_length=255,
84         allow_null=True)
85     networkResource = ResourceSerializer(
86         help_text="networkResource",
87         required=False,
88         allow_null=True)
89
90
91 class VnfcResourceInfoSerializer(serializers.Serializer):
92     vnfcInstanceId = serializers.CharField(
93         help_text="vnfcInstanceId",
94         required=False,
95         max_length=255,
96         allow_null=True)
97     vduId = serializers.CharField(
98         help_text="vduId",
99         required=False, max_length=255, allow_null=True)
100     storageResourceIds = serializers.CharField(
101         help_text="storageResourceIds",
102         required=False,
103         max_length=255,
104         allow_null=True)
105     computeResource = ResourceSerializer(
106         help_text="computeResource",
107         required=False,
108         allow_null=True)
109
110
111 class AccessInfoSerializer(serializers.Serializer):
112     tenant = serializers.CharField(
113         help_text="tenant",
114         required=True,
115         max_length=255,
116         allow_null=True)
117     username = serializers.CharField(
118         help_text="username",
119         required=True,
120         max_length=255,
121         allow_null=True)
122     password = serializers.CharField(
123         help_text="password",
124         required=True,
125         max_length=255,
126         allow_null=True)
127
128
129 class InterfaceInfoSerializer(serializers.Serializer):
130     vimType = serializers.CharField(
131         help_text="vimType",
132         required=True,
133         max_length=255,
134         allow_null=True)
135     apiVersion = serializers.CharField(
136         help_text="apiVersion",
137         required=True,
138         max_length=255,
139         allow_null=True)
140     protocolType = serializers.ChoiceField(
141         help_text="protocolType",
142         choices=["http", "https"],
143         required=True)
144
145
146 class VimInfoSerializer(serializers.Serializer):
147     vimInfoId = serializers.CharField(
148         help_text="vimInfoId",
149         required=False,
150         max_length=255,
151         allow_null=True)
152     vimId = serializers.CharField(
153         help_text="vimId",
154         required=False,
155         max_length=255,
156         allow_null=True)
157     interfaceEndpoint = serializers.CharField(
158         help_text="interfaceEndpoint",
159         required=False,
160         max_length=255,
161         allow_null=True)
162     interfaceInfo = InterfaceInfoSerializer(
163         help_text="vimInfoId",
164         required=False,
165         allow_null=True)
166     accessInfo = AccessInfoSerializer(
167         help_text="accessInfo",
168         required=False,
169         allow_null=True)
170
171
172 class LinkPortsSerializer(serializers.Serializer):
173     resourceId = serializers.CharField(
174         help_text="resourceId",
175         required=True,
176         max_length=255,
177         allow_null=True)
178     vimId = serializers.CharField(
179         help_text="vimId",
180         required=False,
181         max_length=255,
182         allow_null=True)
183
184
185 class ResourceHandleSerializer(serializers.Serializer):
186     resourceId = serializers.CharField(
187         help_text="resourceId",
188         required=True,
189         max_length=255,
190         allow_null=True)
191     vimId = serializers.CharField(
192         help_text="vimId",
193         required=False,
194         max_length=255,
195         allow_null=True)
196     resourceProviderId = serializers.CharField(
197         help_text="resourceProviderId",
198         required=False,
199         max_length=255,
200         allow_null=True)
201
202
203 class ExtVirtualLinkInfoSerializer(serializers.Serializer):
204     extVirtualLinkId = serializers.CharField(
205         help_text="extVirtualLinkId",
206         required=True,
207         max_length=255,
208         allow_null=True)
209     resourceHandle = ResourceHandleSerializer(
210         help_text="iPAddress",
211         required=True)
212     linkPorts = LinkPortsSerializer(
213         help_text="iPAddress",
214         many=True,
215         allow_null=True)
216
217
218 class L3AddressDataSerializer(serializers.Serializer):
219     iPAddressType = serializers.ChoiceField(
220         help_text="iPAddressType",
221         choices=["IPv4", "IPv6"],
222         required=True)
223     iPAddress = serializers.CharField(
224         help_text="iPAddress",
225         required=True,
226         max_length=255,
227         allow_null=True)
228
229
230 class NetworkAddressSerializer(serializers.Serializer):
231     addressType = serializers.ChoiceField(
232         help_text="addressType",
233         choices=["MAC", "IP"],
234         required=True)
235     l2AddressData = serializers.CharField(
236         help_text="l2AddressData",
237         required=False,
238         max_length=255,
239         allow_null=True)
240     l3AddressData = L3AddressDataSerializer(
241         help_text="addresses",
242         required=False)
243
244
245 class ExtCpInfoSerializer(serializers.Serializer):
246     cpInstanceId = serializers.CharField(
247         help_text="cpInstanceId",
248         required=False,
249         max_length=255,
250         allow_null=True)
251     cpdId = serializers.CharField(
252         help_text="cpdId",
253         required=True,
254         max_length=255,
255         allow_null=True)
256     numDynamicAddresses = serializers.CharField(
257         help_text="numDynamicAddresses",
258         required=False,
259         max_length=255,
260         allow_null=True)
261     addresses = NetworkAddressSerializer(
262         help_text="addresses",
263         many=True,
264         allow_null=True)
265
266
267 class ScaleInfoSerializer(serializers.Serializer):
268     aspectId = serializers.CharField(
269         help_text="aspectId",
270         required=True,
271         max_length=255,
272         allow_null=True)
273     scaleLevel = serializers.IntegerField(
274         help_text="scaleLevel",
275         required=True)
276
277
278 class instantiatedVnfInfoSerializer(serializers.Serializer):
279     flavourId = serializers.CharField(
280         help_text="flavourId",
281         required=True,
282         max_length=255,
283         allow_null=True)
284     vnfState = serializers.ChoiceField(
285         help_text="vnfState",
286         choices=["STARTED", "STOPPED", "NOT_INSTANTIATED", "INSTANTIATED", "FAILED"],
287         required=True,
288         allow_null=True)
289     scaleStatus = ScaleInfoSerializer(
290         help_text="scaleStatus",
291         many=True)
292     extCpInfo = ExtCpInfoSerializer(
293         help_text="extCpInfo",
294         many=True)
295     extVirtualLink = ExtVirtualLinkInfoSerializer(
296         help_text="extVirtualLink",
297         many=True)
298     monitoringParameters = serializers.DictField(
299         help_text="monitoringParameters",
300         child=serializers.CharField(allow_blank=True),
301         required=False,
302         allow_null=True)
303     vimInfo = VimInfoSerializer(
304         help_text="vimInfo",
305         many=True)
306     vnfcResourceInfo = VnfcResourceInfoSerializer(
307         help_text="vnfcResourceInfo",
308         many=True)
309     virtualLinkResourceInfo = VirtualLinkResourceInfoSerializer(
310         help_text="virtualLinkResourceInfo",
311         many=True)
312     virtualStorageResourceInfo = VirtualStorageResourceInfoSerializer(
313         help_text="virtualStorageResourceInfo",
314         many=True)
315
316
317 class VnfInfoSerializer(serializers.Serializer):
318     vnfInstanceId = serializers.CharField(
319         help_text="vnfInstanceId",
320         required=True,
321         max_length=255,
322         allow_null=True)
323     vnfInstanceName = serializers.CharField(
324         help_text="vnfInstanceName",
325         required=True,
326         max_length=255,
327         allow_null=True)
328     onboardedVnfPkgInfoId = serializers.CharField(
329         help_text="onboardedVnfPkgInfoId",
330         required=False,
331         max_length=255,
332         allow_null=True)
333     vnfdVersion = serializers.CharField(
334         help_text="vnfdVersion",
335         required=False,
336         max_length=255,
337         allow_null=True,
338         allow_blank=True)
339     vnfProvider = serializers.CharField(
340         help_text="vnfProvider",
341         required=False,
342         max_length=255,
343         allow_null=True,
344         allow_blank=True)
345     instantiatedVnfInfo = instantiatedVnfInfoSerializer(
346         help_text="instantiatedVnfInfo",
347         required=True)
348
349
350 class VnfsInfoSerializer(serializers.ListSerializer):
351     child = VnfInfoSerializer()
352
353
354 class ExtVirtualLinkSerizlizer(serializers.Serializer):
355     vlInstanceId = serializers.CharField(
356         help_text="vlInstanceId",
357         required=False,
358         max_length=255,
359         allow_null=True)
360     resourceSubnetId = serializers.CharField(
361         help_text="resourceSubnetId",
362         required=False,
363         max_length=255,
364         allow_null=True)
365     cpdId = serializers.CharField(
366         help_text="cpdId",
367         required=False,
368         max_length=255,
369         allow_null=True)
370     resourceId = serializers.CharField(
371         help_text="resourceId",
372         required=False,
373         max_length=255,
374         allow_null=True)
375     vim = VimInfoSerializer(
376         help_text="vim",
377         required=False,
378         allow_null=True)
379     extCps = ExtCpInfoSerializer(
380         help_text="extCps",
381         many=True,
382         required=False,
383         allow_null=True)
384
385
386 class AdditionalParamsSerializer(serializers.Serializer):
387     vimId = serializers.CharField(
388         help_text="vimId",
389         required=False,
390         max_length=255,
391         allow_null=True)
392     inputs = serializers.DictField(
393         help_text="inputs",
394         child=serializers.CharField(help_text="custom key-value", allow_blank=True),
395         required=False,
396         allow_null=True)
397     extVirtualLinks = serializers.ListSerializer(
398         help_text="extVirtualLinks",
399         child=ExtVirtualLinkSerizlizer(help_text="extVirtualLinks", required=False, allow_null=True),
400         required=False,
401         allow_null=True)
402
403
404 class InstantiateVnfRequestSerializer(serializers.Serializer):
405     flavourId = serializers.CharField(
406         help_text="flavourId",
407         required=True,
408         max_length=255,
409         allow_null=True)
410     instantiationLevelId = serializers.CharField(
411         help_text="instantiationLevelId",
412         required=True,
413         max_length=255,
414         allow_null=True)
415     localizationLanguage = serializers.CharField(
416         help_text="localizationLanguage",
417         required=True,
418         max_length=255,
419         allow_null=True)
420     vnfmId = serializers.CharField(
421         help_text="vnfmId",
422         required=False,
423         max_length=255,
424         allow_null=True)
425     extVirtualLinks = serializers.ListSerializer(
426         help_text="extVirtualLinks",
427         child=ExtVirtualLinkSerizlizer(help_text="extVirtualLinks", required=False, allow_null=True),
428         required=False,
429         allow_null=True)
430     additionalParams = AdditionalParamsSerializer(
431         help_text="additionalParams",
432         required=False,
433         allow_null=True)
434
435
436 class InstOrTeriVnfResponseSerializer(serializers.Serializer):
437     jobId = serializers.CharField(
438         help_text="jobId",
439         required=True,
440         max_length=255,
441         allow_null=True)
442
443
444 class TerminateVnfRequestSerializer(serializers.Serializer):
445     terminationType = serializers.CharField(
446         help_text="terminationType",
447         required=True,
448         max_length=255,
449         allow_null=True)
450     gracefulTerminationTimeout = serializers.IntegerField(
451         help_text="gracefulTerminationTimeout",
452         default=120,
453         required=False)
454
455
456 class VimInfoSerializer(serializers.Serializer):
457     id = serializers.CharField(
458         help_text="The identifier of the VIM Connection. This identifier is managed by the NFVO.",
459         required=False,
460         max_length=255,
461         allow_null=True)
462     vimId = serializers.CharField(
463         help_text="The identifier of the VIM instance. This identifier is managed by the NFVO.",
464         required=False,
465         max_length=255,
466         allow_null=True)
467     vimType = serializers.CharField(
468         help_text="Discriminator for the different types of the VIM information.",
469         required=False,
470         max_length=255,
471         allow_null=True)
472     interfaceInfo = serializers.DictField(
473         help_text="Information about the interface or interfaces to the VIM",
474         child=serializers.CharField(allow_blank=True),
475         required=False,
476         allow_null=True)
477     accessInfo = serializers.DictField(
478         help_text="Authentication credentials for accessing the VIM, and other access-related information",
479         child=serializers.CharField(allow_blank=True),
480         required=False,
481         allow_null=True)
482     extra = serializers.DictField(
483         help_text="VIM type specific additional information.",
484         child=serializers.CharField(allow_blank=True),
485         required=False,
486         allow_null=True)
487
488
489 class ScaleInfoSerializer(serializers.Serializer):
490     aspectId = serializers.CharField(
491         help_text="Identifier of the scaling aspect.",
492         required=True,
493         max_length=255,
494         allow_null=True)
495     scaleLevel = serializers.IntegerField(
496         help_text="Indicates the scale level.",
497         required=True)
498
499
500 class CpProtocolInfoSerializer(serializers.Serializer):
501     layerProtocol = serializers.ChoiceField(
502         help_text="The identifier of layer(s) and protocol(s) associated to the network address information.",
503         choices=["IP_OVER_ETHERNET"],
504         required=False,
505         allow_null=True)
506     ipOverEthernet = serializers.DictField(
507         help_text="IP addresses over Ethernet to assign to the extCP instance.",
508         child=serializers.CharField(allow_blank=True),
509         required=False,
510         allow_null=True)
511
512
513 class ExtCpInfoSerializer(serializers.Serializer):
514     id = serializers.CharField(
515         help_text="Identifier of the external CP instance and the related information instance.",
516         required=False,
517         max_length=255,
518         allow_null=True)
519     cpdId = serializers.CharField(
520         help_text="Identifier of the external CPD, VnfExtCpd, in the VNFD.",
521         required=True,
522         max_length=255,
523         allow_null=True)
524     cpProtocolInfo = CpProtocolInfoSerializer(
525         help_text="Network protocol information for this CP.",
526         required=False,
527         allow_null=True)
528     extLinkPortId = serializers.CharField(
529         help_text="Identifier of the 'extLinkPortInfo' structure inside the 'extVirtualLinkInfo' structure.",
530         required=False,
531         max_length=255,
532         allow_null=True)
533
534
535 class instantiatedVnfInfoSerializer(serializers.Serializer):
536     flavourId = serializers.CharField(
537         help_text="Identifier of the VNF deployment flavour applied to this VNF instance.",
538         required=True,
539         max_length=255,
540         allow_null=True)
541     vnfState = serializers.ChoiceField(
542         help_text="State of the VNF instance.",
543         choices=["STARTED", "STOPPED"],
544         required=True,
545         allow_null=True)
546     scaleStatus = ScaleInfoSerializer(
547         help_text="Scale status of the VNF, one entry per aspect.",
548         required=False,
549         many=True)
550     extCpInfo = ExtCpInfoSerializer(
551         help_text="Information about the external CPs exposed by the VNF instance.",
552         required=False,
553         many=True)
554
555
556 class VnfInstanceSerializer(serializers.Serializer):
557     id = serializers.CharField(
558         help_text="Identifier of the VNF instance",
559         required=True)
560     vnfInstanceName = serializers.CharField(
561         help_text="Name of the VNF instance.",
562         required=False,
563         allow_null=True,
564         allow_blank=True)
565     vnfInstanceDescription = serializers.CharField(
566         help_text="Human-readable description of the VNF instance.",
567         required=False,
568         allow_null=True,
569         allow_blank=True)
570     vnfdId = serializers.CharField(
571         help_text="Identifier of the VNFD on which the VNF instance is based.",
572         required=False,
573         allow_null=True,
574         allow_blank=True)
575     vnfProvider = serializers.CharField(
576         help_text="Provider of the VNF and the VNFD. The value is copied from the VNFD.",
577         required=False,
578         allow_null=True,
579         allow_blank=True)
580     vnfProductName = serializers.CharField(
581         help_text="Name to identify the VNF Product. The value is copied from the VNFD.",
582         required=False,
583         allow_null=True,
584         allow_blank=True)
585     vnfSoftwareVersion = serializers.CharField(
586         help_text="Software version of the VNF. The value is copied from the VNFD.",
587         required=False,
588         allow_null=True,
589         allow_blank=True)
590     vnfdVersion = serializers.CharField(
591         help_text="Identifies the version of the VNFD. The value is copied from the VNFD.",
592         required=False,
593         allow_null=True,
594         allow_blank=True)
595     vnfPkgId = serializers.CharField(
596         help_text="Identifier of information held by the NFVO about the specific VNF package on which the VNF is based.",
597         required=False,
598         allow_null=True,
599         allow_blank=True)
600     vnfConfigurableProperties = serializers.DictField(
601         help_text="Current values of the configurable properties of the VNF instance.",
602         child=serializers.CharField(allow_blank=True),
603         required=False,
604         allow_null=True)
605     vimConnectionInfo = VimInfoSerializer(
606         help_text="Information about VIM connections to be used for managing the resources for the VNF instance.",
607         required=False,
608         allow_null=True)
609     instantiationState = serializers.ChoiceField(
610         help_text="The instantiation state of the VNF.",
611         choices=["NOT_INSTANTIATED", "INSTANTIATED"],
612         required=False,
613         allow_null=True)
614     instantiatedVnfInfo = instantiatedVnfInfoSerializer(
615         help_text="Information specific to an instantiated VNF instance.",
616         required=False)