1 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
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 rest_framework import serializers
17 from lcm.ns.enum import NOTIFICATION_TYPES, EVENT_TYPE, PERCEIVED_SEVERITY_TYPE, FAULTY_RESOURCE_TYPE, \
19 from lcm.ns.serializers.sol.ns_performance_anagement_interface import NsInstanceSubscriptionFilterSerializer, \
20 SubscriptionAuthenticationSerializer
21 from lcm.pub.utils.enumutil import enum_to_list
24 # FmSubscriptionRequest
25 class FmNotificationsFilterSerializer(serializers.Serializer):
26 nsInstanceSubscriptionFilter = NsInstanceSubscriptionFilterSerializer(
27 help_text="Filter criteria to select NS instances about which to notify.",
28 required=False, allow_null=True)
29 notificationTypes = serializers.ListField(help_text="Match particular notification types",
30 child=serializers.ChoiceField(
32 choices=enum_to_list(NOTIFICATION_TYPES)),
33 required=False, allow_null=True, many=True)
34 faultyResourceTypes = serializers.ListField(help_text="Match alarms related to NSs with a faulty "
35 "resource type listed in this attribute",
36 child=serializers.ChoiceField(
37 choices=enum_to_list(FAULTY_RESOURCE_TYPE)),
38 required=False, allow_null=True, many=True,)
39 perceivedSeverities = serializers.ListField(help_text="Match alarms related to NSs with a perceived "
40 "severity listed in this attribute.",
41 child=serializers.ChoiceField(
42 choices=enum_to_list(PERCEIVED_SEVERITY_TYPE)),
43 required=False, allow_null=True, many=True,)
44 eventTypes = serializers.ListField(help_text="Match alarms releted to NSs with an event type listed in"
46 child=serializers.ChoiceField(choices=enum_to_list(EVENT_TYPE)),
47 required=False, allow_null=True, many=True,)
48 probableCauses = serializers.CharField(help_text="Match alarms related to NSs with a probable cause "
49 "listed in this attribute",
50 required=False, allow_null=True, many=True)
53 class FmSubscriptionRequestSerializer(serializers.Serializer):
54 filter = FmNotificationsFilterSerializer(help_text="Filter settings for this subscription, to define the"
55 " subset of all notifications this subscription"
56 " relates to", required=False, allow_null=True)
57 callbackUri = serializers.CharField(help_text="The URI of the endpoint to send the notification to.",
58 required=True, allow_null=False)
59 authentication = SubscriptionAuthenticationSerializer(
60 help_text="Authentication parameters to conFigure the use of Authorization when sendingnotifications"
61 " corresponding to this subscription", required=False, allow_null=True)
65 class FmSubscriptionSerializer(serializers.Serializer):
66 id = serializers.CharField(help_text="Identifier of this subscription resource",
67 required=True, allow_null=False)
68 filter = FmNotificationsFilterSerializer(help_text="Filter settings for this subscription, to define"
69 " the subset of all notifications this subscription"
71 required=False, allow_null=True)
72 callbackUri = serializers.CharField(help_text="The URI of the endpoint to send the notification to.",
73 required=False, allow_null=True)
74 _links = serializers.CharField(help_text="Links for this resource.", required=True, allow_null=False)
78 class FaultyComponentInfoSerializer(serializers.Serializer):
79 faultyNestedNsInstanceId = serializers.CharField(help_text="Identifier of the faulty nested NS instance",
80 required=False, allow_null=True)
81 faultyNsVirtualLinkInstanceId = serializers.CharField(help_text="Identifier of the faulty NS "
82 "virtual link instance.",
83 required=True, allow_null=False)
84 faultyVnfInstanceId = serializers.CharField(help_text="Identifier of the faulty VNF instance",
85 required=True, allow_null=False)
88 class ResourceHandleSerualizer(serializers.Serializer):
89 vimId = serializers.CharField(help_text="Identifier of the VIM under whose control this resource is "
90 "placed.", required=False, allow_null=True)
91 resourceProviderId = serializers.CharField(help_text="Identifier of the entity responsible for the "
92 "management of the resource.",
93 required=False, allow_null=True)
94 resourceId = serializers.CharField(help_text="Identifier of the resource in the scope of the VIM or the "
95 "resource provider", required=True, allow_null=False)
96 vimLevelResourceType = serializers.CharField(help_text="Type of the resource in the scope of the VIM or"
97 " the resource provider.",
98 required=False, allow_null=True)
101 class FaultyResourceInfoSerialzier(serializers.Serializer):
102 faultyResource = ResourceHandleSerualizer(help_text="Information that identifies the faulty resource "
103 "instance and its managing entity",
104 required=True, allow_null=False)
105 faultyResourceType = serializers.ListField(help_text="Type of the faulty resource.",
106 child=serializers.ChoiceField(
107 choices=enum_to_list(FAULTY_RESOURCE_TYPE)),
108 required=True, allow_null=False,)
111 class AlarmSerializer(serializers.Serializer):
112 id = serializers.CharField(help_text="Identifier of this Alarm information element.",
113 required=True, allow_null=False)
114 managedObjectId = serializers.CharField(help_text="Identifier of the affected NS instance.",
115 required=True, allow_null=False)
116 rootCauseFaultyComponent = FaultyComponentInfoSerializer(
117 help_text="The NS components that are causing the NS fault.", required=False, allow_null=True)
118 rootCauseFaultyResource = FaultyResourceInfoSerialzier(help_text="The virtualised resources that are"
119 " causing the NS fault.",
120 required=False, allow_null=True)
121 alarmRaisedTime = serializers.DateField(help_text="Time stamp indicating when the alarm is raised by "
122 "the managed object", required=True, allow_null=False)
123 alarmChangedTime = serializers.DateField(help_text="Time stamp indicating when the alarm was last"
124 " changed.", required=False, allow_null=True)
125 alarmClearedTime = serializers.DateField(help_text="Time stamp indicating when the alarm was cleared.",
126 required=False, allow_null=True)
127 ackState = serializers.ListField(help_text="Acknowledgement state of the alarm.",
128 child=serializers.ChoiceField(choices=enum_to_list(ACK_STATE)),
129 required=True, allow_null=False)
130 perceivedSeverity = serializers.ListField(help_text="Perceived severity of the managed object failure.",
131 child=serializers.ChoiceField(
132 choices=enum_to_list(PERCEIVED_SEVERITY_TYPE)),
133 required=True, allow_null=False)
134 eventTime = serializers.DateField(help_text="Time stamp indicating when the fault was observed.",
135 required=True, allow_null=False)
136 eventType = serializers.ListField(help_text="Type of event",
137 child=serializers.ChoiceField(
138 choices=enum_to_list(EVENT_TYPE)),
139 required=True, allow_null=False)
140 faultType = serializers.CharField(help_text="Additional information to clarify the type of the fault.",
141 required=False, allow_null=True)
142 probableCause = serializers.CharField(help_text="Information about the probable cause of the fault.",
143 required=True, allow_null=False)
147 class AlarmNotificationSerializer(serializers.Serializer):
148 id = serializers.CharField(help_text="Identifier of this notification.", required=True, allow_null=False)
149 notificationType = serializers.CharField(help_text="Discriminator for the different notification types.",
150 required=True, allow_null=False)
151 subscriptionId = serializers.CharField(help_text="Identifier of the subscription that this notification"
152 " relates to.", required=True, allow_null=False)
153 timeStamp = serializers.DateField(help_text="Date-time of the generation of the notification.",
154 required=True, allow_null=False)
155 alarm = AlarmSerializer(help_text="Information about an alarm including AlarmId, affected NS identifier,"
156 " and FaultDetails.", required=True, allow_null=False)
157 _links = serializers.CharField(help_text="Links to resources related to this notification.",
158 required=True, allow_null=False)
161 # AlarmClearedNotification
162 class AlarmClearedNotificationSerializer(serializers.Serializer):
163 id = serializers.CharField(help_text="Identifier of this notification.",
164 required=True, allow_null=False)
165 notificationType = serializers.CharField(help_text="Discriminator for the different notification "
166 "types.", required=True, allow_null=False)
167 subscriptionId = serializers.CharField(help_text="Identifier of the subscription that this"
168 " notification relates to.",
169 required=True, allow_null=False)
170 timeStamp = serializers.DateField(help_text="Date-time of the generation of the notification.",
171 required=True, allow_null=False)
172 alarmId = serializers.CharField(help_text="Alarm identifier.", required=True, allow_null=False)
173 alarmClearedTime = serializers.DateField(help_text="The time stamp indicating when the alarm was"
174 " cleared.", required=True, allow_null=False)
175 _links = serializers.CharField(help_text="Links to resources related to this notification.",
176 required=True, allow_null=False)
179 # AlarmListRebuiltNotification
180 class AlarmListRebuiltNotificationSerializer(serializers.Serializer):
181 id = serializers.CharField(help_text="Identifier of this notification.",
182 required=True, allow_null=False)
183 notificationType = serializers.CharField(help_text="Discriminator for the different notification types.",
184 required=True, allow_null=False)
185 subscriptionId = serializers.CharField(help_text="Identifier of the subscription that this notification"
187 required=True, allow_null=False)
188 timeStamp = serializers.DateField(help_text="Date-time of the generation of the notification.",
189 required=True, allow_null=False)
190 _links = serializers.CharField(help_text="Links to resources related to this notification.",
191 required=True, allow_null=False)
195 class AlarmModificationsSerializer(serializers.Serializer):
196 ackState = serializers.ListField(help_text="New value of the ackState attribute in Alarm",
197 child=serializers.ChoiceField(choices=enum_to_list(ACK_STATE)),
198 required=True, allow_null=False)