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
18 # PmSubscriptionRequest
19 from lcm.ns.enum import CROSSINGDIRECTION_TYPE, THRESHOLD_TYPE
20 from lcm.pub.utils.enumutil import enum_to_list
23 class NsInstanceSubscriptionFilterSerializer(serializers.Serializer):
24 nsdIds = serializers.CharField(help_text="If present, match NS instances that were created based on a"
25 " NSD identified by one of the nsdId values listed in this"
26 " attribute.", required=False, allow_null=True, many=True)
27 vnfdIds = serializers.CharField(help_text="If present, match NS instances that contain VNF instances that"
28 " were created based on a VNFD identified by one of the vnfdId "
29 "values listed in this attribute.", required=False,
30 allow_null=True, many=True)
31 pnfdIds = serializers.CharField(help_text="If present, match NS instances that contain PNFs that are "
32 "represented by a PNFD identified by one of the pnfdId values "
33 "listed in this attribute", required=False,
34 allow_null=True, many=True)
35 nsInstanceIds = serializers.CharField(help_text="If present, match NS instances with an instance "
36 "identifier listed in this attribute.",
37 required=False, allow_null=True, many=True)
38 nsInstanceNames = serializers.CharField(help_text="If present, match NS instances with a NS Instance Name"
39 " listed in this attribute",
40 required=False, allow_null=True, many=True)
43 class PmNotificationsFilterSerializer(serializers.Serializer):
44 nsInstanceSubscriptionFilter = NsInstanceSubscriptionFilterSerializer(help_text="Filter criteria to"
45 " select NS instances "
46 "about which to notify",
47 required=False, allow_null=True,
49 notificationTypes = serializers.ChoiceField(help_text="Match particular notification types.",
50 choices=["ThresholdCrossedNotification",
51 "PerformanceInformationAvailableNotification"],
52 required=False, allow_null=True, many=True)
55 class SubscriptionAuthenticationSerializer(serializers.Serializer):
56 authType = serializers.ChoiceField(help_text="Defines the types of Authentication Authorization the API"
57 " consumer is willing to accept when receiving a"
58 " notification.", choices=["BASIC",
59 "OAUTH2_CLIENT_CREDENTIALS",
60 "TLS_CERT"], required=True,
61 allow_null=False, many=True)
62 paramsBasic = serializers.CharField(help_text="Parameters for authentication authorization using BASIC",
63 required=False, allow_null=True, allow_blank=True)
64 paramsOauth2ClientCredentials = serializers.CharField(help_text="Parameters for authentication "
65 "authorization using OAUTH2"
66 "_CLIENT_CREDENTIALS.",
67 required=False, allow_null=True, allow_blank=True)
70 class PmSubscriptionRequestSerializer(serializers.Serializer):
71 filter = PmNotificationsFilterSerializer(help_text="Filter settings for this subscription, to define the "
72 "subset of all notifications this subscription"
73 " relates to", required=False, allow_null=True,
75 callbackUri = serializers.CharField(help_text="The URI of the endpoint to send the notification to",
76 required=True, allow_null=False, allow_blank=False)
77 authentication = SubscriptionAuthenticationSerializer(help_text="Authentication parameters to conFigure"
78 " the use of Authorization when sending"
79 " notifications corresponding to "
81 required=False, allow_null=True, allow_blank=True)
85 class PmSubscriptionSerializer(serializers.Serializer):
86 id = serializers.CharField(help_text="Identifier that identifies the subscription.",
87 required=True, allow_null=False)
88 filter = PmNotificationsFilterSerializer(help_text="Filter settings for this subscription, to define the"
89 " subset of all notifications this subscription "
90 "relates to", required=False, allow_null=True)
91 callbackUri = serializers.CharField(help_text="The URI of the endpoint to send the notification to.",
92 required=True, allow_null=False)
93 _links = serializers.CharField(help_text="Links to resources related to this resource.",
94 required=True, allow_null=False)
97 # ThresholdCrossedNotification
98 class ThresholdCrossedNotificationSerializer(serializers.Serializer):
99 id = serializers.CharField(help_text="Identifier of this notification. If a notification is sent multiple"
100 " times due to multiple subscriptions",
101 required=True, allow_null=False)
102 notificationType = serializers.CharField(help_text="Discriminator for the different notification types.",
103 required=True, allow_null=False)
104 subscriptionId = serializers.CharField(help_text="Identifier of the subscription that this notification "
105 "relates to.", required=True, allow_null=False)
106 timeStamp = serializers.CharField(help_text="Date and time of the generation of the notification.",
107 required=True, allow_null=False)
108 thresholdId = serializers.CharField(help_text="Identifier of the threshold which has been crossed.",
109 required=True, allow_null=False)
110 crossingDirection = serializers.ListField(help_text="An indication of whether the threshold was crossed "
111 "in upward or downward direction.",
112 child=serializers.ChoiceField(
114 choices=enum_to_list(CROSSINGDIRECTION_TYPE)),
115 required=True, allow_null=False)
116 objectInstanceId = serializers.CharField(help_text="Identifier that identifies a NS instance.",
117 required=True, allow_null=False)
118 performanceMetric = serializers.CharField(help_text="Performance metric associated with the "
119 "threshold", required=True, allow_null=False)
120 performanceValue = serializers.CharField(help_text="Value of the metric that resulted in threshold "
121 "crossing.", required=True, allow_null=False)
122 _links = serializers.CharField(help_text="Links to resources related to this notification",
123 required=True, allow_null=False)
126 # PerformanceInformationAvailableNotification
127 class PerformanceInformationAvailableNotification(serializers.Serializer):
128 id = serializers.CharField(help_text="Identifier of this notification.", required=True, allow_null=False)
129 notificationType = serializers.CharField(help_text="Discriminator for the different notification types",
130 required=True, allow_null=False)
131 subscriptionId = serializers.CharField(help_text="Identifier of the subscription that this notification "
132 "relates to.", required=True, allow_null=False)
133 timeStamp = serializers.DateField(help_text="Date and time of the generation of the notification.",
134 required=True, allow_null=False)
135 objectInstanceId = serializers.CharField(help_text="Identifier that identifies a NS instance.",
136 required=True, allow_null=False)
137 _links = serializers.CharField(help_text="Links to resources related to this notification",
138 required=True, allow_null=False)
142 class PmJobCriteriaSerializer(serializers.Serializer):
143 performanceMetric = serializers.CharField(help_text="This defines the types of performance metrics for"
144 " the specified object instances",
145 required=False, allow_null=True, many=True)
146 performanceMetricGroup = serializers.CharField(help_text="Group of performance metrics.",
147 required=False, allow_null=True, many=True)
148 collectionPeriod = serializers.CharField(help_text="Specifies the periodicity at which the producer "
149 "will collect performance information",
150 required=True, allow_null=False)
151 reportingPeriod = serializers.CharField(help_text="Specifies the periodicity at which the producer "
152 "will report to the consumer",
153 required=True, allow_null=False)
154 reportingBoundary = serializers.DateField(help_text="Identifies a time boundary after which the "
155 "reporting will stop",
156 required=False, allow_null=True)
159 class CreatePmJobRequestSerializer(serializers.Serializer):
160 objectInstanceIds = serializers.CharField(help_text="Identifiers of the NS instances for which"
161 " performance information is requested to be"
163 required=True, allow_null=False, many=True)
164 criteria = PmJobCriteriaSerializer(help_text="Criteria of the collection of performance information.",
165 required=True, allow_null=False)
169 class PmJobSerializer(serializers.Serializer):
170 id = serializers.CharField(help_text="Identifier of this PM job.", required=True, allow_null=False)
171 objectInstanceIds = serializers.CharField(help_text="Identifiers of the NS instances for which "
172 "performance information is collected.",
173 required=True, allow_null=False, many=True)
174 criteria = PmJobCriteriaSerializer(help_text="Criteria of the collection of performance "
175 "information.", required=True)
176 reports = serializers.CharField(help_text="Information about available reports collected by this PM job",
177 required=False, allow_null=True, many=True)
178 _links = serializers.CharField(help_text="Links for this resource.", required=False, allow_null=True)
181 # CreateThresholdRequest
182 class ThresholdCriteriaSerializer(serializers.Serializer):
183 performanceMetric = serializers.CharField(help_text="Defines the performance metric associated with the "
184 "threshold", required=True, allow_null=False)
185 thresholdType = serializers.ListField(help_text="Type of threshold.",
186 child=serializers.ChoiceField(
187 required=True, choices=enum_to_list(THRESHOLD_TYPE)),
188 required=True, allow_null=False)
191 class CreateThresholdRequestSerializer(serializers.Serializer):
192 objectInstanceId = serializers.CharField(help_text="Identifier of the NS instance associated with this "
193 "threshold", required=True, allow_null=False)
194 criteria = ThresholdCriteriaSerializer(help_text="Criteria that define this threshold.",
195 required=True, allow_null=False)
199 class ThresholdSerializer(serializers.Serializer):
200 id = serializers.CharField(help_text="Identifier of this threshold resource.",
201 required=True, allow_null=False)
202 objectInstanceId = serializers.CharField(help_text="Identifier of the NS instance associated with the "
203 "threshold.", required=True, allow_null=False)
204 criteria = serializers.CharField(help_text="Criteria that define this threshold.",
205 required=True, allow_null=False)
206 _links = serializers.CharField(help_text="Links for this resource.", required=True, allow_null=False)
210 class PerformanceReportSerializer(serializers.Serializer):
211 entries = serializers.CharField(help_text="List of performance information entries.",
212 required=True, allow_null=False, many=True)