fix cp related error
[vfc/nfvo/lcm.git] / lcm / ns / serializers / sol / cp_serializers.py
1 # Copyright (c) 2019, 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 from lcm.ns.const import IPADDRESSES_TYPES
17
18 IPADDRESSES_TYPE = [
19     IPADDRESSES_TYPES.IPV4,
20     IPADDRESSES_TYPES.IPV6
21 ]
22 LAYER_PROTOCOL = [
23     "IP_OVER_ETHERNET"
24 ]
25
26
27 class AddressRangeSerializer(serializers.Serializer):
28     minAddress = serializers.IPAddressField(
29         help_text="Lowest IP address belonging to the range.",
30         required=True)
31     maxAddress = serializers.IPAddressField(
32         help_text="Highest IP address belonging to the range.",
33         required=True)
34
35
36 class IpAddressesDataSerialzier(serializers.Serializer):
37     type = serializers.ChoiceField(
38         help_text="The type of the IP addresses.",
39         required=True,
40         choices=IPADDRESSES_TYPE)
41     fixedAddresses = serializers.ListField(
42         child=serializers.CharField(
43             help_text="Fixed addresses to assign.",
44             required=False,
45             allow_null=True))
46     numDynamicAddresses = serializers.IntegerField(
47         help_text="Number of dynamic addresses to assign.",
48         required=False)
49     addressRange = AddressRangeSerializer(
50         help_text="An IP address range to be used.",
51         required=False)
52     subnetId = serializers.CharField(
53         help_text="Subnet defined by the identifier of the subnet resource in the VIM.",
54         required=False,
55         allow_null=True,
56         allow_blank=True)
57
58
59 class IpAddressesInfoSerialzier(serializers.Serializer):
60     type = serializers.ChoiceField(
61         help_text="The type of the IP addresses.",
62         required=True,
63         choices=IPADDRESSES_TYPE)
64     addresses = serializers.ListField(
65         help_text="An IPV4 or IPV6 address",
66         required=False,
67         allow_null=True)
68     isDynamic = serializers.BooleanField(
69         help_text="Indicates whether this set of addresses was assigned"
70                   " dynamically (true) or based on address information"
71                   " provided as input from the API consumer (false).",
72         required=False)
73     addressRange = AddressRangeSerializer(
74         help_text="An IP address range used,",
75         required=False,
76         allow_null=True)
77     subnetId = serializers.CharField(
78         help_text="Subnet defined by the identifier of the subnet resource in the VIM.",
79         required=False,
80         allow_null=True)
81
82
83 class IpOverEthernetAddressDataSerializer(serializers.Serializer):
84     macAddress = serializers.CharField(
85         help_text="Mac address",
86         required=False,
87         allow_null=True)
88     ipAddresses = IpAddressesDataSerialzier(
89         help_text="List of IP addresses to assign to the extCP instance.",
90         required=False,
91         allow_null=True,
92         many=True)
93
94
95 class IpOverEthernetAddressInfoSerializer(serializers.Serializer):
96     macAddress = serializers.CharField(
97         help_text="Mac address",
98         required=False,
99         allow_null=True)
100     ipAddresses = IpAddressesInfoSerialzier(
101         help_text="List of IP addresses to assign to the extCP instance.",
102         required=False,
103         allow_null=True,
104         many=True)
105
106
107 class CpProtocolDataSerializer(serializers.Serializer):
108     layerProtocol = serializers.ChoiceField(
109         help_text="Identifier of layer(s) and protocol(s)",
110         choices=LAYER_PROTOCOL,
111         required=True)
112     ipOverEthernet = IpOverEthernetAddressDataSerializer(
113         help_text="Network address data for IP over Ethernet to assign to the extCP instance.",
114         required=False,
115         allow_null=True)
116
117
118 class CpProtocolInfoSerializer(serializers.Serializer):
119     layerProtocol = serializers.ChoiceField(
120         help_text="Identifier of layer(s) and protocol(s)",
121         choices=LAYER_PROTOCOL,
122         required=True)
123     ipOverEthernet = IpOverEthernetAddressInfoSerializer(
124         help_text="Network address data for IP over Ethernet to assign to the extCP instance.",
125         required=False,
126         allow_null=True)
127
128
129 class VnfExtCpInfoSerializer(serializers.Serializer):
130     id = serializers.CharField(
131         help_text="Identifier of the external CP instance and the related information instance.",
132         max_length=255,
133         required=True,
134         allow_null=True,
135         allow_blank=False)
136     cpdId = serializers.CharField(
137         help_text="Identifier of the external CPD, VnfExtCpd, in the VNFD.",
138         max_length=255,
139         required=True,
140         allow_null=True,
141         allow_blank=False)
142     cpProtocolInfo = CpProtocolInfoSerializer(
143         help_text="Network protocol information for this CP.",
144         many=True,
145         required=False,
146         allow_null=True)
147     extLinkPortId = serializers.CharField(
148         help_text="Identifier of the extLinkPortInfo structure inside the extVirtualLinkInfo structure.",
149         max_length=255,
150         required=False,
151         allow_null=True,
152         allow_blank=True)