1 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 from rest_framework import serializers
16 from lcm.ns.const import IPADDRESSES_TYPES
19 IPADDRESSES_TYPES.IPV4,
20 IPADDRESSES_TYPES.IPV6
27 class AddressRangeSerializer(serializers.Serializer):
28 minAddress = serializers.IPAddressField(
29 help_text="Lowest IP address belonging to the range.",
31 maxAddress = serializers.IPAddressField(
32 help_text="Highest IP address belonging to the range.",
36 class IpAddressesDataSerialzier(serializers.Serializer):
37 type = serializers.ChoiceField(
38 help_text="The type of the IP addresses.",
40 choices=IPADDRESSES_TYPE)
41 fixedAddresses = serializers.ListField(
42 child=serializers.CharField(
43 help_text="Fixed addresses to assign.",
46 numDynamicAddresses = serializers.IntegerField(
47 help_text="Number of dynamic addresses to assign.",
49 addressRange = AddressRangeSerializer(
50 help_text="An IP address range to be used.",
52 subnetId = serializers.CharField(
53 help_text="Subnet defined by the identifier of the subnet resource in the VIM.",
59 class IpAddressesInfoSerialzier(serializers.Serializer):
60 type = serializers.ChoiceField(
61 help_text="The type of the IP addresses.",
63 choices=IPADDRESSES_TYPE)
64 addresses = serializers.ListField(
65 help_text="An IPV4 or IPV6 address",
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).",
73 addressRange = AddressRangeSerializer(
74 help_text="An IP address range used,",
77 subnetId = serializers.CharField(
78 help_text="Subnet defined by the identifier of the subnet resource in the VIM.",
83 class IpOverEthernetAddressDataSerializer(serializers.Serializer):
84 macAddress = serializers.CharField(
85 help_text="Mac address",
88 ipAddresses = IpAddressesDataSerialzier(
89 help_text="List of IP addresses to assign to the extCP instance.",
95 class IpOverEthernetAddressInfoSerializer(serializers.Serializer):
96 macAddress = serializers.CharField(
97 help_text="Mac address",
100 ipAddresses = IpAddressesInfoSerialzier(
101 help_text="List of IP addresses to assign to the extCP instance.",
107 class CpProtocolDataSerializer(serializers.Serializer):
108 layerProtocol = serializers.ChoiceField(
109 help_text="Identifier of layer(s) and protocol(s)",
110 choices=LAYER_PROTOCOL,
112 ipOverEthernet = IpOverEthernetAddressDataSerializer(
113 help_text="Network address data for IP over Ethernet to assign to the extCP instance.",
118 class CpProtocolInfoSerializer(serializers.Serializer):
119 layerProtocol = serializers.ChoiceField(
120 help_text="Identifier of layer(s) and protocol(s)",
121 choices=LAYER_PROTOCOL,
123 ipOverEthernet = IpOverEthernetAddressInfoSerializer(
124 help_text="Network address data for IP over Ethernet to assign to the extCP instance.",
129 class VnfExtCpInfoSerializer(serializers.Serializer):
130 id = serializers.CharField(
131 help_text="Identifier of the external CP instance and the related information instance.",
136 cpdId = serializers.CharField(
137 help_text="Identifier of the external CPD, VnfExtCpd, in the VNFD.",
142 cpProtocolInfo = CpProtocolInfoSerializer(
143 help_text="Network protocol information for this CP.",
147 extLinkPortId = serializers.CharField(
148 help_text="Identifier of the extLinkPortInfo structure inside the extVirtualLinkInfo structure.",