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