Align grant request with SOL003.
[vfc/nfvo/driver/vnfm/gvnfm.git] / gvnfmadapter / driver / interfaces / serializers / 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 driver.interfaces.serializers.link import LinkSerializer
16 from driver.interfaces.serializers.resource_handle import ResourceHandleSerializer
17
18 from rest_framework import serializers
19
20 LCM_OPERATION_TYPES = [
21     "INSTANTIATE",
22     "SCALE",
23     "SCALE_TO_LEVEL",
24     "CHANGE_FLAVOUR",
25     "TERMINATE",
26     "HEAL",
27     "OPERATE",
28     "CHANGE_EXT_CONN",
29     "MODIFY_INFO"
30 ]
31
32
33 LCM_OPERATION_STATE_TYPES = [
34     "STARTING",
35     "PROCESSING",
36     "COMPLETED",
37     "FAILED_TEMP",
38     "FAILED",
39     "ROLLING_BACK",
40     "ROLLED_BACK"
41 ]
42
43
44 VNFCS_CHANGE_TYPES = [
45     "ADDED",
46     "REMOVED",
47     "MODIFIED",
48     "TEMPORARY"
49 ]
50
51
52 STORAGES_CHANGE_TYPES = [
53     "ADDED",
54     "REMOVED",
55     "MODIFIED",
56     "TEMPORARY"
57 ]
58
59
60 VLS_CHANGE_TYPES = [
61     "ADDED",
62     "REMOVED",
63     "MODIFIED",
64     "TEMPORARY",
65     "LINK_PORT_ADDED",
66     "LINK_PORT_REMOVED"
67 ]
68
69
70 class AdditionalParams(serializers.Serializer):
71     sdncontroller = serializers.CharField(help_text="sdncontroller", required=False)
72     NatIpRange = serializers.CharField(help_text="NatIpRange", required=False)
73     m6000_mng_ip = serializers.CharField(help_text="m6000_mng_ip", required=False)
74     externalPluginManageNetworkName = serializers.CharField(help_text="externalPluginManageNetworkName", required=False)
75     location = serializers.CharField(help_text="location", required=False)
76     externalManageNetworkName = serializers.CharField(help_text="externalManageNetworkName", required=False)
77     sfc_data_network = serializers.CharField(help_text="sfc_data_network", required=False)
78     externalDataNetworkName = serializers.CharField(help_text="externalDataNetworkName", required=False)
79     inputs = serializers.DictField(
80         help_text="inputs",
81         child=serializers.CharField(help_text="but i needed to test these 2 fields somehow", allow_blank=True),
82         required=False,
83         allow_null=True
84     )
85
86
87 class VnfInstReqParamsSerializer(serializers.Serializer):
88     vnfDescriptorId = serializers.CharField(
89         help_text="Identifier that identifies the VNFD which defines the VNF instance to be created.",
90         max_length=255,
91         required=True,
92         allow_null=True
93     )
94     vnfInstanceName = serializers.CharField(
95         help_text="Human-readable name of the VNF instance to be created.",
96         max_length=255,
97         required=True,
98         allow_null=False
99     )
100     vnfInstanceDescription = serializers.CharField(
101         help_text="Human-readable description of the VNF instance to be created.",
102         max_length=255,
103         required=False,
104         allow_null=True
105     )
106     additionalParam = AdditionalParams(
107         help_text="Additional input parameters for the instantiation process,"
108                   " specific to the VNF being instantiated.",
109         required=True
110     )
111
112
113 class ResponseSerializer(serializers.Serializer):
114     vnfInstanceId = serializers.CharField(help_text="VNF instance identifier.", required=True)
115     jobId = serializers.CharField(help_text="Job ID.", required=True)
116
117
118 class VnfTermReqSerializer(serializers.Serializer):
119     vnfInstanceId = serializers.CharField(
120         help_text="VNF instance identifier.",
121         max_length=255,
122         required=True,
123         allow_null=True
124     )
125
126
127 class VnfInfo(serializers.Serializer):
128     vnfInstanceId = serializers.CharField(help_text="VNF instance identifier.", required=True)
129     vnfStatus = serializers.CharField(help_text="The instantiation state of the VNF.", required=True)
130     version = serializers.CharField(help_text="Version of the VNF.", required=True)
131
132
133 class VnfQueryRespSerializer(serializers.Serializer):
134     vnfInfo = VnfInfo(
135         help_text="The information items about the selected VNF instance(s) that are returned.",
136         required=True
137     )
138
139
140 class ResponseDescriptor(serializers.Serializer):
141     status = serializers.CharField(help_text="status.", required=True)
142     responsehistorylist = serializers.CharField(help_text="History response messages.", required=True)
143     responseid = serializers.IntegerField(help_text="Response identifier.", required=True)
144     errorcode = serializers.CharField(help_text="Errorcode.", required=True)
145     progress = serializers.IntegerField(help_text="Progress.", required=True)
146     statusdescription = serializers.CharField(help_text="Status description.", required=True)
147
148
149 class OperationStatusInfo(serializers.Serializer):
150     responsedescriptor = ResponseDescriptor(help_text="Response descriptor.", required=True)
151     jobid = serializers.CharField(help_text="Job ID.", required=True)
152
153
154 class VnfOperRespSerializer(serializers.Serializer):
155     operationStatusInfo = OperationStatusInfo(
156         help_text="Operation Status.",
157         required=True
158     )
159
160
161 class VnfGrantReqSerializer(serializers.Serializer):
162     vnfmid = serializers.CharField(help_text="VNFM identifier.", required=True)
163     nfvoid = serializers.CharField(help_text="NFVO identifier.", required=True)
164     vimid = serializers.CharField(help_text="VIM identifier.", required=True)
165     exvimidlist = serializers.CharField(help_text="Extend VIM identifier list.", required=True)
166     tenant = serializers.CharField(help_text="Tenant name.", required=True)
167     vnfistanceid = serializers.CharField(help_text="VNF instance identifier.", required=True)
168     operationright = serializers.CharField(help_text="Operation right.", required=True)
169     vmlist = serializers.CharField(help_text="VM list.", required=True)
170
171
172 class VnfGrantRespSerializer(serializers.Serializer):
173     vimid = serializers.CharField(help_text="VIM identifier.", required=True)
174     tenant = serializers.CharField(help_text="Tenant name.", required=True)
175
176
177 class VnfNotifyReqSerializer(serializers.Serializer):
178     nfvoid = serializers.CharField(help_text="NFVO identifier.", required=True)
179     vnfmid = serializers.CharField(help_text="VNFM identifier.", required=True)
180     vimid = serializers.CharField(help_text="VIM identifier.", required=True)
181     timestamp = serializers.CharField(help_text="Timestamp.", required=True)
182     vnfistanceid = serializers.CharField(help_text="VNF instance identifier.", required=True)
183     eventtype = serializers.CharField(help_text="Event type.", required=True)
184     vmlist = serializers.CharField(help_text="VM list.", required=True)
185
186
187 class VimConnectionInfoSerializer(serializers.Serializer):
188     id = serializers.CharField(
189         help_text="The identifier of the VIM Connection. This identifier is managed by the NFVO.",
190         max_length=255,
191         required=True,
192         allow_null=False,
193         allow_blank=False)
194     vimId = serializers.CharField(
195         help_text="The identifier of the VIM instance. This identifier is managed by the NFVO.",
196         max_length=255,
197         required=False,
198         allow_null=True,
199         allow_blank=True)
200     vimType = serializers.CharField(
201         help_text="Discriminator for the different types of the VIM information.",
202         max_length=255,
203         required=True,
204         allow_null=False,
205         allow_blank=False)
206     interfaceInfo = serializers.DictField(
207         help_text="Information about the interface or interfaces to the VIM",
208         child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
209         required=False,
210         allow_null=True)
211     accessInfo = serializers.DictField(
212         help_text="Authentication credentials for accessing the VIM, and other access-related information",
213         child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
214         required=False,
215         allow_null=True)
216     extra = serializers.DictField(
217         help_text="VIM type specific additional information. \
218         The applicable structure, and whether or not this attribute is available, is dependent on the content of vimType.",
219         child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
220         required=False,
221         allow_null=True)
222
223
224 class ProblemDetailsSerializer(serializers.Serializer):
225     type = serializers.CharField(help_text="Type", required=False, allow_null=True)
226     title = serializers.CharField(help_text="Title", required=False, allow_null=True)
227     status = serializers.IntegerField(help_text="Status", required=True)
228     detail = serializers.CharField(help_text="Detail", required=True, allow_null=True)
229     instance = serializers.CharField(help_text="Instance", required=False, allow_null=True)
230     additional_details = serializers.ListField(
231         help_text="Any number of additional attributes, as defined in a " +
232         "specification or by an implementation.",
233         required=False,
234         allow_null=True)
235
236
237 class ExtlinkPortInfoSerializer(serializers.Serializer):
238     id = serializers.CharField(
239         help_text="Identifier of this link port as provided by the entity that has created the link port.",
240         max_length=255,
241         required=True,
242         allow_blank=False,
243         allow_null=False)
244     resourceHandle = ResourceHandleSerializer(
245         help_text="Reference to the virtualised resource realizing this link port.",
246         required=True,
247         allow_null=False)
248     id = serializers.CharField(
249         help_text="Identifier of the external CP of the VNF connected to this link port. \
250         There shall be at most one link port associated with any external connection point instance.",
251         max_length=255,
252         required=False,
253         allow_blank=True,
254         allow_null=True)
255
256
257 class ExtVirtualLinkInfoSerializer(serializers.Serializer):
258     id = serializers.CharField(
259         help_text="Identifier of the external VL and the related external VL information instance. \
260         The identifier is assigned by the NFV-MANO entity that manages this VL instance.",
261         required=True,
262         max_length=255,
263         allow_null=False,
264         allow_blank=False)
265     resourceHandle = ResourceHandleSerializer(
266         help_text="Reference to the resource realizing this VL.",
267         required=True,
268         allow_null=False)
269     extlinkPorts = ExtlinkPortInfoSerializer(
270         help_text="Link ports of this VL.",
271         many=True,
272         required=False,
273         allow_null=True)
274
275
276 class VnfInfoModificationsSerializer(serializers.Serializer):
277     vnfInstanceName = serializers.CharField(
278         help_text="If present, this attribute signals modifications of the " +
279         "'vnfInstanceName' attribute in 'VnfInstance'",
280         max_length=255,
281         required=False,
282         allow_null=True,
283         allow_blank=True)
284     vnfInstanceDescription = serializers.CharField(
285         help_text="If present, this attribute signals modifications of the " +
286         "'vnfInstanceDescription' attribute in 'VnfInstance'",
287         required=False,
288         allow_null=True,
289         allow_blank=True)
290     vnfdId = serializers.CharField(
291         help_text="If present, this attribute signals modifications of the " +
292         "'vnfdId' attribute in 'VnfInstance'",
293         max_length=255,
294         required=False,
295         allow_null=True,
296         allow_blank=True)
297     vnfProvider = serializers.CharField(
298         help_text="If present, this attribute signals modifications of the " +
299         "'vnfProvider'  attribute in 'VnfInstance'",
300         max_length=255,
301         required=False,
302         allow_null=True)
303     vnfProductName = serializers.CharField(
304         help_text="If present, this attribute signals modifications of the " +
305         "'vnfProductName' attribute in 'vnfInstance'",
306         max_length=255,
307         required=False,
308         allow_null=True,
309         allow_blank=True)
310     vnfSoftwareVersion = serializers.CharField(
311         help_text="If present, this attribute signals modifications of the " +
312         "'vnfSoftwareVersion' attribute in 'VnfInstance'.",
313         max_length=255,
314         required=False,
315         allow_null=True,
316         allow_blank=True)
317     vnfdVersion = serializers.CharField(
318         help_text="If present, this attribute signals modifications of the " +
319         "'vnfdVersion' attribute in 'VnfInstance'. ",
320         max_length=255,
321         required=False,
322         allow_null=True,
323         allow_blank=False)
324     vnfPkgId = serializers.CharField(
325         help_text="If present, this attribute signals modifications of the " +
326         "'vnfPkgId' attribute in 'VnfInstance'.",
327         max_length=255,
328         required=False,
329         allow_null=True,
330         allow_blank=False)
331     vnfConfigurableProperties = serializers.DictField(
332         help_text="If present, this attribute signals modifications of the " +
333         "'vnfConfigurableProperties'  attribute in 'VnfInstance'. ",
334         child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
335         required=False,
336         allow_null=True,)
337     vimConnectionInfo = VimConnectionInfoSerializer(
338         help_text="If present, this attribute signals modifications of certain" +
339         "entries in the 'vimConnectionInfo'",
340         required=False,
341         many=True,
342         allow_null=True)
343     metadata = serializers.DictField(
344         help_text="If present, this attribute signals modifications of certain" +
345         "'metadata' attribute in 'vnfInstance'.",
346         child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
347         required=False,
348         allow_null=True)
349     extensions = serializers.DictField(
350         help_text="If present, this attribute signals modifications of certain" +
351         "'extensions' attribute in 'vnfInstance'.",
352         child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
353         required=False,
354         allow_null=True)
355
356
357 class LcmOpLinkSerializer(serializers.Serializer):
358     self = LinkSerializer(
359         help_text="URI of this resource.",
360         required=True,
361         allow_null=False)
362     vnfInstance = serializers.CharField(
363         help_text="Link to the VNF instance that the operation applies to.",
364         required=True)
365     grant = serializers.CharField(
366         help_text="Link to the grant for this operation, if one exists.",
367         required=False)
368     cancel = serializers.CharField(
369         help_text="Link to the task resource that represents the 'cancel' " +
370         "operation for this VNF LCM operation occurrence.",
371         required=False)
372     retry = serializers.CharField(
373         help_text="Link to the task resource that represents the 'retry' " +
374         "operation for this VNF LCM operation occurrence, if" +
375         " retrying is currently allowed",
376         required=False)
377     rollback = serializers.CharField(
378         help_text="Link to the task resource that represents the 'cancel' " +
379         "operation for this VNF LCM operation occurrence.",
380         required=False)
381     fail = serializers.CharField(
382         help_text="Link to the task resource that represents the 'fail' " +
383         "operation for this VNF LCM operation occurrence.",
384         required=False)
385
386
387 class AffectedVnfcsSerializer(serializers.Serializer):
388     id = serializers.UUIDField(
389         help_text="Identifier of the Vnfc instance, identifying the " +
390         "applicable 'vnfcResourceInfo' entry in the 'VnfInstance' data type",
391         required=True
392     )
393     vduId = serializers.UUIDField(
394         help_text="Identifier of the related VDU in the VNFD.",
395         required=True
396     )
397     changeType = serializers.ChoiceField(
398         help_text="Signals the type of change",
399         required=True,
400         choices=VNFCS_CHANGE_TYPES
401     )
402     affectedVnfcCpIds = serializers.ListField(
403         help_text="Identifiers of CP(s) of the VNFC instance that " +
404         "were affected by the change",
405         required=False,
406         child=serializers.UUIDField(required=True)
407     )
408     addedStorageResourceIds = serializers.ListField(
409         help_text="References to VirtualStorage resources that " +
410         "have been added",
411         required=False,
412         child=serializers.UUIDField()
413     )
414     removedStorageResourceIds = serializers.ListField(
415         help_text="References to VirtualStorage resources that " +
416         "have been removed.",
417         required=False,
418         child=serializers.UUIDField()
419     )
420     metadata = serializers.DictField(
421         help_text="Metadata about this resource. ",
422         required=False,
423         allow_null=True)
424     computeResource = ResourceHandleSerializer(
425         help_text="Reference to the VirtualCompute resource.",
426         required=True,
427         allow_null=False)
428
429
430 class AffectedStoragesSerializer(serializers.Serializer):
431     id = serializers.UUIDField(
432         help_text="Identifier of the Storage instance, identifying the " +
433         "applicable 'virtualStorageResourceInfo' entry in the 'VnfInstance' data type",
434         required=True
435     )
436     virtualStorageDescId = serializers.UUIDField(
437         help_text="Identifier of the related VirtualStorage descriptor " +
438         "in the VNFD. ",
439         required=True
440     )
441     changeType = serializers.ChoiceField(
442         help_text="Signals the type of change",
443         required=True,
444         choices=STORAGES_CHANGE_TYPES
445     )
446     metadata = serializers.DictField(
447         help_text="Metadata about this resource. ",
448         required=False,
449         allow_null=True)
450     storageResource = ResourceHandleSerializer(
451         help_text="Reference to the VirtualStorage resource.",
452         required=True,
453         allow_null=False)
454
455
456 class AffectedVLsSerializer(serializers.Serializer):
457     id = serializers.UUIDField(
458         help_text="Identifier of the virtual link instance, identifying " +
459         "the applicable 'vnfVirtualLinkResourceInfo' ",
460         required=True
461     )
462     virtualLinkDescId = serializers.UUIDField(
463         help_text="Identifier of the related VLD in the VNFD.",
464         required=True
465     )
466     changeType = serializers.ChoiceField(
467         help_text="Signals the type of change",
468         required=True,
469         choices=VLS_CHANGE_TYPES
470     )
471     metadata = serializers.DictField(
472         help_text="Metadata about this resource. ",
473         required=False,
474         allow_null=True)
475     networkResource = ResourceHandleSerializer(
476         help_text="Reference to the VirtualNetwork resource.",
477         required=True,
478         allow_null=False)
479
480
481 class ResourceChangesSerializer(serializers.Serializer):
482     affectedVnfcs = AffectedVnfcsSerializer(
483         help_text="Information about VNFC instances that were affected " +
484         "during the lifecycle operation.",
485         required=False,
486         many=True
487     )
488     affectedVirtualLinks = AffectedVLsSerializer(
489         help_text="Information about VL instances that were affected " +
490         "during the lifecycle operation. ",
491         required=False,
492         many=True
493     )
494     affectedVirtualStorages = AffectedStoragesSerializer(
495         help_text="Information about virtualised storage instances that " +
496         "were affected during the lifecycle operation",
497         required=False,
498         many=True
499     )
500
501
502 class VNFLCMOpOccSerializer(serializers.Serializer):
503     id = serializers.CharField(
504         help_text="Identifier of this VNF lifecycle management operation" +
505         "occurrence,",
506         max_length=255,
507         required=True,
508         allow_null=False
509     )
510     operationState = serializers.ChoiceField(
511         help_text="The state of the VNF LCM operation occurrence. ",
512         required=True,
513         choices=LCM_OPERATION_STATE_TYPES
514     )
515     stateEnteredTime = serializers.CharField(
516         help_text="Date-time when the current state was entered.",
517         max_length=50
518     )
519     startTime = serializers.CharField(
520         help_text="Date-time of the start of the operation.",
521         max_length=50
522     )
523     vnfInstanceId = serializers.UUIDField(
524         help_text="Identifier of the VNF instance to which the operation" +
525         "applies"
526     )
527     grantId = serializers.UUIDField(
528         help_text="Identifier of the grant related to this VNF LCM operation " +
529                   "occurrence, if such grant exists.",
530         allow_null=True
531     )
532     operation = serializers.ChoiceField(
533         help_text="The lifecycle management operation",
534         required=True,
535         choices=LCM_OPERATION_TYPES
536     )
537     isAutomaticInvocation = serializers.BooleanField(
538         help_text="Set to true if this VNF LCM operation occurrence has " +
539         "been triggered by an automated procedure inside the VNFM. " +
540         "Set to False otherwise.",
541         default=False
542     )
543     operationParams = serializers.DictField(
544         help_text="Input parameters of the LCM operation. This attribute " +
545         "shall be formatted according to the request data type of the " +
546         "related LCM operation. The following mapping between operationType and the " +
547         "data type of this attribute shall apply: " +
548         "1. INSTANTIATE: InstantiateVnfRequest" +
549         "2. SCALE: ScaleVnfRequest " +
550         "3. SCALE_TO_LEVEL: ScaleVnfToLevelRequest " +
551         "4. CHANGE_FLAVOUR: ChangeVnfFlavourRequest " +
552         "5. OPERATE: OperateVnfRequest " +
553         "6. HEAL: HealVnfRequest " +
554         "7. CHANGE_EXT_CONN: ChangeExtVnfConnectivityRequest " +
555         "8. TERMINATE: TerminateVnfRequest " +
556         "9. MODIFY_INFO: VnfInfoModifications",
557         required=True,
558         allow_null=False
559     )
560     isCancelPending = serializers.BooleanField(
561         help_text="If the VNF LCM operation occurrence is in 'STARTING'" +
562         "'PROCESSING' or 'ROLLING_BACK' state and the operation is being" +
563         " cancelled, this attribute shall be set to True. Otherwise, " +
564         " it shall be set to False.",
565         required=True
566     )
567     cancelMode = serializers.CharField(
568         help_text="The mode of an ongoing cancellation. Shall be present " +
569         "when isCancelPending=true, and shall be None otherwise.",
570         allow_null=True,
571         required=False
572     )
573     error = ProblemDetailsSerializer(
574         help_text="If 'operationState' is 'FAILED_TEMP' or 'FAILED' or " +
575         "'PROCESSING' or 'ROLLING_BACK' and previous value of 'operationState' " +
576         "was 'FAILED_TEMP'  this attribute shall be present ",
577         allow_null=True,
578         required=False
579     )
580     resourceChanges = ResourceChangesSerializer(
581         help_text="It contains information about the cumulative changes " +
582         "to virtualised resources that were performed so far by the LCM " +
583         "operation since its start, if applicable.",
584         required=False,
585         allow_null=True)
586     changedInfo = VnfInfoModificationsSerializer(
587         help_text="Information about the changed VNF instance information, " +
588         "including VNF configurable properties",
589         required=False,
590         allow_null=True)
591     changedExtConnectivity = ExtVirtualLinkInfoSerializer(
592         help_text="Information about changed external connectivity, if this " +
593         "notification represents the result of a lifecycle operation occurrence. " +
594         "Shall be present if the 'notificationStatus' is set to 'RESULT' and the " +
595         "'operation' is set to 'CHANGE_EXT_CONN'. Shall be absent otherwise.",
596         many=True,
597         required=False,
598         allow_null=True)
599     _links = LcmOpLinkSerializer(
600         help_text="Links to resources related to this resource.",
601         required=True)