fix the serializer bug of nslcm
[vfc/nfvo/lcm.git] / lcm / ns / serializers / inst_ns_serializers.py
1 # Copyright (c) 2018, CMCC Technologies Co., Ltd.
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
17 from lcm.ns.serializers.pub_serializers import CpProtocolDataSerializer
18 from lcm.ns.serializers.update_serializers import AddPnfDataSerializer, VnfInstanceDataSerializer
19
20
21 class SapDataSerializer(serializers.Serializer):
22     sapdId = serializers.CharField(help_text="Reference to the SAPD for this SAP.", required=True)
23     sapName = serializers.CharField(help_text="Human readable name for the SAP.", required=True)
24     description = serializers.CharField(help_text="Human readable description for the SAP.", required=True)
25     sapProtocolData = CpProtocolDataSerializer(help_text="Parameters for configuring the network protocols"
26                                                          " on the SAP.",
27                                                required=False, allow_null=True, many=True)
28
29
30 class civicAddressElementSerializer(serializers.Serializer):
31     caType = serializers.CharField(help_text="Describe the content type of caValue.", required=True)
32     caValue = serializers.CharField(help_text="Content of civic address element corresponding to the"
33                                               "aType.", required=True)
34
35
36 class LocationConstraintsSerializer(serializers.Serializer):
37     countryCode = serializers.CharField(help_text="The two-letter ISO 3166 [29] country code in capital"
38                                                   "letters.", required=True)
39     civicAddressElement = civicAddressElementSerializer(help_text="Zero or more elements comprising the civic"
40                                                                   "address.",
41                                                         required=False, allow_null=True, many=True)
42
43
44 class VnfLocationConstraintSerializer(serializers.Serializer):
45     vnfProfileId = serializers.CharField(help_text="ID of VNF profile", required=False, allow_null=True)
46     locationConstraints = LocationConstraintsSerializer(help_text="Defines the location constraints for the"
47                                                                   "VNF instance to be created based on the"
48                                                                   "VNF profile.",
49                                                         required=False, allow_null=True)
50
51
52 class ParamsForVnfSerializer(serializers.Serializer):
53     vnfProfileId = serializers.CharField(help_text="Identifier of (reference to) a vnfProfile to which the"
54                                                    "additional parameters apply", required=True)
55     additionalParams = serializers.DictField(help_text="Content of civic address element corresponding to the"
56                                                        "caType",
57                                              child=serializers.CharField(help_text="KeyValue Pairs",
58                                                                          allow_blank=True),
59                                              required=False, allow_null=True)
60
61
62 class AffinityOrAntiAffinityRuleSerializer(serializers.Serializer):
63     vnfdId = serializers.ListField(help_text="Reference to a VNFD.", required=False, allow_null=True)
64     vnfProfileId = serializers.ListField(help_text="Reference to a vnfProfile defined in the NSD.",
65                                          required=True)
66     vnfInstanceId = serializers.ListField(help_text="Reference to the existing VNF instance as the subject of"
67                                                     "the affinity or anti-affinity rule.",
68                                           required=False, allow_null=True)
69     affinityOrAntiAffiinty = serializers.ChoiceField(help_text="The type of the constraint.",
70                                                      choices=["AFFINITY", "ANTI_AFFINITY"], required=True)
71     scope = serializers.ChoiceField(help_text="Specifies the scope of the rule where the placement constraint"
72                                               "applies.", choices=["NFVI_POP", "ZONE", "ZONE_GROUP",
73                                                                    "NFVI_NODE"], required=True)
74
75
76 class InstantNsReqSerializer(serializers.Serializer):
77     nsFlavourId = serializers.CharField(help_text="Identifier of the NS deployment flavour to be"
78                                                   "instantiated.", required=True)
79     sapData = SapDataSerializer(help_text="Create data concerning the SAPs of this NS",
80                                 required=False, allow_null=True, many=True)
81     addpnfData = AddPnfDataSerializer(help_text="Information on the PNF(s) that are part of this NS.",
82                                       required=False, allow_null=True, many=True)
83     vnfInstanceData = VnfInstanceDataSerializer(help_text="Specify an existing VNF instance to be used in "
84                                                           "the NS.",
85                                                 required=False, allow_null=True, many=True)
86     nestedNsInstanceId = serializers.ListField(help_text="Specify an existing NS instance to be used as a "
87                                                          "nested NS within the NS",
88                                                required=False, allow_null=True)
89     localizationLanguage = VnfLocationConstraintSerializer(help_text="Defines the location constraints for "
90                                                                      "the VNF to be instantiated as part of"
91                                                                      " the NS instantiation.",
92                                                            required=False, allow_null=True, many=True)
93     additionalParamForNs = serializers.DictField(
94         help_text="Allows the OSS/BSS to provide additional parameters at the NS level ",
95         child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
96         required=False,
97         allow_null=True
98     )
99     additionalParamsForVnf = ParamsForVnfSerializer(help_text="Allows the OSS/BSS to provide additional "
100                                                               "parameter(s)per VNF instance",
101                                                     required=False, allow_null=True, many=True)
102     startTime = serializers.DateTimeField(help_text="Timestamp indicating the earliest time to instantiate"
103                                                     "the NS.", required=False, allow_null=True)
104     nsInstantiationLevelId = serializers.CharField(help_text="Identifies one of the NS instantiation levels"
105                                                              "declared in the DF applicable to this NS "
106                                                              "instance", required=False, allow_null=True)
107     additionalAffinityOrAntiAffiniityRule = AffinityOrAntiAffinityRuleSerializer(
108         help_text="Specifies additional affinity or anti-affinity constraint for the VNF instances to be"
109                   " instantiated as part of the NS instantiation.",
110         required=False, allow_null=True, many=True)
111
112
113 class InstNsPostDealReqSerializer(serializers.Serializer):
114     status = serializers.CharField(help_text="Status of NS Inst", required=True)