a0fd4953e30ff7e48c3c7a2470f2cb4a9cbf0679
[modeling/etsicatalog.git] / catalog / packages / serializers / vnf_pkg_notifications.py
1 # Copyright (C) 2019 Verizon. All Rights Reserved
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 from catalog.packages.const import NOTIFICATION_TYPES
17
18 PackageOperationalStateType = ["ENABLED", "DISABLED"]
19 PackageUsageStateType = ["IN_USE", "NOT_IN_USE"]
20 PackageChangeType = ["OP_STATE_CHANGE", "PKG_DELETE"]
21
22
23 class VersionSerializer(serializers.Serializer):
24     vnfSoftwareVersion = serializers.CharField(
25         help_text="VNF software version to match.",
26         max_length=255,
27         required=True,
28         allow_null=False
29     )
30     vnfdVersions = serializers.ListField(
31         child=serializers.CharField(),
32         help_text="Match VNF packages that contain "
33                   "VNF products with certain VNFD versions",
34         required=False,
35         allow_null=False
36     )
37
38
39 class vnfProductsSerializer(serializers.Serializer):
40     vnfProductName = serializers.CharField(
41         help_text="Name of the VNF product to match.",
42         max_length=255,
43         required=True,
44         allow_null=False
45     )
46     versions = VersionSerializer(
47         help_text="match VNF packages that contain "
48                   "VNF products with certain versions",
49         required=False,
50         allow_null=False
51     )
52
53
54 class vnfProductsProvidersSerializer(serializers.Serializer):
55     vnfProvider = serializers.CharField(
56         help_text="Name of the VNFprovider to match.",
57         max_length=255,
58         required=True,
59         allow_null=False
60     )
61     vnfProducts = vnfProductsSerializer(
62         help_text="match VNF packages that contain "
63                   "VNF products with certain product names, "
64                   "from one particular provider",
65         required=False,
66         allow_null=False
67     )
68
69
70 class PkgmNotificationsFilter(serializers.Serializer):
71     notificationTypes = serializers.ListField(
72         child=serializers.ChoiceField(
73             required=True,
74             choices=NOTIFICATION_TYPES
75         ),
76         help_text="Match particular notification types",
77         allow_null=False,
78         required=False
79     )
80     vnfProductsFromProviders = serializers.ListField(
81         child=vnfProductsProvidersSerializer(),
82         help_text="Match VNF packages that contain "
83                   "VNF products from certain providers.",
84         allow_null=False,
85         required=False
86     )
87     vnfdId = serializers.ListField(
88         child=serializers.UUIDField(),
89         help_text="Match VNF packages with a VNFD identifier"
90                   "listed in the attribute",
91         required=False,
92         allow_null=False
93     )
94     vnfPkgId = serializers.ListField(
95         child=serializers.UUIDField(),
96         help_text="Match VNF packages with a VNFD identifier"
97                   "listed in the attribute",
98         required=False,
99         allow_null=False
100     )
101     operationalState = serializers.ListField(
102         child=serializers.ChoiceField(
103             required=True,
104             choices=PackageOperationalStateType
105         ),
106         help_text="Operational state of the VNF package.",
107         allow_null=False,
108         required=False
109     )
110     usageState = serializers.ListField(
111         child=serializers.ChoiceField(
112             required=True,
113             choices=PackageUsageStateType
114         ),
115         help_text="Operational state of the VNF package.",
116         allow_null=False,
117         required=False
118     )
119
120
121 class LinkSerializer(serializers.Serializer):
122     href = serializers.CharField(
123         help_text="URI of the referenced resource.",
124         required=True,
125         allow_null=False,
126         allow_blank=False
127     )
128
129     class Meta:
130         ref_name = 'NOTIFICATION_LINKSERIALIZER'
131
132
133 class PkgmLinksSerializer(serializers.Serializer):
134     vnfPackage = LinkSerializer(
135         help_text="Link to the resource representing the VNF package to which the notified change applies.",
136         required=False,
137         allow_null=False
138     )
139     subscription = LinkSerializer(
140         help_text="Link to the related subscription.",
141         required=False,
142         allow_null=False
143     )
144
145
146 class PkgChangeNotificationSerializer(serializers.Serializer):
147     id = serializers.CharField(
148         help_text="Identifier of this notification.",
149         required=True,
150         allow_null=False
151     )
152     notificationType = serializers.ChoiceField(
153         help_text="Discriminator for the different notification types.",
154         choices=["VnfPackageChangeNotification"],
155         required=True,
156         allow_null=False
157     )
158     timeStamp = serializers.DateTimeField(
159         help_text="Date-time of the generation of the notification.",
160         format="%Y-%m-%d %H:%M:%S",
161         required=True,
162         allow_null=False
163     )
164     subscriptionId = serializers.CharField(
165         help_text="Identifier of the subscription that this notification relates to.",
166         required=True,
167         allow_null=False
168     )
169     vnfPkgId = serializers.UUIDField(
170         help_text="Identifier of the VNF package.",
171         required=True,
172         allow_null=False
173     )
174     vnfdId = serializers.UUIDField(
175         help_text="This identifier, which is managed by the VNF provider, "
176                   "identifies the VNF package and the VNFD in a globally unique way.",
177         required=True,
178         allow_null=False
179     )
180     changeType = serializers.ChoiceField(
181         help_text="The type of change of the VNF package.",
182         choices=PackageChangeType,
183         required=True,
184         allow_null=False
185     )
186     operationalState = serializers.ChoiceField(
187         help_text="New operational state of the VNF package.",
188         choices=PackageOperationalStateType,
189         required=False,
190         allow_null=False
191     )
192     vnfdId = serializers.CharField(
193         help_text="This identifier, which is managed by the VNF provider, "
194                   "identifies the VNF package and the VNFD in a globally unique way.",
195         required=True,
196         allow_null=False
197     )
198     _links = PkgmLinksSerializer(
199         help_text="Links to resources related to this resource.",
200         required=True,
201         allow_null=False
202     )
203
204
205 class PkgOnboardingNotificationSerializer(serializers.Serializer):
206     id = serializers.CharField(
207         help_text="Identifier of this notification.",
208         required=True,
209         allow_null=False
210     )
211     notificationType = serializers.ChoiceField(
212         help_text="Discriminator for the different notification types.",
213         choices=["VnfPackageOnboardingNotification"],
214         required=True,
215         allow_null=False
216     )
217     subscriptionId = serializers.CharField(
218         help_text="Identifier of the subscription that this notification relates to.",
219         required=True,
220         allow_null=False
221     )
222     timeStamp = serializers.DateTimeField(
223         help_text="Date-time of the generation of the notification.",
224         format="%Y-%m-%d %H:%M:%S",
225         required=True,
226         allow_null=False
227     )
228     vnfPkgId = serializers.UUIDField(
229         help_text="Identifier of the VNF package.",
230         required=True,
231         allow_null=False
232     )
233     vnfdId = serializers.UUIDField(
234         help_text="This identifier, which is managed by the VNF provider, "
235                   "identifies the VNF package and the VNFD in a globally unique way.",
236         required=True,
237         allow_null=False
238     )
239     _links = PkgmLinksSerializer(
240         help_text="Links to resources related to this resource.",
241         required=True,
242         allow_null=False
243     )