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
17 from lcm.ns.serializers.sol.link import linkSerializer
18 from lcm.ns_pnfs.serializers.pnf_serializer import PnfInstanceSerializer
21 class AddressRangeSerializer(serializers.Serializer):
22 minAddress = serializers.IPAddressField(help_text="Lowest IP address belonging to the range.",
24 maxAddress = serializers.IPAddressField(help_text="Highest IP address belonging to the range.",
28 class IpAddressSerialzier(serializers.Serializer):
29 type = serializers.ChoiceField(help_text="The type of the IP addresses.",
30 required=True, choices=["IPV4", "IPV6"])
31 fixedAddresses = serializers.ListField(child=serializers.CharField(help_text="Fixed addresses to assign.",
32 required=False, allow_null=True))
33 numDynamicAddresses = serializers.IntegerField(help_text="Number of dynamic addresses to assign.",
35 addressRange = AddressRangeSerializer(help_text="An IP address range to be used.", required=False)
36 subnetId = serializers.CharField(help_text="Subnet defined by the identifier of the subnet resource"
37 " in the VIM.", required=False, allow_null=True,
41 class ipAddressesSerializer(serializers.Serializer):
42 type = serializers.ChoiceField(help_text="The type of the IP addresses.",
43 required=True, choices=["IPV4", "IPV6"])
44 addresses = serializers.ListField(help_text="An IPV4 or IPV6 address", required=False, allow_null=True)
45 isDynamic = serializers.BooleanField(help_text="Indicates whether this set of addresses was assigned"
46 " dynamically (true) or based on address information"
47 " provided as input from the API consumer (false). ",
49 addressRange = AddressRangeSerializer(help_text="An IP address range used,",
50 required=False, allow_null=True)
51 subnetId = serializers.CharField(help_text="Subnet defined by the identifier of the subnet resource in "
52 "the VIM. ", required=False, allow_null=True)
55 class Links(serializers.Serializer):
56 self = linkSerializer(help_text="URI of this resource.", required=True)
57 nestedNsInstances = linkSerializer(help_text="Links to the nested NS instances of the present NS"
58 "instance.", required=False, allow_null=True)
59 instantiate = linkSerializer(help_text="Link to the 'instantiate' task resource", required=False,
61 terminate = linkSerializer(help_text="Link to the 'terminate' task resource", required=False, allow_null=True)
62 update = linkSerializer(help_text="Link to the 'update' task resource", required=False, allow_null=True)
63 scale = linkSerializer(help_text="Link to the 'scale' task resource", required=False, allow_null=True)
64 heal = linkSerializer(help_text="Link to the 'heal' task resource", required=False, allow_null=True)
67 class IpOverEthernetAddressDataSerializer(serializers.Serializer):
68 macAddress = serializers.CharField(help_text="Mac address", required=False, allow_null=True)
69 ipAddresses = IpAddressSerialzier(help_text="List of IP addresses to assign to the extCP instance.",
70 required=False, allow_null=True, many=True)
73 class NsOperateJobSerializer(serializers.Serializer):
74 jobId = serializers.CharField(help_text="ID of NS operate job", required=True)
77 class VnfInstSerializer(serializers.Serializer):
78 vnfInstanceId = serializers.CharField(help_text="ID of VNF instance", required=True)
79 vnfInstanceName = serializers.CharField(help_text="Name of VNF instance", required=False, allow_null=True, allow_blank=True)
80 vnfdId = serializers.CharField(help_text="ID of VNFD", required=False, allow_null=True, allow_blank=True)
83 class CpInstInfoSerializer(serializers.Serializer):
84 cpInstanceId = serializers.CharField(help_text="ID of CP instance", required=True)
85 cpInstanceName = serializers.CharField(help_text="Name of CP instance", required=False, allow_null=True, allow_blank=True)
86 cpdId = serializers.CharField(help_text="ID of CPD", required=False, allow_null=True, allow_blank=True)
89 class VlInstSerializer(serializers.Serializer):
90 vlInstanceId = serializers.CharField(help_text="ID of VL instance", required=True)
91 vlInstanceName = serializers.CharField(help_text="Name of VL instance", required=False, allow_null=True, allow_blank=True)
92 vldId = serializers.CharField(help_text="ID of VLD", required=False, allow_null=True, allow_blank=True)
93 relatedCpInstanceId = CpInstInfoSerializer(help_text="Related CP instances", many=True)
96 class VnffgInstSerializer(serializers.Serializer):
97 vnffgInstanceId = serializers.CharField(help_text="ID of VNFFG instance", required=True)
98 vnfdId = serializers.CharField(help_text="ID of VNFD", required=False, allow_null=True, allow_blank=True)
99 pnfId = serializers.CharField(help_text="ID of PNF", required=False, allow_null=True, allow_blank=True)
100 virtualLinkId = serializers.CharField(help_text="ID of virtual link", required=False, allow_null=True, allow_blank=True)
101 cpdId = serializers.CharField(help_text="ID of CPD", required=False, allow_null=True, allow_blank=True)
102 nfp = serializers.CharField(help_text="nfp", required=False, allow_null=True, allow_blank=True)
105 class QueryNsRespSerializer(serializers.Serializer):
106 nsInstanceId = serializers.CharField(help_text="ID of NS instance", required=True)
107 nsName = serializers.CharField(help_text="Name of NS instance", required=False, allow_null=True, allow_blank=True)
108 description = serializers.CharField(help_text="Description of NS instance", required=False, allow_null=True, allow_blank=True)
109 nsdId = serializers.CharField(help_text="ID of NSD", required=True)
110 vnfInfo = VnfInstSerializer(help_text="VNF instances", many=True, required=False, allow_null=True)
111 pnfInfo = PnfInstanceSerializer(help_text="PNF instances", many=True, required=False, allow_null=True)
112 vlInfo = VlInstSerializer(help_text="VL instances", many=True, required=False, allow_null=True)
113 vnffgInfo = VnffgInstSerializer(help_text="VNFFG instances", many=True, required=False, allow_null=True)
114 nsState = serializers.CharField(help_text="State of NS instance", required=False, allow_null=True, allow_blank=True)
117 class CpProtocolDataSerializer(serializers.Serializer):
118 layerProtocol = serializers.ChoiceField(help_text="Identifier of layer(s) and protocol(s)",
119 choices=["IP_OVER_ETHERNET"], required=True)
120 ipOverEthernet = IpOverEthernetAddressDataSerializer(help_text="Network address data for IP over Ethernet"
121 "to assign to the extCP instance.",
122 required=False, allow_null=True)