summaryrefslogtreecommitdiffstats
path: root/gvnfmadapter/driver/interfaces/serializers/serializers.py
blob: b9de78aee75db4485fc64676f38f4d1ac40a92d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
# Copyright 2018 ZTE Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from driver.interfaces.serializers.link import LinkSerializer
from driver.interfaces.serializers.resource_handle import ResourceHandleSerializer
from driver.interfaces.serializers.problem_details import ProblemDetailsSerializer

from rest_framework import serializers

LCM_OPERATION_TYPES = [
    "INSTANTIATE",
    "SCALE",
    "SCALE_TO_LEVEL",
    "CHANGE_FLAVOUR",
    "TERMINATE",
    "HEAL",
    "OPERATE",
    "CHANGE_EXT_CONN",
    "MODIFY_INFO"
]


LCM_OPERATION_STATE_TYPES = [
    "STARTING",
    "PROCESSING",
    "COMPLETED",
    "FAILED_TEMP",
    "FAILED",
    "ROLLING_BACK",
    "ROLLED_BACK"
]


VNFCS_CHANGE_TYPES = [
    "ADDED",
    "REMOVED",
    "MODIFIED",
    "TEMPORARY"
]


STORAGES_CHANGE_TYPES = [
    "ADDED",
    "REMOVED",
    "MODIFIED",
    "TEMPORARY"
]


VLS_CHANGE_TYPES = [
    "ADDED",
    "REMOVED",
    "MODIFIED",
    "TEMPORARY",
    "LINK_PORT_ADDED",
    "LINK_PORT_REMOVED"
]


class AdditionalParams(serializers.Serializer):
    sdncontroller = serializers.CharField(help_text="sdncontroller", required=False)
    NatIpRange = serializers.CharField(help_text="NatIpRange", required=False)
    m6000_mng_ip = serializers.CharField(help_text="m6000_mng_ip", required=False)
    externalPluginManageNetworkName = serializers.CharField(help_text="externalPluginManageNetworkName", required=False)
    location = serializers.CharField(help_text="location", required=False)
    externalManageNetworkName = serializers.CharField(help_text="externalManageNetworkName", required=False)
    sfc_data_network = serializers.CharField(help_text="sfc_data_network", required=False)
    externalDataNetworkName = serializers.CharField(help_text="externalDataNetworkName", required=False)
    inputs = serializers.DictField(
        help_text="inputs",
        child=serializers.CharField(help_text="but i needed to test these 2 fields somehow", allow_blank=True),
        required=False,
        allow_null=True
    )


class VnfInstReqParamsSerializer(serializers.Serializer):
    vnfDescriptorId = serializers.CharField(
        help_text="Identifier that identifies the VNFD which defines the VNF instance to be created.",
        max_length=255,
        required=True,
        allow_null=True
    )
    vnfInstanceName = serializers.CharField(
        help_text="Human-readable name of the VNF instance to be created.",
        max_length=255,
        required=True,
        allow_null=False
    )
    vnfInstanceDescription = serializers.CharField(
        help_text="Human-readable description of the VNF instance to be created.",
        max_length=255,
        required=False,
        allow_null=True
    )
    additionalParam = AdditionalParams(
        help_text="Additional input parameters for the instantiation process,"
                  " specific to the VNF being instantiated.",
        required=True
    )


class ResponseSerializer(serializers.Serializer):
    vnfInstanceId = serializers.CharField(help_text="VNF instance identifier.", required=True)
    jobId = serializers.CharField(help_text="Job ID.", required=True)


class VnfTermReqSerializer(serializers.Serializer):
    vnfInstanceId = serializers.CharField(
        help_text="VNF instance identifier.",
        max_length=255,
        required=True,
        allow_null=True
    )


class VnfInfo(serializers.Serializer):
    vnfInstanceId = serializers.CharField(help_text="VNF instance identifier.", required=True)
    vnfStatus = serializers.CharField(help_text="The instantiation state of the VNF.", required=True)
    version = serializers.CharField(help_text="Version of the VNF.", required=True)


class VnfQueryRespSerializer(serializers.Serializer):
    vnfInfo = VnfInfo(
        help_text="The information items about the selected VNF instance(s) that are returned.",
        required=True
    )


class ResponseDescriptor(serializers.Serializer):
    status = serializers.CharField(help_text="status.", required=True)
    responsehistorylist = serializers.CharField(help_text="History response messages.", required=True)
    responseid = serializers.IntegerField(help_text="Response identifier.", required=True)
    errorcode = serializers.CharField(help_text="Errorcode.", required=True)
    progress = serializers.IntegerField(help_text="Progress.", required=True)
    statusdescription = serializers.CharField(help_text="Status description.", required=True)


class OperationStatusInfo(serializers.Serializer):
    responsedescriptor = ResponseDescriptor(help_text="Response descriptor.", required=True)
    jobid = serializers.CharField(help_text="Job ID.", required=True)


class VnfOperRespSerializer(serializers.Serializer):
    operationStatusInfo = OperationStatusInfo(
        help_text="Operation Status.",
        required=True
    )


class VnfGrantReqSerializer(serializers.Serializer):
    vnfmid = serializers.CharField(help_text="VNFM identifier.", required=True)
    nfvoid = serializers.CharField(help_text="NFVO identifier.", required=True)
    vimid = serializers.CharField(help_text="VIM identifier.", required=True)
    exvimidlist = serializers.CharField(help_text="Extend VIM identifier list.", required=True)
    tenant = serializers.CharField(help_text="Tenant name.", required=True)
    vnfistanceid = serializers.CharField(help_text="VNF instance identifier.", required=True)
    operationright = serializers.CharField(help_text="Operation right.", required=True)
    vmlist = serializers.CharField(help_text="VM list.", required=True)


class VnfGrantRespSerializer(serializers.Serializer):
    vimid = serializers.CharField(help_text="VIM identifier.", required=True)
    tenant = serializers.CharField(help_text="Tenant name.", required=True)


class VnfNotifyReqSerializer(serializers.Serializer):
    nfvoid = serializers.CharField(help_text="NFVO identifier.", required=True)
    vnfmid = serializers.CharField(help_text="VNFM identifier.", required=True)
    vimid = serializers.CharField(help_text="VIM identifier.", required=True)
    timestamp = serializers.CharField(help_text="Timestamp.", required=True)
    vnfistanceid = serializers.CharField(help_text="VNF instance identifier.", required=True)
    eventtype = serializers.CharField(help_text="Event type.", required=True)
    vmlist = serializers.CharField(help_text="VM list.", required=True)


class VimConnectionInfoSerializer(serializers.Serializer):
    id = serializers.CharField(
        help_text="The identifier of the VIM Connection. This identifier is managed by the NFVO.",
        max_length=255,
        required=True,
        allow_null=False,
        allow_blank=False)
    vimId = serializers.CharField(
        help_text="The identifier of the VIM instance. This identifier is managed by the NFVO.",
        max_length=255,
        required=False,
        allow_null=True,
        allow_blank=True)
    vimType = serializers.CharField(
        help_text="Discriminator for the different types of the VIM information.",
        max_length=255,
        required=True,
        allow_null=False,
        allow_blank=False)
    interfaceInfo = serializers.DictField(
        help_text="Information about the interface or interfaces to the VIM",
        child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
        required=False,
        allow_null=True)
    accessInfo = serializers.DictField(
        help_text="Authentication credentials for accessing the VIM, and other access-related information",
        child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
        required=False,
        allow_null=True)
    extra = serializers.DictField(
        help_text="VIM type specific additional information. \
        The applicable structure, and whether or not this attribute is available, is dependent on the content of vimType.",
        child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
        required=False,
        allow_null=True)


class ExtlinkPortInfoSerializer(serializers.Serializer):
    id = serializers.CharField(
        help_text="Identifier of this link port as provided by the entity that has created the link port.",
        max_length=255,
        required=True,
        allow_blank=False,
        allow_null=False)
    resourceHandle = ResourceHandleSerializer(
        help_text="Reference to the virtualised resource realizing this link port.",
        required=True,
        allow_null=False)
    id = serializers.CharField(
        help_text="Identifier of the external CP of the VNF connected to this link port. \
        There shall be at most one link port associated with any external connection point instance.",
        max_length=255,
        required=False,
        allow_blank=True,
        allow_null=True)


class ExtVirtualLinkInfoSerializer(serializers.Serializer):
    id = serializers.CharField(
        help_text="Identifier of the external VL and the related external VL information instance. \
        The identifier is assigned by the NFV-MANO entity that manages this VL instance.",
        required=True,
        max_length=255,
        allow_null=False,
        allow_blank=False)
    resourceHandle = ResourceHandleSerializer(
        help_text="Reference to the resource realizing this VL.",
        required=True,
        allow_null=False)
    extlinkPorts = ExtlinkPortInfoSerializer(
        help_text="Link ports of this VL.",
        many=True,
        required=False,
        allow_null=True)


class VnfInfoModificationsSerializer(serializers.Serializer):
    vnfInstanceName = serializers.CharField(
        help_text="If present, this attribute signals modifications of the " +
        "'vnfInstanceName' attribute in 'VnfInstance'",
        max_length=255,
        required=False,
        allow_null=True,
        allow_blank=True)
    vnfInstanceDescription = serializers.CharField(
        help_text="If present, this attribute signals modifications of the " +
        "'vnfInstanceDescription' attribute in 'VnfInstance'",
        required=False,
        allow_null=True,
        allow_blank=True)
    vnfdId = serializers.CharField(
        help_text="If present, this attribute signals modifications of the " +
        "'vnfdId' attribute in 'VnfInstance'",
        max_length=255,
        required=False,
        allow_null=True,
        allow_blank=True)
    vnfProvider = serializers.CharField(
        help_text="If present, this attribute signals modifications of the " +
        "'vnfProvider'  attribute in 'VnfInstance'",
        max_length=255,
        required=False,
        allow_null=True)
    vnfProductName = serializers.CharField(
        help_text="If present, this attribute signals modifications of the " +
        "'vnfProductName' attribute in 'vnfInstance'",
        max_length=255,
        required=False,
        allow_null=True,
        allow_blank=True)
    vnfSoftwareVersion = serializers.CharField(
        help_text="If present, this attribute signals modifications of the " +
        "'vnfSoftwareVersion' attribute in 'VnfInstance'.",
        max_length=255,
        required=False,
        allow_null=True,
        allow_blank=True)
    vnfdVersion = serializers.CharField(
        help_text="If present, this attribute signals modifications of the " +
        "'vnfdVersion' attribute in 'VnfInstance'. ",
        max_length=255,
        required=False,
        allow_null=True,
        allow_blank=False)
    vnfPkgId = serializers.CharField(
        help_text="If present, this attribute signals modifications of the " +
        "'vnfPkgId' attribute in 'VnfInstance'.",
        max_length=255,
        required=False,
        allow_null=True,
        allow_blank=False)
    vnfConfigurableProperties = serializers.DictField(
        help_text="If present, this attribute signals modifications of the " +
        "'vnfConfigurableProperties'  attribute in 'VnfInstance'. ",
        child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
        required=False,
        allow_null=True,)
    vimConnectionInfo = VimConnectionInfoSerializer(
        help_text="If present, this attribute signals modifications of certain" +
        "entries in the 'vimConnectionInfo'",
        required=False,
        many=True,
        allow_null=True)
    metadata = serializers.DictField(
        help_text="If present, this attribute signals modifications of certain" +
        "'metadata' attribute in 'vnfInstance'.",
        child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
        required=False,
        allow_null=True)
    extensions = serializers.DictField(
        help_text="If present, this attribute signals modifications of certain" +
        "'extensions' attribute in 'vnfInstance'.",
        child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
        required=False,
        allow_null=True)


class LcmOpLinkSerializer(serializers.Serializer):
    self = LinkSerializer(
        help_text="URI of this resource.",
        required=True,
        allow_null=False)
    vnfInstance = serializers.CharField(
        help_text="Link to the VNF instance that the operation applies to.",
        required=True)
    grant = serializers.CharField(
        help_text="Link to the grant for this operation, if one exists.",
        required=False)
    cancel = serializers.CharField(
        help_text="Link to the task resource that represents the 'cancel' " +
        "operation for this VNF LCM operation occurrence.",
        required=False)
    retry = serializers.CharField(
        help_text="Link to the task resource that represents the 'retry' " +
        "operation for this VNF LCM operation occurrence, if" +
        " retrying is currently allowed",
        required=False)
    rollback = serializers.CharField(
        help_text="Link to the task resource that represents the 'cancel' " +
        "operation for this VNF LCM operation occurrence.",
        required=False)
    fail = serializers.CharField(
        help_text="Link to the task resource that represents the 'fail' " +
        "operation for this VNF LCM operation occurrence.",
        required=False)


class AffectedVnfcsSerializer(serializers.Serializer):
    id = serializers.UUIDField(
        help_text="Identifier of the Vnfc instance, identifying the " +
        "applicable 'vnfcResourceInfo' entry in the 'VnfInstance' data type",
        required=True
    )
    vduId = serializers.UUIDField(
        help_text="Identifier of the related VDU in the VNFD.",
        required=True
    )
    changeType = serializers.ChoiceField(
        help_text="Signals the type of change",
        required=True,
        choices=VNFCS_CHANGE_TYPES
    )
    affectedVnfcCpIds = serializers.ListField(
        help_text="Identifiers of CP(s) of the VNFC instance that " +
        "were affected by the change",
        required=False,
        child=serializers.UUIDField(required=True)
    )
    addedStorageResourceIds = serializers.ListField(
        help_text="References to VirtualStorage resources that " +
        "have been added",
        required=False,
        child=serializers.UUIDField()
    )
    removedStorageResourceIds = serializers.ListField(
        help_text="References to VirtualStorage resources that " +
        "have been removed.",
        required=False,
        child=serializers.UUIDField()
    )
    metadata = serializers.DictField(
        help_text="Metadata about this resource. ",
        required=False,
        allow_null=True)
    computeResource = ResourceHandleSerializer(
        help_text="Reference to the VirtualCompute resource.",
        required=True,
        allow_null=False)


class AffectedStoragesSerializer(serializers.Serializer):
    id = serializers.UUIDField(
        help_text="Identifier of the Storage instance, identifying the " +
        "applicable 'virtualStorageResourceInfo' entry in the 'VnfInstance' data type",
        required=True
    )
    virtualStorageDescId = serializers.UUIDField(
        help_text="Identifier of the related VirtualStorage descriptor " +
        "in the VNFD. ",
        required=True
    )
    changeType = serializers.ChoiceField(
        help_text="Signals the type of change",
        required=True,
        choices=STORAGES_CHANGE_TYPES
    )
    metadata = serializers.DictField(
        help_text="Metadata about this resource. ",
        required=False,
        allow_null=True)
    storageResource = ResourceHandleSerializer(
        help_text="Reference to the VirtualStorage resource.",
        required=True,
        allow_null=False)


class AffectedVLsSerializer(serializers.Serializer):
    id = serializers.UUIDField(
        help_text="Identifier of the virtual link instance, identifying " +
        "the applicable 'vnfVirtualLinkResourceInfo' ",
        required=True
    )
    virtualLinkDescId = serializers.UUIDField(
        help_text="Identifier of the related VLD in the VNFD.",
        required=True
    )
    changeType = serializers.ChoiceField(
        help_text="Signals the type of change",
        required=True,
        choices=VLS_CHANGE_TYPES
    )
    metadata = serializers.DictField(
        help_text="Metadata about this resource. ",
        required=False,
        allow_null=True)
    networkResource = ResourceHandleSerializer(
        help_text="Reference to the VirtualNetwork resource.",
        required=True,
        allow_null=False)


class ResourceChangesSerializer(serializers.Serializer):
    affectedVnfcs = AffectedVnfcsSerializer(
        help_text="Information about VNFC instances that were affected " +
        "during the lifecycle operation.",
        required=False,
        many=True
    )
    affectedVirtualLinks = AffectedVLsSerializer(
        help_text="Information about VL instances that were affected " +
        "during the lifecycle operation. ",
        required=False,
        many=True
    )
    affectedVirtualStorages = AffectedStoragesSerializer(
        help_text="Information about virtualised storage instances that " +
        "were affected during the lifecycle operation",
        required=False,
        many=True
    )


class VNFLCMOpOccSerializer(serializers.Serializer):
    id = serializers.CharField(
        help_text="Identifier of this VNF lifecycle management operation" +
        "occurrence,",
        max_length=255,
        required=True,
        allow_null=False
    )
    operationState = serializers.ChoiceField(
        help_text="The state of the VNF LCM operation occurrence. ",
        required=True,
        choices=LCM_OPERATION_STATE_TYPES
    )
    stateEnteredTime = serializers.CharField(
        help_text="Date-time when the current state was entered.",
        max_length=50
    )
    startTime = serializers.CharField(
        help_text="Date-time of the start of the operation.",
        max_length=50
    )
    vnfInstanceId = serializers.UUIDField(
        help_text="Identifier of the VNF instance to which the operation" +
        "applies"
    )
    grantId = serializers.UUIDField(
        help_text="Identifier of the grant related to this VNF LCM operation " +
                  "occurrence, if such grant exists.",
        allow_null=True
    )
    operation = serializers.ChoiceField(
        help_text="The lifecycle management operation",
        required=True,
        choices=LCM_OPERATION_TYPES
    )
    isAutomaticInvocation = serializers.BooleanField(
        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.",
        default=False
    )
    operationParams = serializers.DictField(
        help_text="Input parameters of the LCM operation. This attribute " +
        "shall be formatted according to the request data type of the " +
        "related LCM operation. The following mapping between operationType and the " +
        "data type of this attribute shall apply: " +
        "1. INSTANTIATE: InstantiateVnfRequest" +
        "2. SCALE: ScaleVnfRequest " +
        "3. SCALE_TO_LEVEL: ScaleVnfToLevelRequest " +
        "4. CHANGE_FLAVOUR: ChangeVnfFlavourRequest " +
        "5. OPERATE: OperateVnfRequest " +
        "6. HEAL: HealVnfRequest " +
        "7. CHANGE_EXT_CONN: ChangeExtVnfConnectivityRequest " +
        "8. TERMINATE: TerminateVnfRequest " +
        "9. MODIFY_INFO: VnfInfoModifications",
        required=True,
        allow_null=False
    )
    isCancelPending = serializers.BooleanField(
        help_text="If the VNF LCM operation occurrence is in 'STARTING'" +
        "'PROCESSING' or 'ROLLING_BACK' state and the operation is being" +
        " cancelled, this attribute shall be set to True. Otherwise, " +
        " it shall be set to False.",
        required=True
    )
    cancelMode = serializers.CharField(
        help_text="The mode of an ongoing cancellation. Shall be present " +
        "when isCancelPending=true, and shall be None otherwise.",
        allow_null=True,
        required=False
    )
    error = ProblemDetailsSerializer(
        help_text="If 'operationState' is 'FAILED_TEMP' or 'FAILED' or " +
        "'PROCESSING' or 'ROLLING_BACK' and previous value of 'operationState' " +
        "was 'FAILED_TEMP'  this attribute shall be present ",
        allow_null=True,
        required=False
    )
    resourceChanges = ResourceChangesSerializer(
        help_text="It contains information about the cumulative changes " +
        "to virtualised resources that were performed so far by the LCM " +
        "operation since its start, if applicable.",
        required=False,
        allow_null=True)
    changedInfo = VnfInfoModificationsSerializer(
        help_text="Information about the changed VNF instance information, " +
        "including VNF configurable properties",
        required=False,
        allow_null=True)
    changedExtConnectivity = ExtVirtualLinkInfoSerializer(
        help_text="Information about changed external connectivity, if this " +
        "notification represents the result of a lifecycle operation occurrence. " +
        "Shall be present if the 'notificationStatus' is set to 'RESULT' and the " +
        "'operation' is set to 'CHANGE_EXT_CONN'. Shall be absent otherwise.",
        many=True,
        required=False,
        allow_null=True)
    _links = LcmOpLinkSerializer(
        help_text="Links to resources related to this resource.",
        required=True)