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