Align gvnfmdriver grant with SOL003
[vfc/nfvo/driver/vnfm/gvnfm.git] / gvnfmadapter / driver / interfaces / serializers / grant_request.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 driver.interfaces.serializers.link import LinkSerializer
16 from driver.interfaces.serializers.resource_handle import ResourceHandleSerializer
17
18 from rest_framework import serializers
19
20
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.",
24         required=True
25     )
26     type = serializers.ChoiceField(
27         help_text="Type of the resource definition referenced.",
28         choices=["COMPUTE", "VL", "STORAGE", "LINKPORT"],
29         required=True
30     )
31     vduId = serializers.CharField(
32         help_text="Reference to the related VDU in the VNFD applicable to this resource.",
33         required=False,
34         allow_null=True,
35         allow_blank=True
36     )
37     resourceTemplateId = serializers.CharField(
38         help_text="Reference to a resource template(such as VnfVirtualLinkDesc) in the VNFD.",
39         required=False,
40         allow_null=True,
41         allow_blank=True
42     )
43     resource = ResourceHandleSerializer(
44         help_text="Resource information for an existing resource.",
45         required=False,
46         allow_null=True
47     )
48
49
50 class ConstraintResourceRefSerializer(serializers.Serializer):
51     idType = serializers.ChoiceField(
52         help_text="The type of the identifier.",
53         choices=["RES_MGMT", "GRANT"],
54         required=True
55     )
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).",
58         required=True
59     )
60     vimConnectionId = serializers.CharField(
61         help_text="",
62         required=False,
63         allow_null=True,
64         allow_blank=True
65     )
66     resourceProviderId = serializers.CharField(
67         help_text="Identifier of the resource provider. It shall only be present when idType = RES_MGMT.",
68         required=False,
69         allow_null=True,
70         allow_blank=True
71     )
72
73
74 class PlacementConstraintSerializer(serializers.Serializer):
75     affinityOrAntiAffinity = serializers.ChoiceField(
76         help_text="The type of the constraint.",
77         choices=["AFFINITY", "ANTI_AFFINITY"],
78         required=True
79     )
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"],
83         required=True
84     )
85     resource = ConstraintResourceRefSerializer(
86         help_text="References to resources in the constraint rule.",
87         many=True,
88         required=False
89     )
90
91
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.",
95         required=False
96     )
97     resource = ConstraintResourceRefSerializer(
98         help_text="References to resources in the constraint rule.",
99         many=True,
100         required=False
101     )
102
103
104 class GrantRequestLinksSerializer(serializers.Serializer):
105     vnfLcmOpOcc = LinkSerializer(
106         help_text="Related VNF lifecycle management operation occurrence.",
107         required=True
108     )
109     vnfInstance = LinkSerializer(
110         help_text="Related VNF instance.",
111         required=True
112     )
113
114
115 class GrantRequestSerializer(serializers.Serializer):
116     vnfInstanceId = serializers.CharField(
117         help_text="Identifier of the VNF instance which this grant request is related to.",
118         required=True
119     )
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
123         allow_null=True,
124         allow_blank=True
125     )
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
129         allow_null=True,
130         allow_blank=True
131     )
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.",
134         required=False,
135         allow_null=True,
136         allow_blank=True
137     )
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"],
141         required=True
142     )
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.",
145         required=True
146     )
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.",
149         required=False,
150         allow_null=True,
151         allow_blank=True
152     )
153     addResources = ResourceDefinitionSerializer(
154         help_text="List of resource definitions in the VNFD for resources to be added by the LCM operation.",
155         many=True,
156         required=False
157     )
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.",
160         many=True,
161         required=False
162     )
163     removeResources = ResourceDefinitionSerializer(
164         help_text="Provides the definitions of resources to be removed by the LCM operation.",
165         many=True,
166         required=False
167     )
168     updateResources = ResourceDefinitionSerializer(
169         help_text="Provides the definitions of resources to be modified by the LCM operation.",
170         many=True,
171         required=False
172     )
173     placementConstraints = PlacementConstraintSerializer(
174         help_text="Placement constraints that the VNFM may send to the NFVO in order to influence the resource placement decision.",
175         many=True,
176         required=False
177     )
178     vimConstraints = VimConstraintSerializer(
179         help_text="Used by the VNFM to require that multiple resources are managed through the same VIM connection.",
180         many=True,
181         required=False
182     )
183     additionalParams = serializers.DictField(
184         help_text="Additional parameters passed by the VNFM.",
185         child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
186         required=False,
187         allow_null=True
188     )
189     _links = GrantRequestLinksSerializer(
190         help_text="Links to resources related to this request.",
191         required=False  # TODO required
192     )