Add vnf Grant swagger generate logic
[vfc/nfvo/lcm.git] / lcm / v2 / 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 ResourceHandleSerializer(serializers.Serializer):
19     vimConnectionId = serializers.CharField(
20         help_text="Identifier of the VIM connection to manage the resource.",
21         required=False,
22         allow_null=True,
23         allow_blank=True
24     )
25     resourceProviderId = serializers.CharField(
26         help_text="Identifier of the entity responsible for the management of the resource.",
27         required=False,
28         allow_null=True,
29         allow_blank=True
30     )
31     resourceId = serializers.CharField(
32         help_text="Identifier of the resource in the scope of the VIM or the resource provider.",
33         required=True
34     )
35     vimLevelResourceType = serializers.CharField(
36         help_text="Type of the resource in the scope of the VIM or the resource provider.",
37         required=False,
38         allow_null=True,
39         allow_blank=True
40     )
41
42
43 class ResourceDefinitionSerializer(serializers.Serializer):
44     id = serializers.CharField(
45         help_text="Identifier of this ResourceDefinition, unique at least within the scope of the GrantRequest.",
46         required=True
47     )
48     type = serializers.ChoiceField(
49         help_text="Type of the resource definition referenced.",
50         choices=["COMPUTE", "VL", "STORAGE", "LINKPORT"],
51         required=True
52     )
53     vduId = serializers.CharField(
54         help_text="Reference to the related VDU in the VNFD applicable to this resource.",
55         required=False,
56         allow_null=True,
57         allow_blank=True
58     )
59     resourceTemplateId = serializers.CharField(
60         help_text="Reference to a resource template(such as VnfVirtualLinkDesc) in the VNFD.",
61         required=False,
62         allow_null=True,
63         allow_blank=True
64     )
65     resource = ResourceHandleSerializer(
66         help_text="Resource information for an existing resource.",
67         required=False,
68         allow_null=True
69     )
70
71
72 class ConstraintResourceRefSerializer(serializers.Serializer):
73     idType = serializers.ChoiceField(
74         help_text="The type of the identifier.",
75         choices=["RES_MGMT", "GRANT"],
76         required=True
77     )
78     resourceId = serializers.CharField(
79         help_text="An actual resource-management-level identifier(idType=RES_MGMT), or an identifier that references a ResourceDefinition(idType=GRANT).",
80         required=True
81     )
82     vimConnectionId = serializers.CharField(
83         help_text="",
84         required=False,
85         allow_null=True,
86         allow_blank=True
87     )
88     resourceProviderId = serializers.CharField(
89         help_text="Identifier of the resource provider. It shall only be present when idType = RES_MGMT.",
90         required=False,
91         allow_null=True,
92         allow_blank=True
93     )
94
95
96 class PlacementConstraintSerializer(serializers.Serializer):
97     affinityOrAntiAffinity = serializers.ChoiceField(
98         help_text="The type of the constraint.",
99         choices=["AFFINITY", "ANTI_AFFINITY"],
100         required=True
101     )
102     scope = serializers.ChoiceField(
103         help_text="The scope of the placement constraint indicating the category of the place where the constraint applies.",
104         choices=["NFVI_POP", "ZONE", "ZONE_GROUP", "NFVI_NODE"],
105         required=True
106     )
107     resource = ConstraintResourceRefSerializer(
108         help_text="References to resources in the constraint rule.",
109         many=True
110     )
111
112
113 class VimConstraintSerializer(serializers.Serializer):
114     sameResourceGroup = serializers.BooleanField(
115         help_text="Set to true when the constraint applies not only to the same VIM connection, but also to the same infrastructure resource group.",
116         required=False,
117         allow_null=True
118     )
119     resource = ConstraintResourceRefSerializer(
120         help_text="References to resources in the constraint rule.",
121         many=True
122     )
123
124
125 class LinkSerializer(serializers.Serializer):
126     href = serializers.CharField(
127         help_text="URI of the referenced resource.",
128         required=True
129     )
130
131
132 class GrantRequestLinksSerializer(serializers.Serializer):
133     vnfLcmOpOcc = LinkSerializer(
134         help_text="Related VNF lifecycle management operation occurrence.",
135         required=True
136     )
137     vnfInstance = LinkSerializer(
138         help_text="Related VNF instance.",
139         required=True
140     )
141
142
143 class GrantRequestSerializer(serializers.Serializer):
144     vnfInstanceId = serializers.CharField(
145         help_text="Identifier of the VNF instance which this grant request is related to.",
146         required=True
147     )
148     vnfLcmOpOccId = serializers.CharField(
149         help_text="The identifier of the VNF lifecycle management operation occurrence associated to the GrantRequest.",
150         required=False,
151         allow_null=True,
152         allow_blank=True
153     )
154     vnfdId = serializers.CharField(
155         help_text="Identifier of the VNFD that defines the VNF for which the LCM operation is to be granted.",
156         required=False,
157         allow_null=True,
158         allow_blank=True
159     )
160     flavourId = serializers.CharField(
161         help_text="Identifier of the VNF deployment flavour of the VNFD that defines the VNF for which the LCM operation is to be granted.",
162         required=False,
163         allow_null=True,
164         allow_blank=True
165     )
166     operation = serializers.ChoiceField(
167         help_text="The lifecycle management operation for which granting is requested.",
168         choices=["INSTANTIATE", "SCALE", "SCALE_TO_LEVEL", "CHANGE_FLAVOUR", "TERMINATE", "HEAL", "OPERATE", "OPERATE", "CHANGE_EXT_CONN", "MODIFY_INFO"],
169         required=True
170     )
171     isAutomaticInvocation = serializers.BooleanField(
172         help_text="Set to true if this VNF LCM operation occurrence has been triggered by an automated procedure inside the VNFM, set to false otherwise.",
173         required=True
174     )
175     instantiationLevelId = serializers.CharField(
176         help_text="If operation=INSTANTIATE, the identifier of the instantiation level may be provided as an alternative way to define the resources to be added.",
177         required=False,
178         allow_null=True,
179         allow_blank=True
180     )
181     addResources = ResourceDefinitionSerializer(
182         help_text="List of resource definitions in the VNFD for resources to be added by the LCM operation.",
183         many=True
184     )
185     tempResources = ResourceDefinitionSerializer(
186         help_text="List of resource definitions in the VNFD for resources to be temporarily instantiated during the runtime of the LCM operation.",
187         many=True
188     )
189     removeResources = ResourceDefinitionSerializer(
190         help_text="Provides the definitions of resources to be removed by the LCM operation.",
191         many=True
192     )
193     updateResources = ResourceDefinitionSerializer(
194         help_text="Provides the definitions of resources to be modified by the LCM operation.",
195         many=True
196     )
197     placementConstraints = PlacementConstraintSerializer(
198         help_text="Placement constraints that the VNFM may send to the NFVO in order to influence the resource placement decision.",
199         many=True
200     )
201     vimConstraints = VimConstraintSerializer(
202         help_text="Used by the VNFM to require that multiple resources are managed through the same VIM connection.",
203         many=True
204     )
205     additionalParams = serializers.DictField(
206         help_text="Additional parameters passed by the VNFM.",
207         child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
208         required=False,
209         allow_null=True
210     )
211     _links = GrantRequestLinksSerializer(
212         help_text="Links to resources related to this request.",
213         required=True
214     )
215
216
217 class VimConnectionInfoSerializer(serializers.Serializer):
218     id = serializers.CharField(
219         help_text="The identifier of the VIM Connection. This identifier is managed by the NFVO.",
220         required=True
221     )
222     vimId = serializers.CharField(
223         help_text="The identifier of the VIM instance. This identifier is managed by the NFVO.",
224         required=False,
225         allow_null=True,
226         allow_blank=True
227     )
228     vimType = serializers.CharField(
229         help_text="Discriminator for the different types of the VIM information.",
230         required=False,
231         allow_null=True,
232         allow_blank=True
233     )
234     interfaceInfo = serializers.DictField(
235         help_text="Information about the interface or interfaces to the VIM.",
236         child=serializers.CharField(help_text="Interface Info", allow_blank=True),
237         required=False,
238         allow_null=True
239     )
240     accessInfo = serializers.DictField(
241         help_text="Authentication credentials for accessing the VIM.",
242         child=serializers.CharField(help_text="Access Info", allow_blank=True),
243         required=False,
244         allow_null=True
245     )
246     extra = serializers.DictField(
247         help_text="VIM type specific additional information.",
248         child=serializers.CharField(help_text="Extra", allow_blank=True),
249         required=False,
250         allow_null=True
251     )
252
253
254 class ZoneInfoSerializer(serializers.Serializer):
255     id = serializers.CharField(
256         help_text="The identifier of this ZoneInfo instance, for the purpose of referencing it from other structures in the Grant structure.",
257         required=True
258     )
259     zoneId = serializers.CharField(
260         help_text="The identifier of the resource zone, as managed by the resource management layer(typically, the VIM).",
261         required=False,
262         allow_null=True,
263         allow_blank=True
264     )
265     vimConnectionId = serializers.CharField(
266         help_text="Identifier of the connection to the VIM that manages the resource zone.",
267         required=False,
268         allow_null=True,
269         allow_blank=True
270     )
271     resourceProviderId = serializers.CharField(
272         help_text="Identifies the entity responsible for the management the resource zone.",
273         required=False,
274         allow_null=True,
275         allow_blank=True
276     )
277
278
279 class ZoneGroupInfoSerializer(serializers.Serializer):
280     zoneId = serializers.ListSerializer(
281         help_text="References of identifiers of ZoneInfo structures.",
282         child=serializers.CharField(help_text="IdentifierLocal", allow_blank=True),
283         required=False,
284         allow_null=True
285     )
286
287
288 class GrantInfoSerializer(serializers.Serializer):
289     resourceDefinitionId = serializers.CharField(
290         help_text="Identifier of the related ResourceDefinition from the related GrantRequest.",
291         required=True
292     )
293     reservationId = serializers.CharField(
294         help_text="The reservation identifier applicable to the VNFC/VirtualLink/VirtualStorage.",
295         required=False,
296         allow_null=True,
297         allow_blank=True
298     )
299     vimConnectionId = serializers.CharField(
300         help_text="Identifier of the VIM connection to be used to manage this resource.",
301         required=False,
302         allow_null=True,
303         allow_blank=True
304     )
305     resourceProviderId = serializers.CharField(
306         help_text="Identifies the entity responsible for the management of the virtualised resource.",
307         required=False,
308         allow_null=True,
309         allow_blank=True
310     )
311     zoneId = serializers.CharField(
312         help_text="Reference to the identifier of the ZoneInfo in the Grant.",
313         required=False,
314         allow_null=True,
315         allow_blank=True
316     )
317     resourceGroupId = serializers.CharField(
318         help_text="Identifier of the infrastructure resource group.",
319         required=False,
320         allow_null=True,
321         allow_blank=True
322     )
323
324
325 class VimComputeResourceFlavourSerializer(serializers.Serializer):
326     vimConnectionId = serializers.CharField(
327         help_text="Identifier of the VIM connection to access the flavour referenced in this structure.",
328         required=False,
329         allow_null=True,
330         allow_blank=True
331     )
332     resourceProviderId = serializers.CharField(
333         help_text="Identifies the entity responsible for the management of the virtualised resource.",
334         required=False,
335         allow_null=True,
336         allow_blank=True
337     )
338     vnfdVirtualComputeDescId = serializers.CharField(
339         help_text="Identifier which references the virtual compute descriptor in the VNFD that maps to this flavour.",
340         required=False,
341         allow_null=True,
342         allow_blank=True
343     )
344     vimFlavourId = serializers.CharField(
345         help_text="Identifier of the compute resource flavour in the resource management layer (i.e. VIM).",
346         required=False,
347         allow_null=True,
348         allow_blank=True
349     )
350
351
352 class VimSoftwareImageSerializer(serializers.Serializer):
353     vimConnectionId = serializers.CharField(
354         help_text="Identifier of the VIM connection to access the flavour referenced in this structure.",
355         required=False,
356         allow_null=True,
357         allow_blank=True
358     )
359     resourceProviderId = serializers.CharField(
360         help_text="Identifies the entity responsible for the management of the virtualised resource.",
361         required=False,
362         allow_null=True,
363         allow_blank=True
364     )
365     vnfdSoftwareImageId = serializers.CharField(
366         help_text="Identifier which references the software image descriptor in the VNFD.",
367         required=False,
368         allow_null=True,
369         allow_blank=True
370     )
371     vimSoftwareImageId = serializers.CharField(
372         help_text="Identifier of the software image in the resource management layer (i.e. VIM).",
373         required=False,
374         allow_null=True,
375         allow_blank=True
376     )
377
378
379 class VimAssetsSerializer(serializers.Serializer):
380     computeResourceFlavours = VimComputeResourceFlavourSerializer(
381         help_text="Mappings between virtual compute descriptors defined in the VNFD and compute resource flavours managed in the VIM.",
382         many=True
383     )
384     softwareImages = VimSoftwareImageSerializer(
385         help_text="Mappings between software images defined in the VNFD and software images managed in the VIM.",
386         many=True
387     )
388
389
390 class AddressRangeSerializer(serializers.Serializer):
391     minAddress = serializers.CharField(
392         help_text="Lowest IP address belonging to the range.",
393         required=True
394     )
395     maxAddress = serializers.CharField(
396         help_text="Highest IP address belonging to the range.",
397         required=True
398     )
399
400
401 class IpAddresseSerializer(serializers.Serializer):
402     type = serializers.ChoiceField(
403         help_text="The type of the IP addresses.",
404         choices=["IPV4", "IPV6"],
405         required=True
406     )
407     fixedAddresses = serializers.ListSerializer(
408         help_text="Fixed addresses to assign.",
409         child=serializers.CharField(help_text="IpAddress"),
410         required=False,
411         allow_null=True
412     )
413     numDynamicAddresses = serializers.IntegerField(
414         help_text="Number of dynamic addresses to assign.",
415         required=True
416     )
417     addressRange = AddressRangeSerializer(
418         help_text="An IP address range to be used, e.g. in case of egress connections.",
419         required=False,
420         allow_null=True
421     )
422     subnetId = serializers.CharField(
423         help_text="Subnet defined by the identifier of the subnet resource in the VIM.",
424         required=False,
425         allow_null=True,
426         allow_blank=True
427     )
428
429
430 class IpOverEthernetAddressDataSerializer(serializers.Serializer):
431     macAddress = serializers.CharField(
432         help_text="MAC address.",
433         required=False,
434         allow_null=True,
435         allow_blank=True
436     )
437     ipAddresses = IpAddresseSerializer(
438         help_text="List of IP addresses to assign to the CP instance.",
439         many=True
440     )
441
442
443 class CpProtocolDataSerializer(serializers.Serializer):
444     layerProtocol = serializers.ChoiceField(
445         help_text="Identifier of layer(s) and protocol(s).",
446         choices=["IP_OVER_ETHERNET"],
447         required=True
448     )
449     ipOverEthernet = IpOverEthernetAddressDataSerializer(
450         help_text="Network address data for IP over Ethernet to assign to the extCP instance.",
451         required=False,
452         allow_null=True,
453     )
454
455
456 class VnfExtCpConfigSerializer(serializers.Serializer):
457     cpInstanceId = serializers.CharField(
458         help_text="Identifier of the external CP instance to which this set of configuration parameters is requested to be applied.",
459         required=False,
460         allow_null=True,
461         allow_blank=True
462     )
463     linkPortId = serializers.CharField(
464         help_text="Identifier of a pre-configured link port to which the external CP will be associated.",
465         required=False,
466         allow_null=True,
467         allow_blank=True
468     )
469     cpProtocolData = CpProtocolDataSerializer(
470         help_text="Parameters for configuring the network protocols on the link port that connects the CP to a VL.",
471         many=True
472     )
473
474
475 class VnfExtCpDataSerializer(serializers.Serializer):
476     cpdId = serializers.CharField(
477         help_text="The identifier of the CPD in the VNFD.",
478         required=True
479     )
480     cpConfig = VnfExtCpConfigSerializer(
481         help_text="List of instance data that need to be configured on the CP instances created from the respective CPD.",
482         many=True
483     )
484
485
486 class ExtLinkPortDataSerializer(serializers.Serializer):
487     id = serializers.CharField(
488         help_text="Identifier of this link port as provided by the entity that has created the link port.",
489         required=True
490     )
491     resourceHandle = serializers.CharField(
492         help_text="Reference to the virtualised resource realizing this link port.",
493         required=True
494     )
495
496
497 class ExtVirtualLinkDataSerializer(serializers.Serializer):
498     id = serializers.CharField(
499         help_text="The identifier of the external VL instance.",
500         required=True
501     )
502     vimConnectionId = serializers.CharField(
503         help_text="Identifier of the VIM connection to manage this resource.",
504         required=False,
505         allow_null=True,
506         allow_blank=True
507     )
508     resourceProviderId = serializers.CharField(
509         help_text="Identifies the entity responsible for the management of this resource.",
510         required=False,
511         allow_null=True,
512         allow_blank=True
513     )
514     resourceId = serializers.CharField(
515         help_text="The identifier of the resource in the scope of the VIM or the resource provider.",
516         required=True
517     )
518     extCps = VnfExtCpDataSerializer(
519         help_text="External CPs of the VNF to be connected to this external VL.",
520         many=True
521     )
522     extLinkPorts = ExtLinkPortDataSerializer(
523         help_text="Externally provided link ports to be used to connect external connection points to this external VL.",
524         many=True
525     )
526
527
528 class ExtManagedVirtualLinkDataSerializer(serializers.Serializer):
529     id = serializers.CharField(
530         help_text="The identifier of the externally-managed internal VL instance.",
531         required=True
532     )
533     virtualLinkDescId = serializers.CharField(
534         help_text="The identifier of the VLD in the VNFD for this VL.",
535         required=True
536     )
537     vimConnectionId = serializers.CharField(
538         help_text="Identifier of the VIM connection to manage this resource.",
539         required=False,
540         allow_null=True,
541         allow_blank=True
542     )
543     resourceProviderId = serializers.CharField(
544         help_text="Identifies the entity responsible for the management of this resource.",
545         required=False,
546         allow_null=True,
547         allow_blank=True
548     )
549     resourceId = serializers.CharField(
550         help_text="The identifier of the resource in the scope of the VIM or the resource provider.",
551         required=True
552     )
553
554
555 class GrantLinksSerializer(serializers.Serializer):
556     self = LinkSerializer(
557         help_text="URI of this resource.",
558         required=True
559     )
560     vnfLcmOpOcc = LinkSerializer(
561         help_text="Related VNF lifecycle management operation occurrence.",
562         required=True
563     )
564     vnfInstance = LinkSerializer(
565         help_text="Related VNF instance.",
566         required=True
567     )
568
569
570 class GrantSerializer(serializers.Serializer):
571     id = serializers.CharField(
572         help_text="Identifier of the grant.",
573         required=True
574     )
575     vnfInstanceId = serializers.CharField(
576         required=True
577     )
578     vnfLcmOpOccId = serializers.CharField(
579         help_text="Identifier of the related VNF lifecycle management operation occurrence.",
580         required=False,
581         allow_null=True,
582         allow_blank=True
583     )
584     vimConnections = VimConnectionInfoSerializer(
585         help_text="Provides information regarding VIM connections that are approved to be used by the VNFM to allocate resources.",
586         many=True
587     )
588     zones = ZoneInfoSerializer(
589         help_text="Identifies resource zones where the resources are approved to be allocated by the VNFM.",
590         many=True
591     )
592     zoneGroups = ZoneGroupInfoSerializer(
593         help_text="Information about groups of resource zones.",
594         many=True
595     )
596     computeReservationId = serializers.CharField(
597         help_text="Information that identifies a reservation applicable to the compute resource requirements.",
598         required=False,
599         allow_null=True,
600         allow_blank=True
601     )
602     networkReservationId = serializers.CharField(
603         help_text="Information that identifies a reservation applicable to the network resource requirements.",
604         required=False,
605         allow_null=True,
606         allow_blank=True
607     )
608     storageReservationId = serializers.CharField(
609         help_text="Information that identifies a reservation applicable to the storage resource requirements.",
610         required=False,
611         allow_null=True,
612         allow_blank=True
613     )
614     addResources = GrantInfoSerializer(
615         help_text="List of resources that are approved to be added.",
616         many=True
617     )
618     tempResources = GrantInfoSerializer(
619         help_text="List of resources that are approved to be temporarily instantiated during the runtime of the lifecycle operation.",
620         many=True
621     )
622     removeResources = GrantInfoSerializer(
623         help_text="List of resources that are approved to be removed.",
624         many=True
625     )
626     updateResources = GrantInfoSerializer(
627         help_text="List of resources that are approved to be modified.",
628         many=True
629     )
630     vimAssets = VimAssetsSerializer(
631         help_text="Information about assets for the VNF that are managed by the NFVO in the VIM.",
632         required=False,
633         allow_null=True
634     )
635     extVirtualLinks = ExtVirtualLinkDataSerializer(
636         help_text="Information about external VLs to connect the VNF to.",
637         many=True
638     )
639     extManagedVirtualLinks = ExtManagedVirtualLinkDataSerializer(
640         help_text="Information about internal VLs that are managed by other entities than the VNFM.",
641         many=True
642     )
643     _links = GrantLinksSerializer(
644         help_text="Links to resources related to this resource.",
645         required=True
646     )