improve enum in serializers
[vfc/nfvo/lcm.git] / lcm / ns / serializers / sol / pub_serializers.py
1 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
2 # Copyright (c) 2019, ZTE Corporation.
3
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 from rest_framework import serializers
16 from lcm.ns.enum import AFFINITY_OR_ANTIAFFIINTY, AFFINITY_OR_ANTIAFFIINTY_SCOPE
17 from lcm.pub.utils.enumutil import enum_to_list
18
19
20 class ProblemDetailsSerializer(serializers.Serializer):
21     type = serializers.CharField(
22         help_text="A URI reference according to IETF RFC 3986 [5] that identifies the problem type.",
23         required=False,
24         allow_null=True,
25         allow_blank=True
26     )
27     title = serializers.CharField(
28         help_text="A short, human-readable summary of the problem type.",
29         required=False,
30         allow_null=True,
31         allow_blank=True
32     )
33     status = serializers.IntegerField(
34         help_text="The HTTP status code for this occurrence of the problem.",
35         required=True
36     )
37     detail = serializers.CharField(
38         help_text="A human-readable explanation specific to this occurrence of the problem.",
39         required=True
40     )
41     instance = serializers.CharField(
42         help_text="A URI reference that identifies the specific occurrence of the problem.",
43         required=False,
44         allow_null=True,
45         allow_blank=True
46     )
47     additional_details = serializers.ListField(
48         help_text="Any number of additional attributes, as defined in a specification or by an"
49                   " implementation.",
50         required=False,
51         allow_null=True
52     )
53
54
55 class LinkSerializer(serializers.Serializer):
56     href = serializers.CharField(
57         help_text="URI of the referenced resource.",
58         required=True,
59         allow_null=False,
60         allow_blank=False)
61
62
63 class AffinityOrAntiAffinityRuleSerializer(serializers.Serializer):
64     vnfdId = serializers.ListField(
65         child=serializers.CharField(),
66         help_text="Identifier of the VNFD on which the VNF instance is based.",
67         required=False,
68         allow_null=True)
69     vnfProfileId = serializers.ListField(
70         child=serializers.CharField(),
71         help_text="Identifier of (Reference to) a vnfProfile defined in the NSD which the existing VNF instance shall be matched with.",
72         required=False,
73         allow_null=True)
74     vnfInstanceId = serializers.ListField(
75         child=serializers.CharField(),
76         help_text="Identifier of the existing VNF instance to be used in the NS.",
77         required=True,
78         allow_null=False)
79     affinityOrAntiAffiinty = serializers.ChoiceField(
80         help_text="The type of the constraint.",
81         choices=enum_to_list(AFFINITY_OR_ANTIAFFIINTY),
82         required=True,
83         allow_null=False,
84         allow_blank=False)
85     scope = serializers.ChoiceField(
86         help_text="Specifies the scope of the rule where the placement constraint applies.",
87         choices=enum_to_list(AFFINITY_OR_ANTIAFFIINTY_SCOPE),
88         required=True,
89         allow_null=False,
90         allow_blank=False)