improve enum in serializers 52/85752/1
authormaopengzhang <zhang.maopeng1@zte.com.cn>
Fri, 19 Apr 2019 06:22:12 +0000 (14:22 +0800)
committermaopengzhang <zhang.maopeng1@zte.com.cn>
Fri, 19 Apr 2019 06:22:12 +0000 (14:22 +0800)
improve enum in serializers

Change-Id: I5ca15132f036cc05f7917efb58f69cf1d3f0d6a3
Issue-ID: VFC-1241
Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
lcm/ns/enum.py
lcm/ns/serializers/sol/ext_managed_virtual_link_info.py
lcm/ns/serializers/sol/heal_serializers.py
lcm/ns/serializers/sol/lccn_filter_data.py
lcm/ns/serializers/sol/ns_instance.py
lcm/ns/serializers/sol/ns_lcm_op_occ.py
lcm/ns/serializers/sol/pub_serializers.py
lcm/ns/serializers/sol/scale_ns_serializers.py
lcm/ns/serializers/sol/subscription_auth_data.py
lcm/ns/serializers/sol/update_serializers.py

index 5e22f66..3db2211 100644 (file)
@@ -18,6 +18,16 @@ ACTION_TYPE = enum(
     STOP=2,
     REBOOT=3
 )
+AFFINITY_OR_ANTIAFFIINTY = enum(
+    AFFINITY="AFFINITY",
+    ANTI_AFFINITY="ANTI_AFFINITY"
+)
+AFFINITY_OR_ANTIAFFIINTY_SCOPE = enum(
+    NFVI_POP="NFVI_POP",
+    ZONE="ZONE",
+    ZONE_GROUP="ZONE_GROUP",
+    NFVI_NODE="NFVI_NODE"
+)
 AUTH_TYPE = enum(
     BASIC="BASIC",
     OAUTH2_CLIENT_CREDENTIALS="OAUTH2_CLIENT_CREDENTIALS",
@@ -46,6 +56,16 @@ CHANGE_TYPE = enum(
     ADD_LINK_PORT='ADD_LINK_PORT',
     REMOVE_LINK_PORT='REMOVE_LINK_PORT'
 )
+CP_INSTANCE_TYPE = enum(
+    VNFC_CP='VNFC_CP',
+    EXT_CP='EXT_CP'
+)
+DEGREE_HEALING = enum(
+    HEAL_RESTORE="HEAL_RESTORE",
+    HEAL_QOS="HEAL_QOS",
+    HEAL_RESET="HEAL_RESET",
+    PARTIAL_HEALING="PARTIAL_HEALING"
+)
 GRANT_TYPE = enum(
     INSTANTIATE="INSTANTIATE",
     TERMINATE="TERMINATE",
@@ -57,6 +77,10 @@ HEAL_ACTION_TYPE = enum(
     START="vmCreate",
     RESTART="vmReset"
 )
+INSTANTIATION_STATE = enum(
+    NOT_INSTANTIATED="NOT_INSTANTIATED",
+    INSTANTIATED="INSTANTIATED"
+)
 IPADDRESSES_TYPE = enum(
     IPV4='IPV4',
     IPV6='IPV6'
@@ -68,6 +92,16 @@ LCM_NOTIFICATION_STATUS = enum(
 LAYER_PROTOCOL = enum(
     IP_OVER_ETHERNET="IP_OVER_ETHERNET"
 )
+NFP_STATE = enum(
+    ENABLED="ENABLED",
+    DISABLED="DISABLED"
+)
+NOTIFICATION_TYPE = enum(
+    NSLCM_OPERATION_OCCURRENCE_NOTIFICATION="NsLcmOperationOccurrenceNotification",
+    NS_IDENTIFIER_CREATION_NOTIFICATION="NsIdentifierCreationNotification",
+    NS_IDENTIFIER_DELETION_NOTIFICATION="NsIdentifierDeletionNotification",
+    NS_CHANGE_NOTIFICATION="NsChangeNotification"
+)
 NS_COMPOMENT_TYPE = enum(
     VNF="VNF",
     PNF="PNF",
@@ -100,6 +134,10 @@ OPERATION_TYPE = enum(
     UPDATE="UPDATE",
     HEAL="HEAL",
 )
+OPERATIONAL_STATE = enum(
+    STARTED="STARTED",
+    STOPPED="STOPPED"
+)
 OPNAME_FOR_CHANGE_NOTIFICATION_TYPE = enum(
     VNF_INSTANTIATE="VNF_INSTANTIATE",
     VNF_SCALE="VNF_SCALE",
@@ -128,6 +166,30 @@ OWNER_TYPE = enum(
     VNFM=1,
     NS=2
 )
+PROTOCOL = enum(
+    TCP="TCP",
+    UDP="UDP",
+    ICMP="ICMP"
+)
+SCALE_TYPE = enum(
+    SCALE_NS="SCALE_NS",
+    SCALE_VNF="SCALE_VNF"
+)
+SCALE_VNF_TYPE = enum(
+    SCALE_OUT="SCALE_OUT",
+    SCALE_IN="SCALE_IN",
+    SCALE_TO_INSTANTIATION_LEVEL="SCALE_TO_INSTANTIATION_LEVEL",
+    SCALE_TO_SCALE_LEVEL="SCALE_TO_SCALE_LEVEL(S)"
+)
+
+SCALING_DIRECTION = enum(
+    SCALE_IN="SCALE_IN",
+    SCALE_OUT="SCALE_OUT"
+)
+STOP_TYPE = enum(
+    FORCEFUL="FORCEFUL",
+    GRACEFUL="GRACEFUL"
+)
 VNF_STATUS = enum(
     NULL='null',
     INSTANTIATING="instantiating",
@@ -140,3 +202,7 @@ VNF_STATUS = enum(
     UPDATING="updating",
     HEALING="healing"
 )
+VNF_STATE = enum(
+    STARTED="STARTED",
+    STOPPED="STOPPED"
+)
index 3e6bbb7..3cfc0d5 100644 (file)
@@ -14,6 +14,8 @@
 
 from rest_framework import serializers
 from lcm.ns.serializers.sol.resource_handle import ResourceHandleSerializer
+from lcm.ns.enum import CP_INSTANCE_TYPE
+from lcm.pub.utils.enumutil import enum_to_list
 
 
 class VnfLinkPortInfo(serializers.Serializer):
@@ -37,7 +39,7 @@ class VnfLinkPortInfo(serializers.Serializer):
         allow_blank=True)
     cpInstanceType = serializers.ChoiceField(
         required=False,
-        choices=['VNFC_CP', 'EXT_CP'],
+        choices=enum_to_list(CP_INSTANCE_TYPE),
         help_text="Type of the CP instance that is identified by cpInstanceId.")
 
 
index a699056..85415be 100644 (file)
@@ -14,6 +14,8 @@
 # limitations under the License.
 
 from rest_framework import serializers
+from lcm.ns.enum import DEGREE_HEALING
+from lcm.pub.utils.enumutil import enum_to_list
 
 
 # class ActionVmSerializer(serializers.Serializer):
@@ -45,7 +47,7 @@ class HealVnfDataSerializer(serializers.Serializer):
 class HealNsDataSerializer(serializers.Serializer):
     degreeHealing = serializers.ChoiceField(
         help_text="Indicates the degree of healing.",
-        choices=["HEAL_RESTORE", "HEAL_QOS", "HEAL_RESET", "PARTIAL_HEALING"],
+        choices=enum_to_list(DEGREE_HEALING),
         required=True)
     actionsHealing = serializers.ListField(
         help_text="Used to specify dedicated healing actions in a particular order",
index dd25905..d9b2005 100644 (file)
@@ -16,8 +16,8 @@
 from rest_framework import serializers
 
 from ns_instance_subscription_filter import NsInstanceSubscriptionFilter
-from lcm.ns.const import NOTIFICATION_TYPES, NS_LCM_OP_TYPES, LCM_OPERATION_STATE_TYPES, NS_COMPOMENT_TYPE,\
-    LCM_OPName_For_Change_Notification_Type, LCM_OpOcc_Status_For_ChangeNotification_Type
+from lcm.ns.enum import NOTIFICATION_TYPE, OPERATION_TYPE, OPERATION_STATE_TYPE, NS_COMPOMENT_TYPE, OPNAME_FOR_CHANGE_NOTIFICATION_TYPE, OPOCC_STATUS_FOR_CHANGENOTIFICATION_TYPE
+from lcm.pub.utils.enumutil import enum_to_list
 
 
 class LifeCycleChangeNotificationsFilter(serializers.Serializer):
@@ -27,31 +27,31 @@ class LifeCycleChangeNotificationsFilter(serializers.Serializer):
         allow_null=False)
     notificationTypes = serializers.ListField(
         help_text="Match particular notification types.",
-        child=serializers.ChoiceField(required=True, choices=NOTIFICATION_TYPES),
+        child=serializers.ChoiceField(required=True, choices=enum_to_list(NOTIFICATION_TYPE)),
         required=False,
         allow_null=False)
     operationTypes = serializers.ListField(
         help_text="Match particular NS lifecycle operation types for the notification of type NsLcmOperationOccurrenceNotification.",
-        child=serializers.ChoiceField(required=True, choices=NS_LCM_OP_TYPES),
+        child=serializers.ChoiceField(required=True, choices=enum_to_list(OPERATION_TYPE)),
         required=False,
         allow_null=False)
     operationStates = serializers.ListField(
         help_text="Match particular LCM operation state values as reported in notifications of type NsLcmOperationOccurrenceNotification.",
-        child=serializers.ChoiceField(required=True, choices=LCM_OPERATION_STATE_TYPES),
+        child=serializers.ChoiceField(required=True, choices=enum_to_list(OPERATION_STATE_TYPE)),
         required=False,
         allow_null=False)
     nsComponentTypes = serializers.ListField(
         help_text="Match particular NS component types for the notification of type NsChangeNotification. ",
-        child=serializers.ChoiceField(required=True, choices=NS_COMPOMENT_TYPE),
+        child=serializers.ChoiceField(required=True, choices=enum_to_list(NS_COMPOMENT_TYPE)),
         required=False,
         allow_null=False)
     lcmOpNameImpactingNsComponent = serializers.ListField(
         help_text="Match particular LCM operation names for the notification of type NsChangeNotification.",
-        child=serializers.ChoiceField(required=True, choices=LCM_OPName_For_Change_Notification_Type),
+        child=serializers.ChoiceField(required=True, choices=enum_to_list(OPNAME_FOR_CHANGE_NOTIFICATION_TYPE)),
         required=False,
         allow_null=False)
     lcmOpOccStatusImpactingNsComponent = serializers.ListField(
         help_text="Match particular LCM operation status values as reported in notifications of type NsChangeNotification.",
-        child=serializers.ChoiceField(required=True, choices=LCM_OpOcc_Status_For_ChangeNotification_Type),
+        child=serializers.ChoiceField(required=True, choices=enum_to_list(OPOCC_STATUS_FOR_CHANGENOTIFICATION_TYPE)),
         required=False,
         allow_null=False)
index 059ddaf..b8024d5 100644 (file)
@@ -21,13 +21,8 @@ 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
-from lcm.ns.const import IPADDRESSES_TYPE_LIST
-
-
-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):
@@ -198,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)
@@ -361,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)
@@ -516,7 +511,7 @@ class NfpRuleSerializer(serializers.Serializer):
         allow_null=True)
     etherType = serializers.ChoiceField(
         help_text="Indicates the protocol carried over the Ethernet layer",
-        choices=IPADDRESSES_TYPE_LIST,
+        choices=enum_to_list(IPADDRESSES_TYPE),
         required=False,
         allow_null=True)
     vlanTag = serializers.ListField(
@@ -526,7 +521,7 @@ class NfpRuleSerializer(serializers.Serializer):
     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"],
+        choices=enum_to_list(PROTOCOL),
         required=False,
         allow_null=True)
     dscp = serializers.CharField(
@@ -585,7 +580,7 @@ class NfpInfoSerializer(serializers.Serializer):
         required=True)
     nfpState = serializers.ChoiceField(
         help_text="The state of the NFP instance.",
-        choices=["ENABLED", "DISABLED"],
+        choices=enum_to_list(NFP_STATE),
         required=True)
 
 
@@ -716,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(
index 565b876..23f8097 100644 (file)
@@ -1,5 +1,5 @@
 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
-# Copyright (c) 2019, ZTE
+# Copyright (c) 2019, ZTE Corporation.
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
 
 from rest_framework import serializers
 
-from lcm.ns import const
 from lcm.ns.serializers.sol.affected_nss import AffectedNssSerializer
 from lcm.ns.serializers.sol.affected_pnfs import AffectedPnfsSerializer
 from lcm.ns.serializers.sol.affected_saps import AffectedSapsSerializer
@@ -25,6 +24,8 @@ from lcm.ns.serializers.sol.affected_vnffgs import AffectedVnffgsSerializer
 from lcm.ns.serializers.sol.affected_vnfs import AffectedVnfsSerializer
 from lcm.ns.serializers.sol.pub_serializers import LinkSerializer
 from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer
+from lcm.ns.enum import OPERATION_STATE_TYPE, OPERATION_TYPE
+from lcm.pub.utils.enumutil import enum_to_list
 
 
 class ResourceChangesSerializer(serializers.Serializer):
@@ -93,7 +94,7 @@ class NSLCMOpOccSerializer(serializers.Serializer):
     operationState = serializers.ChoiceField(
         help_text="The state of the VNF LCM operation occurrence. ",
         required=True,
-        choices=const.LCM_OPERATION_STATE_TYPES
+        choices=enum_to_list(OPERATION_STATE_TYPE)
     )
     stateEnteredTime = serializers.CharField(
         help_text="Date-time when the current state was entered.",
@@ -109,7 +110,7 @@ class NSLCMOpOccSerializer(serializers.Serializer):
     operation = serializers.ChoiceField(
         help_text="The lifecycle management operation",
         required=True,
-        choices=const.NS_LCM_OP_TYPES
+        choices=enum_to_list(OPERATION_TYPE)
     )
     isAutomaticInvocation = serializers.BooleanField(
         help_text="Set to true if this NS LCM operation occurrence has been automatically triggered by the NFVO.",
index fab3c65..4be9aa5 100644 (file)
@@ -1,4 +1,5 @@
 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
+# Copyright (c) 2019, ZTE Corporation.
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -12,6 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 from rest_framework import serializers
+from lcm.ns.enum import AFFINITY_OR_ANTIAFFIINTY, AFFINITY_OR_ANTIAFFIINTY_SCOPE
+from lcm.pub.utils.enumutil import enum_to_list
 
 
 class ProblemDetailsSerializer(serializers.Serializer):
@@ -75,13 +78,13 @@ class AffinityOrAntiAffinityRuleSerializer(serializers.Serializer):
         allow_null=False)
     affinityOrAntiAffiinty = serializers.ChoiceField(
         help_text="The type of the constraint.",
-        choices=["AFFINITY", "ANTI_AFFINITY"],
+        choices=enum_to_list(AFFINITY_OR_ANTIAFFIINTY),
         required=True,
         allow_null=False,
         allow_blank=False)
     scope = serializers.ChoiceField(
         help_text="Specifies the scope of the rule where the placement constraint applies.",
-        choices=["NFVI_POP", "ZONE", "ZONE_GROUP", "NFVI_NODE"],
+        choices=enum_to_list(AFFINITY_OR_ANTIAFFIINTY_SCOPE),
         required=True,
         allow_null=False,
         allow_blank=False)
index f7a2c85..b97994b 100644 (file)
@@ -1,4 +1,5 @@
 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
+# Copyright (c) 2019, ZTE Corporation.
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -17,12 +18,14 @@ from rest_framework import serializers
 from lcm.ns.serializers.sol.inst_ns_serializers import VnfLocationConstraintSerializer, ParamsForVnfSerializer
 from lcm.ns.serializers.sol.update_serializers import VnfInstanceDataSerializer
 from lcm.ns.serializers.sol.ns_instance import NsScaleInfoSerializer, VnfScaleInfoSerializer
+from lcm.ns.enum import SCALING_DIRECTION, SCALE_VNF_TYPE, SCALE_TYPE
+from lcm.pub.utils.enumutil import enum_to_list
 
 
 class ScaleNsByStepsDataSerializer(serializers.Serializer):
     scalingDirection = serializers.ChoiceField(
         help_text="The scaling direction",
-        choices=["SCALE_IN", "SCALE_OUT"],
+        choices=enum_to_list(SCALING_DIRECTION),
         required=True)
     aspectId = serializers.CharField(
         help_text="The aspect of the NS that is requested to be scaled, as declared in the NSD. ",
@@ -131,7 +134,7 @@ class ScaleVnfDataSerializers(serializers.Serializer):
 
     scaleVnfType = serializers.ChoiceField(
         help_text="Type of the scale VNF operation requested.",
-        choices=["SCALE_OUT", "SCALE_IN", "SCALE_TO_INSTANTIATION_LEVEL", "SCALE_TO_SCALE_LEVEL(S)"],
+        choices=enum_to_list(SCALE_VNF_TYPE),
         required=True)
 
     scaleToLevelData = ScaleToLevelDataSerializer(
@@ -146,7 +149,7 @@ class ScaleVnfDataSerializers(serializers.Serializer):
 class ScaleNsRequestSerializer(serializers.Serializer):
     scaleType = serializers.ChoiceField(
         help_text="Indicates the type of scaling to be performed",
-        choices=["SCALE_NS", "SCALE_VNF"],
+        choices=enum_to_list(SCALE_TYPE),
         required=True)
     scaleNsData = ScaleNsDataSerializer(
         help_text="The necessary information to scale the referenced NS instance.",
index 72015e9..b3ea3fc 100644 (file)
@@ -15,7 +15,8 @@
 
 from rest_framework import serializers
 
-from lcm.ns import const
+from lcm.ns.enum import AUTH_TYPE
+from lcm.pub.utils.enumutil import enum_to_list
 
 
 class OAuthCredentialsSerializer(serializers.Serializer):
@@ -55,7 +56,7 @@ class SubscriptionAuthenticationSerializer(serializers.Serializer):
                   " willing to accept when receiving a notification.",
         child=serializers.ChoiceField(
             required=True,
-            choices=const.AUTH_TYPES),
+            choices=enum_to_list(AUTH_TYPE)),
         required=True)
     paramsBasic = BasicAuthSerializer(
         help_text="Parameters for authentication/authorization using BASIC.",
index f953984..5f8f9a6 100644 (file)
@@ -18,6 +18,8 @@ from lcm.ns.serializers.sol.resource_handle import ResourceHandleSerializer
 from lcm.ns.serializers.sol.ns_instance import NsCpHandleSerializer, NfpRuleSerializer
 from lcm.ns.serializers.sol.cp_serializers import CpProtocolDataSerializer
 from lcm.ns.serializers.sol.cp_serializers import IpAddressesDataSerialzier
+from lcm.ns.enum import OPERATIONAL_STATE, STOP_TYPE
+from lcm.pub.utils.enumutil import enum_to_list
 
 
 class VnfInstanceDataSerializer(serializers.Serializer):
@@ -184,13 +186,13 @@ class ChangeVnfFlavourDataSerizlizer(serializers.Serializer):
 class OperationalStatesSerializer(serializers.Serializer):
     OperationalStates = serializers.ChoiceField(
         help_text="State of operation",
-        choices=["STARTED", "STOPPED"])
+        choices=enum_to_list(OPERATIONAL_STATE))
 
 
 class StopTypeSerializer(serializers.Serializer):
     StopType = serializers.ChoiceField(
         help_text="Type of stop",
-        choices=["FORCEFUL", "GRACEFUL"])
+        choices=enum_to_list(STOP_TYPE))
 
 
 class OperateVnfDataSerializer(serializers.Serializer):