improve enum in serializers
[vfc/nfvo/lcm.git] / lcm / ns / serializers / sol / ns_instance.py
index f8e3d82..b8024d5 100644 (file)
@@ -21,54 +21,45 @@ from lcm.ns.serializers.sol.resource_handle import ResourceHandleSerializer
 from lcm.ns.serializers.sol.ext_virtual_link_info import ExtVirtualLinkInfoSerializer
 from lcm.ns.serializers.sol.ext_managed_virtual_link_info import ExtManagedVirtualLinkInfo, VnfLinkPortInfo
 from lcm.ns.serializers.sol.pub_serializers import AffinityOrAntiAffinityRuleSerializer
-
-
-INSTANTIATION_STATE = [
-    "NOT_INSTANTIATED",
-    "INSTANTIATED"
-]
+from lcm.ns.enum import IPADDRESSES_TYPE, INSTANTIATION_STATE, VNF_STATE, NFP_STATE, PROTOCOL
+from lcm.pub.utils.enumutil import enum_to_list
 
 
 class VnfScaleInfoSerializer(serializers.Serializer):
-    aspectlId = serializers.Serializer(help_text="The scaling aspect", required=True)
-    scaleLevel = serializers.Serializer(help_text="The scale level for that aspect", required=True)
+    aspectlId = serializers.Serializer(
+        help_text="Identifier of the scaling aspect",
+        required=True)
+    scaleLevel = serializers.Serializer(
+        help_text="The scale level for that aspect.",
+        required=True)
 
 
 class NsScaleInfoSerializer(serializers.Serializer):
-    nsScalingAspectId = serializers.CharField(help_text="Identifier of the NS scaling aspect.", required=True)
-    nsScaleLevelId = serializers.CharField(help_text="Identifier of the NS scale level.", required=True)
+    nsScalingAspectId = serializers.CharField(
+        help_text="Identifier of the NS scaling aspect.",
+        required=True)
+    nsScaleLevelId = serializers.CharField(
+        help_text="Identifier of the NS scale level.",
+        required=True)
 
 
 class VnfcCpInfo(serializers.Serializer):
     id = serializers.CharField(
         help_text="Identifier of the external CP instance and the related information instance.",
-        max_length=255,
-        required=True,
-        allow_null=False,
-        allow_blank=False)
+        required=True)
     cpdId = serializers.CharField(
         help_text="Identifier of the external CPD, VnfExtCpd, in the VNFD.",
-        max_length=255,
-        required=True,
-        allow_null=False,
-        allow_blank=False)
+        required=True)
     vnfExtCpId = serializers.CharField(
         help_text="When the VNFC CP is exposed as external CP of the VNF, the identifier of this external VNF CP.",
-        required=False,
-        max_length=255,
-        allow_null=True,
-        allow_blank=True)
+        required=False)
     cpProtocolInfo = CpProtocolInfoSerializer(
         help_text="Network protocol information for this CP.",
         many=True,
-        required=False,
-        allow_null=True)
+        required=False)
     vnfLinkPortId = serializers.CharField(
         help_text="Identifier of the vnfLinkPorts structure in the vnfVirtualLinkResourceInfo structure.",
-        max_length=255,
-        required=True,
-        allow_null=False,
-        allow_blank=False)
+        required=True)
 
 
 class VnfcResourceInfoSerializer(serializers.Serializer):
@@ -87,8 +78,7 @@ class VnfcResourceInfoSerializer(serializers.Serializer):
         required=True,
         allow_null=False)
     storageResourceIds = serializers.ListSerializer(
-        help_text="References to the VirtualStorage resources. \
-        The value refers to a VirtualStorageResourceInfo item in the VnfInstance.",
+        help_text="References to the VirtualStorage resources. The value refers to a VirtualStorageResourceInfo item in the VnfInstance.",
         child=serializers.CharField(help_text="Identifier In Vnf", allow_blank=True),
         required=False,
         allow_null=True)
@@ -99,16 +89,13 @@ class VnfcResourceInfoSerializer(serializers.Serializer):
         allow_null=True,
         allow_blank=True)
     vnfcCpInfo = VnfcCpInfo(
-        help_text="CPs of the VNFC instance. \
-        Shall be present when that particular CP of the VNFC instance is associated to an external CP of the VNF instance.",
+        help_text="CPs of the VNFC instance. Shall be present when that particular CP of the VNFC instance is associated to an external CP of the VNF instance.",
         many=True,
         required=False,
         allow_null=True)
     metadata = serializers.DictField(
         help_text="Metadata about this resource.",
-        child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
-        required=False,
-        allow_null=True)
+        required=False)
 
 
 # class VnfLinkPortInfo(serializers.Serializer):
@@ -206,7 +193,7 @@ class InstantiatedVnfInfo(serializers.Serializer):
         allow_blank=False)
     vnfState = serializers.ChoiceField(
         help_text="State of the VNF instance.",
-        choices=["STARTED", "STOPPED"],
+        choices=enum_to_list(VNF_STATE),
         required=True,
         allow_null=True,
         allow_blank=False)
@@ -369,7 +356,7 @@ class VnfInstanceSerializer(serializers.Serializer):
         required=False)
     instantiationState = serializers.ChoiceField(
         help_text="The instantiation state of the VNF.",
-        choices=INSTANTIATION_STATE,
+        choices=enum_to_list(INSTANTIATION_STATE),
         required=True,
         allow_null=False,
         allow_blank=False)
@@ -397,23 +384,40 @@ class VnfInstanceSerializer(serializers.Serializer):
 
 
 class PnfExtCpInfoSerializer(serializers.Serializer):
-    cpInstanceId = serializers.CharField(help_text="Identifier of the CP in the scope of the PNF.",
-                                         required=True)
+    cpInstanceId = serializers.CharField(
+        help_text="Identifier of the CP in the scope of the PNF.",
+        required=True)
 
-    cpdId = serializers.CharField(help_text="Identifier of (reference to) the Connection Point Descriptor"
-                                            "(CPD) for this CP.", required=True)
+    cpdId = serializers.CharField(
+        help_text="Identifier of (reference to) the Connection Point Descriptor (CPD) for this CP.",
+        required=True)
 
-    cpProtocolData = CpProtocolDataSerializer(help_text="Parameters for configuring the network protocols on"
-                                                        "the CP.", required=True, many=True)
+    cpProtocolData = CpProtocolDataSerializer(
+        help_text="Parameters for configuring the network protocols on the CP.",
+        required=True,
+        many=True)
 
 
 class PnfInfoSerializer(serializers.Serializer):
-    pnfId = serializers.CharField(help_text="Identifier of the PNF.", required=True)
-    pnfName = serializers.CharField(help_text="Name of the PNF.", required=True)
-    pnfdId = serializers.CharField(help_text="Identifier of the PNFD on which the PNF is based.", required=True)
-    pnfdInfoId = serializers.CharField(help_text="Identifier of the PNFD information onject related to this PNF.", required=True)
-    pnfProfileId = serializers.CharField(help_text="Identifier of the related PnfProfile in the NSD on which the PNF is based.", required=True)
-    cpInfo = PnfExtCpInfoSerializer(help_text="Information on the external CP of the PNF", required=True, many=True)
+    pnfId = serializers.CharField(
+        help_text="Identifier of the PNF.",
+        required=True)
+    pnfName = serializers.CharField(
+        help_text="Name of the PNF.",
+        required=True)
+    pnfdId = serializers.CharField(
+        help_text="Identifier of the PNFD on which the PNF is based.",
+        required=True)
+    pnfdInfoId = serializers.CharField(
+        help_text="Identifier of the PNFD information onject related to this PNF.",
+        required=True)
+    pnfProfileId = serializers.CharField(
+        help_text="Identifier of the related PnfProfile in the NSD on which the PNF is based.",
+        required=True)
+    cpInfo = PnfExtCpInfoSerializer(
+        help_text="Information on the external CP of the PNF",
+        required=True,
+        many=True)
 
 
 class NsLinkPortInfo(serializers.Serializer):
@@ -437,106 +441,181 @@ class NsLinkPortInfo(serializers.Serializer):
 
 
 class NsVirtualLinkInfoSerializer(serializers.Serializer):
-    id = serializers.CharField(help_text="Identifier of the VL instance.", required=True)
-    nsVirtualLinkDescId = serializers.CharField(help_text="Identifier of the VLD in the NSD.", required=True)
-    nsVirtualLinkProfileId = serializers.CharField(help_text="Identifier of the VL profile in the NSD.", required=True)
-    resourceHandle = ResourceHandleSerializer(help_text="Identifier(s) of the virtualised network resource(s) realizing the VL instance", required=True, many=True)
-    linkPort = NsLinkPortInfo(help_text="Link ports of this VL.", many=True, required=False, allow_null=True)
+    id = serializers.CharField(
+        help_text="Identifier of the VL instance.",
+        required=True)
+    nsVirtualLinkDescId = serializers.CharField(
+        help_text="Identifier of the VLD in the NSD.",
+        required=True)
+    nsVirtualLinkProfileId = serializers.CharField(
+        help_text="Identifier of the VL profile in the NSD.",
+        required=True)
+    resourceHandle = ResourceHandleSerializer(
+        help_text="Identifier(s) of the virtualised network resource(s) realizing the VL instance",
+        required=True,
+        many=True)
+    linkPort = NsLinkPortInfo(
+        help_text="Link ports of this VL.",
+        many=True,
+        required=False,
+        allow_null=True)
 
 
 class NsCpHandleSerializer(serializers.Serializer):
-    vnfInstanceId = serializers.CharField(help_text="Identifier of the VNF instance associated to the CP"
-                                                    "instance.", required=False, allow_null=True)
-    vnfExtCpInstanceId = serializers.CharField(help_text="Identifier of the VNF external CP instance in the"
-                                                         "scope of the VNF instance.",
-                                               required=False, allow_null=True)
-    pnfInfoId = serializers.CharField(help_text="Identifier of the PNF instance associated to the CP"
-                                                "instance.", required=False, allow_null=True)
-    pnfExtCpInstanceId = serializers.CharField(help_text="Identifier of the PNF external CP instance in the"
-                                                         "scope of the PNF.", required=False, allow_null=True)
-    nsInstanceId = serializers.CharField(help_text="Identifier of the NS instance associated to the SAP"
-                                                   "instance", required=False, allow_null=True)
-    nsSapInstanceId = serializers.CharField(help_text="Identifier of the SAP instance in the scope of the NS"
-                                                      "instance.", required=False, allow_null=True)
+    vnfInstanceId = serializers.CharField(
+        help_text="Identifier of the VNF instance associated to the CP instance.",
+        required=False,
+        allow_null=True)
+    vnfExtCpInstanceId = serializers.CharField(
+        help_text="Identifier of the VNF external CP instance in the scope of the VNF instance.",
+        required=False,
+        allow_null=True)
+    pnfInfoId = serializers.CharField(
+        help_text="Identifier of the PNF instance associated to the CP instance.",
+        required=False,
+        allow_null=True)
+    pnfExtCpInstanceId = serializers.CharField(
+        help_text="Identifier of the PNF external CP instance in the scope of the PNF.",
+        required=False,
+        allow_null=True)
+    nsInstanceId = serializers.CharField(
+        help_text="Identifier of the NS instance associated to the SAP instance",
+        required=False,
+        allow_null=True)
+    nsSapInstanceId = serializers.CharField(
+        help_text="Identifier of the SAP instance in the scope of the NS instance.",
+        required=False,
+        allow_null=True)
 
 
 class MaskSerializer(serializers.Serializer):
-    startingPoint = serializers.CharField(help_text="Indicates the offset between the last bit of the source"
-                                                    "mac address and the first bit of the sequence of bits"
-                                                    "to be matched.", required=True)
-    length = serializers.CharField(help_text="Indicates the number of bits to be matched", required=True)
-    value = serializers.CharField(help_text="Provide the sequence of bit values to be matched.",
-                                  required=True)
+    startingPoint = serializers.CharField(
+        help_text="Indicates the offset between the last bit of the source mac address and the first bit of the sequence of bits to be matched.",
+        required=True)
+    length = serializers.CharField(
+        help_text="Indicates the number of bits to be matched.",
+        required=True)
+    value = serializers.CharField(
+        help_text="Provide the sequence of bit values to be matched.",
+        required=True)
 
 
 class NfpRuleSerializer(serializers.Serializer):
-    etherDestinationAddress = serializers.CharField(help_text="Indicates a destination Mac address",
-                                                    required=False, allow_null=True)
-    etherSourceAddress = serializers.CharField(help_text="Indicates a source Mac address",
-                                               required=False, allow_null=True)
-    etherType = serializers.ChoiceField(help_text="Indicates the protocol carried over the Ethernet layer",
-                                        choices=["IPV4", "IPV6"], required=False, allow_null=True)
-    vlanTag = serializers.ListField(help_text="ndicates a VLAN identifier in an IEEE 802.1Q-2014 tag",
-                                    required=False, allow_null=True)
-    protocol = serializers.ChoiceField(help_text="Indicates the L4 protocol, For IPv4 [7] this corresponds to"
-                                                 "the field called Protocol to identifythe next level "
-                                                 "protocol", choices=["TCP", "UDP", "ICMP"],
-                                       required=False, allow_null=True)
-    dscp = serializers.CharField(help_text="For IPv4 [7] a string of 0 and 1 digits that corresponds to the"
-                                           "6-bit Differentiated Services Code Point (DSCP) field of the"
-                                           "IP header.", required=False, allow_null=True)
-    sourcePortRange = serializers.CharField(help_text="Indicates a range of source ports",
-                                            required=False, allow_null=True)
-    destinationPortRange = serializers.CharField(help_text="Indicates a range of destination ports",
-                                                 required=False, allow_null=True)
-    sourceIpAddressPrefix = serializers.CharField(help_text="Indicates the source IP address range in CIDR"
-                                                            "format.", required=False, allow_null=True)
-    destinationIpAddressPrefix = serializers.CharField(help_text="Indicates the destination IP address range"
-                                                                 "in CIDRformat.",
-                                                       required=False, allow_null=True)
-    extendedCriteria = MaskSerializer(help_text="Indicates values of specific bits in a frame",
-                                      required=False, allow_null=True, many=True)
+    etherDestinationAddress = serializers.CharField(
+        help_text="Indicates a destination Mac address",
+        required=False,
+        allow_null=True)
+    etherSourceAddress = serializers.CharField(
+        help_text="Indicates a source Mac address",
+        required=False,
+        allow_null=True)
+    etherType = serializers.ChoiceField(
+        help_text="Indicates the protocol carried over the Ethernet layer",
+        choices=enum_to_list(IPADDRESSES_TYPE),
+        required=False,
+        allow_null=True)
+    vlanTag = serializers.ListField(
+        help_text="ndicates a VLAN identifier in an IEEE 802.1Q-2014 tag",
+        required=False,
+        allow_null=True)
+    protocol = serializers.ChoiceField(
+        help_text="Indicates the L4 protocol, For IPv4 [7] this corresponds to"
+                  "the field called Protocol to identifythe next level protocol",
+        choices=enum_to_list(PROTOCOL),
+        required=False,
+        allow_null=True)
+    dscp = serializers.CharField(
+        help_text="For IPv4 [7] a string of 0 and 1 digits that corresponds to the"
+                  "6-bit Differentiated Services Code Point (DSCP) field of the IP header.",
+        required=False,
+        allow_null=True)
+    sourcePortRange = serializers.CharField(
+        help_text="Indicates a range of source ports",
+        required=False,
+        allow_null=True)
+    destinationPortRange = serializers.CharField(
+        help_text="Indicates a range of destination ports",
+        required=False,
+        allow_null=True)
+    sourceIpAddressPrefix = serializers.CharField(
+        help_text="Indicates the source IP address range in CIDR format.",
+        required=False,
+        allow_null=True)
+    destinationIpAddressPrefix = serializers.CharField(
+        help_text="Indicates the destination IP address range in CIDR format.",
+        required=False,
+        allow_null=True)
+    extendedCriteria = MaskSerializer(
+        help_text="Indicates values of specific bits in a frame",
+        required=False,
+        allow_null=True,
+        many=True)
 
 
 class NfpInfoSerializer(serializers.Serializer):
-    id = serializers.CharField(help_text="Identifier of this NFP instance.", required=True)
-    nfpdId = serializers.CharField(help_text="Identifier of the NFPD used to instantiate this NFP"
-                                             "instance.", required=False, allow_null=True)
-    nfpName = serializers.CharField(help_text="Human readable name for the NFP instance.",
-                                    required=False, allow_null=True)
-    description = serializers.CharField(help_text="Human readable description for the NFP instance.",
-                                        required=True)
-    nscpHandle = NsCpHandleSerializer(help_text="Identifier(s) of the CPs and/or SAPs which the NFP "
-                                                "passes by", required=True, many=True)
-    totalCp = serializers.CharField(help_text="Total number of CP and SAP instances in this NFP"
-                                              "instance.", required=False, allow_null=True)
-    nfpRule = NfpRuleSerializer(help_text="The NfpRule data type is an expression of the conditions that "
-                                          "shall be met in order for the NFP to be applicable to the packet",
-                                required=True)
-    nfpState = serializers.ChoiceField(help_text="The state of the NFP instance.",
-                                       choices=["ENABLED", "DISABLED"], required=True)
+    id = serializers.CharField(
+        help_text="Identifier of this NFP instance.",
+        required=True)
+    nfpdId = serializers.CharField(
+        help_text="Identifier of the NFPD used to instantiate this NFP instance.",
+        required=False,
+        allow_null=True)
+    nfpName = serializers.CharField(
+        help_text="Human readable name for the NFP instance.",
+        required=False,
+        allow_null=True)
+    description = serializers.CharField(
+        help_text="Human readable description for the NFP instance.",
+        required=True)
+    nscpHandle = NsCpHandleSerializer(
+        help_text="Identifier(s) of the CPs and/or SAPs which the NFP passes by",
+        required=True,
+        many=True)
+    totalCp = serializers.CharField(
+        help_text="Total number of CP and SAP instances in this NFP instance.",
+        required=False,
+        allow_null=True)
+    nfpRule = NfpRuleSerializer(
+        help_text="The NfpRule data type is an expression of the conditions that shall be met in order for the NFP to be applicable to the packet",
+        required=True)
+    nfpState = serializers.ChoiceField(
+        help_text="The state of the NFP instance.",
+        choices=enum_to_list(NFP_STATE),
+        required=True)
 
 
 class VnffgInfoSerializer(serializers.Serializer):
-    id = serializers.CharField(help_text="Identifier of this VNFFG instance.", required=True)
-    vnffgdId = serializers.CharField(help_text="Identifier of the VNFFGD in the NSD.", required=True)
-    vnfInstanceId = serializers.ListField(help_text="Identifier(s) of the constituent VNF instance(s) of this"
-                                                    "VNFFG instance.",
-                                          child=serializers.CharField(help_text="ID of vnf instance"),
-                                          required=True)
-    pnfInfoId = serializers.ListField(help_text="Identifier(s) of the constituent PNF instance(s) of this"
-                                                "VNFFG instance",
-                                      child=serializers.CharField(help_text="ID of pnf info"),
-                                      required=False, allow_null=True)
-    nsVirtualLinkInfoId = serializers.ListField(help_text="Identifier(s) of the constituent VL instance(s) of"
-                                                          "thisVNFFG instance.",
-                                                child=serializers.CharField(
-                                                    help_text="ID of ns virtual link info"), required=True)
-    nsCpHandle = NsCpHandleSerializer(help_text="Identifiers of the CP instances attached to the "
-                                                "constituent VNFs and PNFs or the SAP instances of "
-                                                "the VNFFG.", required=True, allow_null=False, many=True)
-    nfpInfo = NfpInfoSerializer(help_text="Information on the NFP instances.",
-                                required=True, allow_null=False, many=True)
+    id = serializers.CharField(
+        help_text="Identifier of this VNFFG instance.",
+        required=True)
+    vnffgdId = serializers.CharField(
+        help_text="Identifier of the VNFFGD in the NSD.",
+        required=True)
+    vnfInstanceId = serializers.ListField(
+        help_text="Identifier(s) of the constituent VNF instance(s) of this VNFFG instance.",
+        child=serializers.CharField(
+            help_text="ID of vnf instance"),
+        required=True)
+    pnfInfoId = serializers.ListField(
+        help_text="Identifier(s) of the constituent PNF instance(s) of this VNFFG instance",
+        child=serializers.CharField(help_text="ID of pnf info"),
+        required=False,
+        allow_null=True)
+    nsVirtualLinkInfoId = serializers.ListField(
+        help_text="Identifier(s) of the constituent VL instance(s) of thisVNFFG instance.",
+        child=serializers.CharField(help_text="ID of ns virtual link info"),
+        required=True)
+    nsCpHandle = NsCpHandleSerializer(
+        help_text="Identifiers of the CP instances attached to the "
+                  "constituent VNFs and PNFs or the SAP instances of the VNFFG.",
+        required=True,
+        allow_null=False,
+        many=True)
+    nfpInfo = NfpInfoSerializer(
+        help_text="Information on the NFP instances.",
+        required=True,
+        allow_null=False,
+        many=True)
 
 
 class SapInfo(serializers.Serializer):
@@ -632,11 +711,10 @@ class NsInstanceSerializer(serializers.Serializer):
         help_text="Identifier of the nested NS(s) of the NS instance.",
         child=serializers.CharField(),
         required=False,
-        allow_null=True
-    )
+        allow_null=True)
     nsState = serializers.ChoiceField(
         help_text="The state of the NS instance.",
-        choices=["NOT_INSTANTIATED", "INSTANTIATED"],
+        choices=enum_to_list(INSTANTIATION_STATE),
         required=True,
         allow_null=True)
     nsScaleStatus = NsScaleInfoSerializer(
@@ -645,8 +723,10 @@ class NsInstanceSerializer(serializers.Serializer):
         allow_null=True,
         many=True)
     additionalAffinityOrAntiAffinityRule = AffinityOrAntiAffinityRuleSerializer(
+        help_text="Specifies additional affinity or anti-affinity constraint for the VNF instances to be instantiated as part of the NS instantiation.",
         many=True,
         required=False,
-        allow_null=True,
-        help_text="Specifies additional affinity or anti-affinity constraint for the VNF instances to be instantiated as part of the NS instantiation.")
-    _links = NsLinkSerializer(help_text="The links of the NS instance.", required=True)
+        allow_null=True)
+    _links = NsLinkSerializer(
+        help_text="The links of the NS instance.",
+        required=True)