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