separate ns-create and test create function
[vfc/nfvo/lcm.git] / lcm / ns / serializers / ns_serializers.py
1 # Copyright 2018 ZTE Corporation.
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 lcm.ns_pnfs.serializers.pnf_serializer import PnfInstanceSerializer
17
18
19 class VnfInstSerializer(serializers.Serializer):
20     vnfInstanceId = serializers.CharField(help_text="ID of VNF instance", required=True)
21     vnfInstanceName = serializers.CharField(help_text="Name of VNF instance", required=False, allow_null=True, allow_blank=True)
22     vnfdId = serializers.CharField(help_text="ID of VNFD", required=False, allow_null=True, allow_blank=True)
23
24
25 class CpInstInfoSerializer(serializers.Serializer):
26     cpInstanceId = serializers.CharField(help_text="ID of CP instance", required=True)
27     cpInstanceName = serializers.CharField(help_text="Name of CP instance", required=False, allow_null=True, allow_blank=True)
28     cpdId = serializers.CharField(help_text="ID of CPD", required=False, allow_null=True, allow_blank=True)
29
30
31 class VlInstSerializer(serializers.Serializer):
32     vlInstanceId = serializers.CharField(help_text="ID of VL instance", required=True)
33     vlInstanceName = serializers.CharField(help_text="Name of VL instance", required=False, allow_null=True, allow_blank=True)
34     vldId = serializers.CharField(help_text="ID of VLD", required=False, allow_null=True, allow_blank=True)
35     relatedCpInstanceId = CpInstInfoSerializer(help_text="Related CP instances", many=True)
36
37
38 class VnffgInstSerializer(serializers.Serializer):
39     vnffgInstanceId = serializers.CharField(help_text="ID of VNFFG instance", required=True)
40     vnfdId = serializers.CharField(help_text="ID of VNFD", required=False, allow_null=True, allow_blank=True)
41     pnfId = serializers.CharField(help_text="ID of PNF", required=False, allow_null=True, allow_blank=True)
42     virtualLinkId = serializers.CharField(help_text="ID of virtual link", required=False, allow_null=True, allow_blank=True)
43     cpdId = serializers.CharField(help_text="ID of CPD", required=False, allow_null=True, allow_blank=True)
44     nfp = serializers.CharField(help_text="nfp", required=False, allow_null=True, allow_blank=True)
45
46
47 class QueryNsRespSerializer(serializers.Serializer):
48     nsInstanceId = serializers.CharField(help_text="ID of NS instance", required=True)
49     nsName = serializers.CharField(help_text="Name of NS instance", required=False, allow_null=True, allow_blank=True)
50     description = serializers.CharField(help_text="Description of NS instance", required=False, allow_null=True, allow_blank=True)
51     nsdId = serializers.CharField(help_text="ID of NSD", required=True)
52     vnfInfo = VnfInstSerializer(help_text="VNF instances", many=True, required=False, allow_null=True)
53     pnfInfo = PnfInstanceSerializer(help_text="PNF instances", many=True, required=False, allow_null=True)
54     vlInfo = VlInstSerializer(help_text="VL instances", many=True, required=False, allow_null=True)
55     vnffgInfo = VnffgInstSerializer(help_text="VNFFG instances", many=True, required=False, allow_null=True)
56     nsState = serializers.CharField(help_text="State of NS instance", required=False, allow_null=True, allow_blank=True)
57
58
59 class VnfLocationSerializer(serializers.Serializer):
60     vimId = serializers.CharField(help_text="ID of VIM", required=False, allow_null=True, allow_blank=True)
61
62
63 class LocationConstraintSerializer(serializers.Serializer):
64     vnfProfileId = serializers.CharField(help_text="ID of VNF profile", required=False, allow_null=True, allow_blank=True)
65     locationConstraints = VnfLocationSerializer(help_text="Location constraint", required=False, allow_null=True)
66
67
68 class AddressRange(serializers.Serializer):
69     minAddress = serializers.IPAddressField(help_text="Lowest IP address belonging to the range.", required=True)
70     maxAddress = serializers.IPAddressField(help_text="Highest IP address belonging to the range.", required=True)
71
72
73 class IpAddress(serializers.Serializer):
74     type = serializers.ChoiceField(help_text="The type of the IP addresses.", required=True, choices=["IPV4", "IPV6"])
75     fixedAddresses = serializers.ListField(child=serializers.CharField(help_text="Fixed addresses to assign."), required=False)
76     numDynamicAddresses = serializers.IntegerField(help_text="Number of dynamic addresses to assign.", required=False)
77     addressRange = AddressRange(help_text="An IP address range to be used.", required=False)
78     subnetId = serializers.CharField(help_text="Subnet defined by the identifier of the subnet resource in the VIM.", required=False, allow_null=True, allow_blank=True)
79
80
81 class IpOverEthernetSerializer(serializers.Serializer):
82     macAddress = serializers.CharField(help_text="MAC address.", required=False, allow_null=True, allow_blank=True)
83     ipAddresses = IpAddress(help_text="List of IP addresses to assign to the extCP instance.", required=False, many=True)
84
85
86 class CpProtocolInfoSerializer(serializers.Serializer):
87     layerProtocol = serializers.ChoiceField(
88         help_text="The identifier of layer(s) and protocol(s) associated to the network address information.",
89         choices=["IP_OVER_ETHERNET"],
90         required=True,
91         allow_null=False)
92     ipOverEthernet = IpOverEthernetSerializer(
93         help_text="IP addresses over Ethernet to assign to the extCP instance.",
94         required=False,
95         allow_null=True)
96
97
98 class PnfExtCpData(serializers.Serializer):
99     cpInstanceId = serializers.CharField(help_text="Identifier of the CP", required=False, allow_null=True, allow_blank=True)
100     cpdId = serializers.CharField(help_text="Identifier of the Connection Point Descriptor", required=False, allow_null=True, allow_blank=True)
101     cpProtocolData = CpProtocolInfoSerializer(help_text="Address assigned for this CP", required=True, allow_null=False, many=True)
102
103
104 class AddPnfData(serializers.Serializer):
105     pnfId = serializers.CharField(help_text="Identifier of the PNF", required=True, allow_null=False, allow_blank=True)
106     pnfName = serializers.CharField(help_text="Name of the PNF", required=True, allow_null=True, allow_blank=True)
107     pnfdId = serializers.CharField(help_text="Identifier of the PNFD", required=True, allow_null=False, allow_blank=True)
108     pnfProfileId = serializers.CharField(help_text="Identifier of related PnfProfile in the NSD", required=True, allow_null=False, allow_blank=True)
109     cpData = PnfExtCpData(help_text="Address assigned for the PNF external CP", required=False, many=True)
110
111
112 class InstantNsReqSerializer(serializers.Serializer):
113     locationConstraints = LocationConstraintSerializer(help_text="Location constraints", required=False, many=True)
114     additionalParamForNs = serializers.DictField(
115         help_text="Additional param for NS",
116         child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
117         required=False,
118         allow_null=True
119     )
120     addpnfData = AddPnfData(help_text="Information on the PNF", required=False, many=True)
121
122
123 class NsOperateJobSerializer(serializers.Serializer):
124     jobId = serializers.CharField(help_text="ID of NS operate job", required=True)
125
126
127 class TerminateNsReqSerializer(serializers.Serializer):
128     terminationType = serializers.CharField(help_text="Type of NS termination", required=False, allow_null=True, allow_blank=True)
129     gracefulTerminationTimeout = serializers.CharField(help_text="Timeout of NS graceful termination", required=False, allow_null=True, allow_blank=True)
130
131
132 class InstNsPostDealReqSerializer(serializers.Serializer):
133     status = serializers.CharField(help_text="Status of NS Inst", required=True)
134
135
136 class ScaleNsByStepsSerializer(serializers.Serializer):
137     aspectId = serializers.CharField(help_text="ID of aspect", required=True)
138     numberOfSteps = serializers.CharField(help_text="Number of steps", required=True)
139     scalingDirection = serializers.CharField(help_text="Scaling direction", required=True)
140
141
142 class ScaleNsDataSerializer(serializers.Serializer):
143     scaleNsByStepsData = ScaleNsByStepsSerializer(help_text="Scale NS by steps data", many=True)
144
145
146 class ManualScaleNsReqSerializer(serializers.Serializer):
147     scaleType = serializers.CharField(help_text="Type of NS Scale", required=True)
148     scaleNsData = ScaleNsDataSerializer(help_text="Scale NS data", many=True)