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