1 # Copyright 2018 ZTE Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 from driver.interfaces.serializers.link import LinkSerializer
16 from driver.interfaces.serializers.resource_handle import ResourceHandleSerializer
18 from rest_framework import serializers
21 class ResourceDefinitionSerializer(serializers.Serializer):
22 id = serializers.CharField(
23 help_text="Identifier of this ResourceDefinition, unique at least within the scope of the GrantRequest.",
26 type = serializers.ChoiceField(
27 help_text="Type of the resource definition referenced.",
28 choices=["COMPUTE", "VL", "STORAGE", "LINKPORT"],
31 vduId = serializers.CharField(
32 help_text="Reference to the related VDU in the VNFD applicable to this resource.",
37 resourceTemplateId = serializers.CharField(
38 help_text="Reference to a resource template(such as VnfVirtualLinkDesc) in the VNFD.",
43 resource = ResourceHandleSerializer(
44 help_text="Resource information for an existing resource.",
50 class ConstraintResourceRefSerializer(serializers.Serializer):
51 idType = serializers.ChoiceField(
52 help_text="The type of the identifier.",
53 choices=["RES_MGMT", "GRANT"],
56 resourceId = serializers.CharField(
57 help_text="An actual resource-management-level identifier(idType=RES_MGMT), or an identifier that references a ResourceDefinition(idType=GRANT).",
60 vimConnectionId = serializers.CharField(
66 resourceProviderId = serializers.CharField(
67 help_text="Identifier of the resource provider. It shall only be present when idType = RES_MGMT.",
74 class PlacementConstraintSerializer(serializers.Serializer):
75 affinityOrAntiAffinity = serializers.ChoiceField(
76 help_text="The type of the constraint.",
77 choices=["AFFINITY", "ANTI_AFFINITY"],
80 scope = serializers.ChoiceField(
81 help_text="The scope of the placement constraint indicating the category of the place where the constraint applies.",
82 choices=["NFVI_POP", "ZONE", "ZONE_GROUP", "NFVI_NODE"],
85 resource = ConstraintResourceRefSerializer(
86 help_text="References to resources in the constraint rule.",
92 class VimConstraintSerializer(serializers.Serializer):
93 sameResourceGroup = serializers.BooleanField(
94 help_text="Set to true when the constraint applies not only to the same VIM connection, but also to the same infrastructure resource group.",
97 resource = ConstraintResourceRefSerializer(
98 help_text="References to resources in the constraint rule.",
104 class GrantRequestLinksSerializer(serializers.Serializer):
105 vnfLcmOpOcc = LinkSerializer(
106 help_text="Related VNF lifecycle management operation occurrence.",
109 vnfInstance = LinkSerializer(
110 help_text="Related VNF instance.",
115 class GrantRequestSerializer(serializers.Serializer):
116 vnfInstanceId = serializers.CharField(
117 help_text="Identifier of the VNF instance which this grant request is related to.",
120 vnfLcmOpOccId = serializers.CharField(
121 help_text="The identifier of the VNF lifecycle management operation occurrence associated to the GrantRequest.",
122 required=False, # TODO required
126 vnfdId = serializers.CharField(
127 help_text="Identifier of the VNFD that defines the VNF for which the LCM operation is to be granted.",
128 required=False, # TODO required
132 flavourId = serializers.CharField(
133 help_text="Identifier of the VNF deployment flavour of the VNFD that defines the VNF for which the LCM operation is to be granted.",
138 operation = serializers.ChoiceField(
139 help_text="The lifecycle management operation for which granting is requested.",
140 choices=["INSTANTIATE", "SCALE", "SCALE_TO_LEVEL", "CHANGE_FLAVOUR", "TERMINATE", "HEAL", "OPERATE", "CHANGE_EXT_CONN", "MODIFY_INFO"],
143 isAutomaticInvocation = serializers.BooleanField(
144 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.",
147 instantiationLevelId = serializers.CharField(
148 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.",
153 addResources = ResourceDefinitionSerializer(
154 help_text="List of resource definitions in the VNFD for resources to be added by the LCM operation.",
158 tempResources = ResourceDefinitionSerializer(
159 help_text="List of resource definitions in the VNFD for resources to be temporarily instantiated during the runtime of the LCM operation.",
163 removeResources = ResourceDefinitionSerializer(
164 help_text="Provides the definitions of resources to be removed by the LCM operation.",
168 updateResources = ResourceDefinitionSerializer(
169 help_text="Provides the definitions of resources to be modified by the LCM operation.",
173 placementConstraints = PlacementConstraintSerializer(
174 help_text="Placement constraints that the VNFM may send to the NFVO in order to influence the resource placement decision.",
178 vimConstraints = VimConstraintSerializer(
179 help_text="Used by the VNFM to require that multiple resources are managed through the same VIM connection.",
183 additionalParams = serializers.DictField(
184 help_text="Additional parameters passed by the VNFM.",
185 child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
189 _links = GrantRequestLinksSerializer(
190 help_text="Links to resources related to this request.",
191 required=False # TODO required