0c1b395d56ef30b715b83487ba2e61dbc8a4cff8
[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 = vnfProductsProvidersSerializer(
81         help_text="Match VNF packages that contain "
82                   "VNF products from certain providers.",
83         allow_null=False,
84         required=False
85     )
86     vnfdId = serializers.ListField(
87         child=serializers.UUIDField(),
88         help_text="Match VNF packages with a VNFD identifier"
89                   "listed in the attribute",
90         required=False,
91         allow_null=False
92     )
93     vnfPkgId = serializers.ListField(
94         child=serializers.UUIDField(),
95         help_text="Match VNF packages with a VNFD identifier"
96                   "listed in the attribute",
97         required=False,
98         allow_null=False
99     )
100     operationalState = serializers.ListField(
101         child=serializers.ChoiceField(
102             required=True,
103             choices=PackageOperationalStateType
104         ),
105         help_text="Operational state of the VNF package.",
106         allow_null=False,
107         required=False
108     )
109     usageState = serializers.ListField(
110         child=serializers.ChoiceField(
111             required=True,
112             choices=PackageUsageStateType
113         ),
114         help_text="Operational state of the VNF package.",
115         allow_null=False,
116         required=False
117     )
118
119
120 class LinkSerializer(serializers.Serializer):
121     href = serializers.CharField(
122         help_text="URI of the referenced resource.",
123         required=True,
124         allow_null=False,
125         allow_blank=False
126     )
127
128     class Meta:
129         ref_name = 'NOTIFICATION_LINKSERIALIZER'
130
131
132 class PkgmLinksSerializer(serializers.Serializer):
133     vnfPackage = LinkSerializer(
134         help_text="Link to the resource representing the VNF package to which the notified change applies.",
135         required=False,
136         allow_null=False
137     )
138     subscription = LinkSerializer(
139         help_text="Link to the related subscription.",
140         required=False,
141         allow_null=False
142     )
143
144
145 class PkgChangeNotificationSerializer(serializers.Serializer):
146     id = serializers.CharField(
147         help_text="Identifier of this notification.",
148         required=True,
149         allow_null=False
150     )
151     notificationTypes = serializers.ChoiceField(
152         help_text="Discriminator for the different notification types.",
153         choices=["VnfPackageChangeNotification"],
154         required=True,
155         allow_null=False
156     )
157     subscriptionId = serializers.CharField(
158         help_text="Identifier of the subscription that this notification relates to.",
159         required=True,
160         allow_null=False
161     )
162     vnfPkgId = serializers.UUIDField(
163         help_text="Identifier of the VNF package.",
164         required=True,
165         allow_null=False
166     )
167     vnfdId = serializers.UUIDField(
168         help_text="This identifier, which is managed by the VNF provider, "
169                   "identifies the VNF package and the VNFD in a globally unique way.",
170         required=True,
171         allow_null=False
172     )
173     changeType = serializers.ChoiceField(
174         help_text="The type of change of the VNF package.",
175         choices=PackageChangeType,
176         required=True,
177         allow_null=False
178     )
179     operationalState = serializers.ChoiceField(
180         help_text="New operational state of the VNF package.",
181         choices=PackageOperationalStateType,
182         required=False,
183         allow_null=False
184     )
185     vnfdId = serializers.CharField(
186         help_text="This identifier, which is managed by the VNF provider, "
187                   "identifies the VNF package and the VNFD in a globally unique way.",
188         required=True,
189         allow_null=False
190     )
191     _links = PkgmLinksSerializer(
192         help_text="Links to resources related to this resource.",
193         required=True,
194         allow_null=False
195     )
196
197
198 class PkgOnboardingNotificationSerializer(serializers.Serializer):
199     id = serializers.CharField(
200         help_text="Identifier of this notification.",
201         required=True,
202         allow_null=False
203     )
204     notificationTypes = serializers.ChoiceField(
205         help_text="Discriminator for the different notification types.",
206         choices=["VnfPackageOnboardingNotification"],
207         required=True,
208         allow_null=False
209     )
210     subscriptionId = serializers.CharField(
211         help_text="Identifier of the subscription that this notification relates to.",
212         required=True,
213         allow_null=False
214     )
215     vnfPkgId = serializers.UUIDField(
216         help_text="Identifier of the VNF package.",
217         required=True,
218         allow_null=False
219     )
220     vnfdId = serializers.UUIDField(
221         help_text="This identifier, which is managed by the VNF provider, "
222                   "identifies the VNF package and the VNFD in a globally unique way.",
223         required=True,
224         allow_null=False
225     )
226     _links = PkgmLinksSerializer(
227         help_text="Links to resources related to this resource.",
228         required=True,
229         allow_null=False
230     )