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