separate ns-inst 04/75604/1
authortianxing <15210838572@139.com>
Thu, 10 Jan 2019 07:02:49 +0000 (15:02 +0800)
committertianxing <15210838572@139.com>
Thu, 10 Jan 2019 07:02:56 +0000 (15:02 +0800)
Change-Id: I794a65fe540848046ed93aaa02347ecc7a8d8216
Signed-off-by: tianxing <15210838572@139.com>
Issue-ID: VFC-1234

lcm/ns/serializers/create_ns_serializers.py
lcm/ns/serializers/inst_ns_serializers.py
lcm/ns/serializers/ns_serializers.py
lcm/ns/serializers/pub_serializers.py [new file with mode: 0644]
lcm/ns/serializers/update_serializers.py
lcm/ns/tests/test_ns_instant.py
lcm/ns/views/inst_ns_view.py

index 3128f1d..d52c1cf 100644 (file)
@@ -14,8 +14,7 @@
 
 from rest_framework import serializers
 
-from lcm.ns.serializers.ns_serializers import IpAddress
-from lcm.ns.serializers.common_Link import LinkSerializer
+from lcm.ns.serializers.pub_serializers import Links, IpAddressSerialzier, ipAddressesSerializer
 
 
 class ContextSerializer(serializers.Serializer):
@@ -40,10 +39,8 @@ class VnfInstanceSerializer(serializers.Serializer):
 
 class IpOverEthernetAddressDataSerializer(serializers.Serializer):
     macAddress = serializers.CharField(help_text="Mac address", required=False, allow_null=True)
-    ipAddresses = serializers.ListField(help_text="List of IP addresses to assign to the extCP instance.",
-                                        child=IpAddress(
-                                            help_text="List of IP addresses to assign to the extCP instance.",
-                                            required=True), required=False, allow_null=True, )
+    ipAddresses = IpAddressSerialzier(help_text="List of IP addresses to assign to the extCP instance.",
+                                      required=False, allow_null=True, many=True)
 
 
 class cpProtocolDataSerializer(serializers.Serializer):
@@ -196,30 +193,6 @@ class VnffgInfoSerializer(serializers.Serializer):
                                 required=True, allow_null=False, many=True)
 
 
-class AddressRange(serializers.Serializer):
-    minAddress = serializers.IPAddressField(help_text="Lowest IP address belonging to the range.",
-                                            required=True)
-    maxAddress = serializers.IPAddressField(help_text="Highest IP address belonging to the range.",
-                                            required=True)
-
-
-class ipAddressesSerializer(serializers.Serializer):
-    type = serializers.ChoiceField(help_text="The type of the IP addresses.",
-                                   choices=["IPV4", "IPV6"], required=True)
-    addresses = serializers.ListField(help_text="Fixed addresses assigned (from the subnet defined by "
-                                                "subnetId if provided)",
-                                      child=serializers.CharField(help_text="An IPV4 or IPV6 address."),
-                                      required=False, allow_null=True)
-# question
-    isDynamic = serializers.BooleanField(help_text="Indicates whether this set of addresses was assigned "
-                                                   "dynamically (true) or based on address information "
-                                                   "provided as input from the API consumer (false).",
-                                         required=False, default=True)
-    addressRange = AddressRange(help_text="An IP address range used", required=False, allow_null=True)
-    subnetId = serializers.CharField(help_text="Subnet defined by the identifier of the subnet"
-                                               "resource in the VIM", required=False, allow_null=True)
-
-
 class IpOverEthernetAddressInfoSerializer(serializers.Serializer):
     macAddress = serializers.CharField(help_text="Assigned MAC address", required=True)
     ipAddresses = ipAddressesSerializer(help_text="Addresses assigned to the CP or SAP instance.",
@@ -269,18 +242,6 @@ class AffinityOrAntiAffinityRuleSerializer(serializers.Serializer):
                                     choices=["NFVI_POP", "ZONE", "ZONE_GROUP", "NFVI_NODE"], required=True)
 
 
-class Links(serializers.Serializer):
-    self = LinkSerializer(help_text="URI of this resource.", required=True)
-    nestedNsInstances = LinkSerializer(help_text="Links to the nested NS instances of the present NS"
-                                                 "instance.", required=False, allow_null=True)
-    instantiate = LinkSerializer(help_text="Link to the 'instantiate' task resource", required=False,
-                                 allow_null=True)
-    terminate = LinkSerializer(help_text="Link to the 'terminate' task resource", required=False, allow_null=True)
-    update = LinkSerializer(help_text="Link to the 'update' task resource", required=False, allow_null=True)
-    scale = LinkSerializer(help_text="Link to the 'scale' task resource", required=False, allow_null=True)
-    heal = LinkSerializer(help_text="Link to the 'heal' task resource", required=False, allow_null=True)
-
-
 class CreateNsRespSerializer(serializers.Serializer):
     nsInstanceId = serializers.CharField(help_text="ID of NS instance", required=True)
     nsInstanceName = serializers.CharField(help_text="Human readable name of the NS instance.", required=True)
index 8413a07..cd01d77 100644 (file)
@@ -14,7 +14,7 @@
 
 from rest_framework import serializers
 
-from lcm.ns.serializers.create_ns_serializers import IpOverEthernetAddressDataSerializer
+from lcm.ns.serializers.pub_serializers import IpOverEthernetAddressDataSerializer
 from lcm.ns.serializers.update_serializers import AddPnfDataSerializer, VnfInstanceDataSerializer
 
 
@@ -30,28 +30,23 @@ class SapDataSerializer(serializers.Serializer):
     sapdId = serializers.CharField(help_text="Reference to the SAPD for this SAP.", required=True)
     sapName = serializers.CharField(help_text="Human readable name for the SAP.", required=True)
     description = serializers.CharField(help_text="Human readable description for the SAP.", required=True)
-    sapProtocolData = serializers.ListField(help_text="Parameters for configuring the network protocols on"
-                                                      "the SAP.",
-                                            child=(CpProtocolDataSerializer(help_text="This type represents "
-                                                                                      "network protocol "
-                                                                                      "data.")),
-                                            required=False, allow_null=True)
+    sapProtocolData = CpProtocolDataSerializer(help_text="Parameters for configuring the network protocols"
+                                                         " on the SAP.",
+                                               required=False, allow_null=True, many=True)
 
 
 class civicAddressElementSerializer(serializers.Serializer):
     caType = serializers.CharField(help_text="Describe the content type of caValue.", required=True)
-    caValue = serializers.Serializer(help_text="Content of civic address element corresponding to the"
-                                               "caType.", required=True)
+    caValue = serializers.CharField(help_text="Content of civic address element corresponding to the"
+                                              "aType.", required=True)
 
 
 class LocationConstraintsSerializer(serializers.Serializer):
     countryCode = serializers.CharField(help_text="The two-letter ISO 3166 [29] country code in capital"
                                                   "letters.", required=True)
-    civicAddressElement = serializers.ListField(help_text="Zero or more elements comprising the civic"
-                                                          "address.",
-                                                child=civicAddressElementSerializer(
-                                                    help_text="caType and caValue", required=True),
-                                                required=False, allow_null=True)
+    civicAddressElement = civicAddressElementSerializer(help_text="Zero or more elements comprising the civic"
+                                                                  "address.",
+                                                        required=False, allow_null=True, many=True)
 
 
 class VnfLocationConstraintSerializer(serializers.Serializer):
@@ -89,65 +84,35 @@ class AffinityOrAntiAffinityRuleSerializer(serializers.Serializer):
 class InstantNsReqSerializer(serializers.Serializer):
     nsFlavourId = serializers.CharField(help_text="Identifier of the NS deployment flavour to be"
                                                   "instantiated.", required=True)
-    sapData = serializers.ListField(help_text="Create data concerning the SAPs of this NS",
-                                    child=(SapDataSerializer(
-                                        help_text="This type represents the information related to a SAP"
-                                                  "of a NS.", required=True)),
-                                    required=False, allow_null=True)
-    addpnfData = serializers.ListField(help_text="Information on the PNF(s) that are part of this NS.",
-                                       child=(AddPnfDataSerializer(help_text="This type specifies an PNF to "
-                                                                             "be added to the NS instance and"
-                                                                             "the PNF Profile to use for"
-                                                                             "this PNF.", required=True)),
-                                       required=False, allow_null=True)
-    vnfInstanceData = serializers.ListField(help_text="Specify an existing VNF instance to be used in the"
-                                                      "NS.",
-                                            child=(VnfInstanceDataSerializer(help_text="This type specifies "
-                                                                                       "an existing VNF "
-                                                                                       "instance to be used "
-                                                                                       "in the NS instance "
-                                                                                       "and if needed",
-                                                                             required=True)),
-                                            required=False, allow_null=True)
+    sapData = SapDataSerializer(help_text="Create data concerning the SAPs of this NS",
+                                required=False, allow_null=True, many=True)
+    addpnfData = AddPnfDataSerializer(help_text="Information on the PNF(s) that are part of this NS.",
+                                      required=False, allow_null=True, many=True)
+    vnfInstanceData = VnfInstanceDataSerializer(help_text="Specify an existing VNF instance to be used in "
+                                                          "the NS.",
+                                                required=False, allow_null=True, many=True)
     nestedNsInstanceId = serializers.ListField(help_text="Specify an existing NS instance to be used as a "
                                                          "nested NS within the NS",
                                                required=False, allow_null=True)
-    localizationLanguage = serializers.ListField(help_text="Defines the location constraints for the VNF to"
-                                                           "be instantiated as part of the NS instantiation.",
-                                                 child=(VnfLocationConstraintSerializer(
-                                                     help_text="This type represents the association of"
-                                                               "location constraints to a VNF instance to be"
-                                                               "created according to a specific VNF profile",
-                                                     required=True)), required=False, allow_null=True)
+    localizationLanguage = VnfLocationConstraintSerializer(help_text="Defines the location constraints for "
+                                                                     "the VNF to be instantiated as part of"
+                                                                     " the NS instantiation.",
+                                                           required=False, allow_null=True, many=True)
     additionalParamForNs = serializers.DictField(
         help_text="Allows the OSS/BSS to provide additional parameters at the NS level ",
         child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True),
         required=False,
         allow_null=True
     )
-    additionalParamsForVnf = serializers.ListField(help_text="Allows the OSS/BSS to provide additional"
-                                                             "parameter(s)per VNF instance",
-                                                   child=(ParamsForVnfSerializer(
-                                                       help_text="This type defines the additional parameters"
-                                                                 "for the VNF instance to be created"
-                                                                 "associated with an NS instance",
-                                                       required=True)), required=False, allow_null=True)
+    additionalParamsForVnf = ParamsForVnfSerializer(help_text="Allows the OSS/BSS to provide additional "
+                                                              "parameter(s)per VNF instance",
+                                                    required=False, allow_null=True, many=True)
     startTime = serializers.DateTimeField(help_text="Timestamp indicating the earliest time to instantiate"
                                                     "the NS.", required=False, allow_null=True)
     nsInstantiationLevelId = serializers.CharField(help_text="Identifies one of the NS instantiation levels"
                                                              "declared in the DF applicable to this NS "
                                                              "instance", required=False, allow_null=True)
-    additionalAffinityOrAntiAffiniityRule = serializers.ListField(help_text="Specifies additional affinity or"
-                                                                            "anti-affinity constraint for the"
-                                                                            "VNF instances to be instantiated"
-                                                                            "as part of the NS "
-                                                                            "instantiation.",
-                                                                  child=(
-                                                                      AffinityOrAntiAffinityRuleSerializer(
-                                                                          help_text="This type describes the"
-                                                                                    "additional affinity or"
-                                                                                    "anti-affinity rule"
-                                                                                    "applicable between the"
-                                                                                    "VNF instances",
-                                                                          required=True)),
-                                                                  required=False, allow_null=True)
+    additionalAffinityOrAntiAffiniityRule = AffinityOrAntiAffinityRuleSerializer(
+        help_text="Specifies additional affinity or anti-affinity constraint for the VNF instances to be"
+                  " instantiated as part of the NS instantiation.",
+        required=False, allow_null=True, many=True)
index 322facb..f525674 100644 (file)
@@ -14,6 +14,7 @@
 
 from rest_framework import serializers
 from lcm.ns_pnfs.serializers.pnf_serializer import PnfInstanceSerializer
+from lcm.ns.serializers.pub_serializers import IpOverEthernetAddressDataSerializer
 
 
 class VnfInstSerializer(serializers.Serializer):
@@ -70,17 +71,9 @@ class AddressRange(serializers.Serializer):
     maxAddress = serializers.IPAddressField(help_text="Highest IP address belonging to the range.", required=True)
 
 
-class IpAddress(serializers.Serializer):
-    type = serializers.ChoiceField(help_text="The type of the IP addresses.", required=True, choices=["IPV4", "IPV6"])
-    fixedAddresses = serializers.ListField(child=serializers.CharField(help_text="Fixed addresses to assign."), required=False)
-    numDynamicAddresses = serializers.IntegerField(help_text="Number of dynamic addresses to assign.", required=False)
-    addressRange = AddressRange(help_text="An IP address range to be used.", required=False)
-    subnetId = serializers.CharField(help_text="Subnet defined by the identifier of the subnet resource in the VIM.", required=False, allow_null=True, allow_blank=True)
-
-
-class IpOverEthernetSerializer(serializers.Serializer):
-    macAddress = serializers.CharField(help_text="MAC address.", required=False, allow_null=True, allow_blank=True)
-    ipAddresses = IpAddress(help_text="List of IP addresses to assign to the extCP instance.", required=False, many=True)
+# class IpOverEthernetSerializer(serializers.Serializer):
+#     macAddress = serializers.CharField(help_text="MAC address.", required=False, allow_null=True, allow_blank=True)
+#     ipAddresses = IpAddress(help_text="List of IP addresses to assign to the extCP instance.", required=False, many=True)
 
 
 class CpProtocolInfoSerializer(serializers.Serializer):
@@ -89,7 +82,7 @@ class CpProtocolInfoSerializer(serializers.Serializer):
         choices=["IP_OVER_ETHERNET"],
         required=True,
         allow_null=False)
-    ipOverEthernet = IpOverEthernetSerializer(
+    ipOverEthernet = IpOverEthernetAddressDataSerializer(
         help_text="IP addresses over Ethernet to assign to the extCP instance.",
         required=False,
         allow_null=True)
diff --git a/lcm/ns/serializers/pub_serializers.py b/lcm/ns/serializers/pub_serializers.py
new file mode 100644 (file)
index 0000000..533aa1c
--- /dev/null
@@ -0,0 +1,68 @@
+# Copyright (c) 2019, CMCC Technologies Co., Ltd.
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from rest_framework import serializers
+from lcm.ns.serializers.common_Link import LinkSerializer
+
+
+class AddressRangeSerializer(serializers.Serializer):
+    minAddress = serializers.IPAddressField(help_text="Lowest IP address belonging to the range.",
+                                            required=True)
+    maxAddress = serializers.IPAddressField(help_text="Highest IP address belonging to the range.",
+                                            required=True)
+
+
+class IpAddressSerialzier(serializers.Serializer):
+    type = serializers.ChoiceField(help_text="The type of the IP addresses.",
+                                   required=True, choices=["IPV4", "IPV6"])
+    fixedAddresses = serializers.ListField(child=serializers.CharField(help_text="Fixed addresses to assign.",
+                                                                       required=False, allow_null=True))
+    numDynamicAddresses = serializers.IntegerField(help_text="Number of dynamic addresses to assign.",
+                                                   required=False)
+    addressRange = AddressRangeSerializer(help_text="An IP address range to be used.", required=False)
+    subnetId = serializers.CharField(help_text="Subnet defined by the identifier of the subnet resource"
+                                               " in the VIM.", required=False, allow_null=True,
+                                     allow_blank=True)
+
+
+class ipAddressesSerializer(serializers.Serializer):
+    type = serializers.ChoiceField(help_text="The type of the IP addresses.",
+                                   required=True, choices=["IPV4", "IPV6"])
+    addresses = serializers.ListField(help_text="An IPV4 or IPV6 address", required=False, allow_null=True)
+    isDynamic = serializers.BooleanField(help_text="Indicates whether this set of addresses was assigned"
+                                                   " dynamically (true) or based on address information"
+                                                   " provided as input from the API consumer (false). ",
+                                         required=False)
+    addressRange = AddressRangeSerializer(help_text="An IP address range used,",
+                                          required=False, allow_null=True)
+    subnetId = serializers.CharField(help_text="Subnet defined by the identifier of the subnet resource in "
+                                               "the VIM. ", required=False, allow_null=True)
+
+
+class Links(serializers.Serializer):
+    self = LinkSerializer(help_text="URI of this resource.", required=True)
+    nestedNsInstances = LinkSerializer(help_text="Links to the nested NS instances of the present NS"
+                                                 "instance.", required=False, allow_null=True)
+    instantiate = LinkSerializer(help_text="Link to the 'instantiate' task resource", required=False,
+                                 allow_null=True)
+    terminate = LinkSerializer(help_text="Link to the 'terminate' task resource", required=False, allow_null=True)
+    update = LinkSerializer(help_text="Link to the 'update' task resource", required=False, allow_null=True)
+    scale = LinkSerializer(help_text="Link to the 'scale' task resource", required=False, allow_null=True)
+    heal = LinkSerializer(help_text="Link to the 'heal' task resource", required=False, allow_null=True)
+
+
+class IpOverEthernetAddressDataSerializer(serializers.Serializer):
+    macAddress = serializers.CharField(help_text="Mac address", required=False, allow_null=True)
+    ipAddresses = IpAddressSerialzier(help_text="List of IP addresses to assign to the extCP instance.",
+                                      required=False, allow_null=True, many=True)
index 06217d8..020ded0 100644 (file)
@@ -12,7 +12,8 @@
 # limitations under the License.
 
 from rest_framework import serializers
-from lcm.ns.serializers.ns_serializers import IpAddress
+
+from lcm.ns.serializers.pub_serializers import IpAddressSerialzier
 
 
 class VnfInstanceDataSerializer(serializers.Serializer):
@@ -36,7 +37,8 @@ class InstantiateVnfDataSerializer(serializers.Serializer):
 
 class IpOverEthernetAddressDataSerializer(serializers.Serializer):
     macAddress = serializers.CharField(help_text="Mac address", required=False, allow_null=True)
-    ipAddresses = serializers.ListField(help_text="List of IP addresses to assign to the extCP instance.", child=IpAddress(help_text="IP addresses to assign to the extCP instance.", required=False), required=False, allow_null=True)
+    ipAddresses = IpAddressSerialzier(help_text="List of IP addresses to assign to the extCP instance.",
+                                      required=False, allow_null=True, many=True)
 
 
 class CpProtocolDataSerializer(serializers.Serializer):
@@ -304,10 +306,8 @@ class PnfExtCpDataSerializer(serializers.Serializer):
                                               required=False, allow_null=True)
     cpdId = IdentifierInNsdSerializer(help_text="Identifier of the Connection Point Descriptor (CPD) for this CP",
                                       required=False, allow_null=True)
-    cpProtocolData = serializers.ListField(help_text="Address assigned for this CP.",
-                                           child=(CpProtocolDataSerializer(
-                                               help_text="This type represents network protocol data.", required=True)),
-                                           required=False, allow_null=True)
+    cpProtocolData = CpProtocolDataSerializer(help_text="Address assigned for this CP.",
+                                              required=False, allow_null=True, many=True)
 
 
 class AddPnfDataSerializer(serializers.Serializer):
@@ -316,10 +316,8 @@ class AddPnfDataSerializer(serializers.Serializer):
     pnfdId = serializers.CharField(help_text="Identifier of the PNFD on which the PNF is based.", required=True)
     pnfProfileId = serializers.CharField(
         help_text="Identifier of related PnfProfile in the NSD on which the PNF is based.", required=True)
-    cpData = serializers.ListField(help_text="Address assigned for the PNF external CP(s). ",
-                                   child=(PnfExtCpDataSerializer(
-                                       help_text="Serializer data of pnf ext cp", required=True)),
-                                   required=False, allow_null=True)
+    cpData = PnfExtCpDataSerializer(help_text="Address assigned for the PNF external CP(s). ",
+                                    required=False, allow_null=True, many=True)
 
 
 class ModifyPnfDataSerializer(serializers.Serializer):
index 38c2875..df4f403 100644 (file)
@@ -54,10 +54,17 @@ class TestNsInstant(TestCase):
             "additionalParamForNs": {
                 "sdnControllerId": "2"
             },
-            "locationConstraints": [{
+            "nsFlavourId": 12345,
+            "localizationLanguage": [{
                 "vnfProfileId": "vnfd1",
                 "locationConstraints": {
-                    "vimId": "3"
+                    "countryCode": "countryCode",
+                    # "vimId": "3",
+                    "civicAddressElement": [
+                        {"caType": "type1",
+                         "caValue": 1
+                         }
+                    ]
                 }
             }]
         }
index 795384c..ce704d3 100644 (file)
@@ -19,7 +19,7 @@ from rest_framework.views import APIView
 from drf_yasg.utils import swagger_auto_schema
 
 from lcm.ns.biz.ns_instant import InstantNSService
-from lcm.ns.serializers.ns_serializers import InstantNsReqSerializer
+from lcm.ns.serializers.inst_ns_serializers import InstantNsReqSerializer
 from lcm.ns.serializers.ns_serializers import NsOperateJobSerializer
 
 logger = logging.getLogger(__name__)