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