summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuoyu Ying <ruoyu.ying@intel.com>2018-08-17 01:37:53 +0800
committerRuoyu Ying <ruoyu.ying@intel.com>2018-08-20 18:57:25 +0800
commitce0a4213d937b76e7392eae604891d3f25e59bb3 (patch)
treef5e6f06b53798c8f0006c0e418afed067e4b9c43
parentf513696c95789bcaea862cf98d239f1004609795 (diff)
Add API for OOF callback
Add API for the OOF callback response.The structure will be the same as OOF response. Change-Id: I35948afd3a799ad6dc1385e63c4c6503d92122dc Issue-ID: VFC-1023 Signed-off-by: Ruoyu Ying <ruoyu.ying@intel.com>
-rw-r--r--lcm/ns/vnfs/place_vnfs.py22
-rw-r--r--lcm/ns/vnfs/serializers.py83
-rw-r--r--lcm/ns/vnfs/urls.py3
-rw-r--r--lcm/ns/vnfs/views.py24
4 files changed, 131 insertions, 1 deletions
diff --git a/lcm/ns/vnfs/place_vnfs.py b/lcm/ns/vnfs/place_vnfs.py
new file mode 100644
index 00000000..0e54a121
--- /dev/null
+++ b/lcm/ns/vnfs/place_vnfs.py
@@ -0,0 +1,22 @@
+# Copyright 2017-2018 Intel Corporation.
+#
+# 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.
+
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class PlaceVnfs(object):
+ def __init__(self, data):
+ self.data = data
diff --git a/lcm/ns/vnfs/serializers.py b/lcm/ns/vnfs/serializers.py
index 652cf7e8..3019ad28 100644
--- a/lcm/ns/vnfs/serializers.py
+++ b/lcm/ns/vnfs/serializers.py
@@ -226,3 +226,86 @@ class VimInfoRespSerializer(serializers.Serializer):
sslCacert = serializers.CharField(help_text="SSL Cacert of VIM", required=False, allow_null=True, allow_blank=True)
sslInsecure = serializers.CharField(help_text="SSL Insecure of VIM", required=False, allow_null=True, allow_blank=True)
status = serializers.CharField(help_text="Status of VIM", required=False, allow_null=True, allow_blank=True)
+
+
+class CandidateSerializer(serializers.Serializer):
+ identifierType = serializers.ChoiceField(
+ help_text="The type of a candidate",
+ choices=["serviceInstanceId", "vnfName", "cloudRegionId", "vimId"],
+ required=True
+ )
+ identifiers = serializers.ListField(
+ help_text="A list of identifiers",
+ child=serializers.CharField(help_text="One identifier", required=True),
+ required=True
+ )
+ cloudOwner = serializers.CharField(
+ help_text="The name of a cloud owner. Only required if identifier Type is cloudRegionId", required=False)
+
+
+class LicenseSolutionSerializer(serializers.Serializer):
+ resourceModuleName = serializers.CharField(help_text="Name of Resource as defined in the Service Model",
+ required=True)
+ serviceResourceId = serializers.CharField(help_text="Resource Id defined in the Service Model", required=True)
+ entitlementPoolUUID = serializers.ListField(
+ help_text="A list of entitlementPoolUUIDs",
+ child=serializers.CharField(help_text="entitlementPoolUUID", required=True),
+ required=True
+ )
+ licenseKeyGroupUUID = serializers.ListField(
+ help_text="A list of licenseKeyGroupUUID",
+ child=serializers.CharField(help_text="licenseKeyGroupUUID", required=True),
+ required=True
+ )
+ entitlementPoolInvariantUUID = serializers.ListField(
+ help_text="A list of entitlementPoolInvariantUUIDs",
+ child=serializers.CharField(help_text="entitlementPoolInvariantUUID", required=True),
+ required=True
+ )
+ licenseKeyGroupInvariantUUID = serializers.ListField(
+ help_text="A list of licenseKeyGroupInvariantUUID",
+ child=serializers.CharField(help_text="licenseKeyGroupInvariantUUID", required=True),
+ required=True
+ )
+
+
+class AssignmentInfoSerializer(serializers.Serializer):
+ key = serializers.CharField(help_text="Any attribute Key needed", required=True)
+ value = serializers.CharField(help_text="Attribute value for that key", required=True)
+
+
+class PlacementSolutionSerializer(serializers.Serializer):
+ resourceModuleName = serializers.CharField(help_text="Name of Resource as defined in the Service Model",
+ required=True)
+ serviceResourceId = serializers.CharField(help_text="Resource Id defined in the Service Model", required=True)
+ solution = CandidateSerializer(help_text="The Placement Solution", required=True)
+ assignmentInfo = AssignmentInfoSerializer(help_text="Additonal information related to a candidate",
+ required=False, many=True)
+
+
+class ComprehensiveSolutionSerializer(serializers.Serializer):
+ child = serializers.ListField(
+ help_text="A list of placement solutions",
+ child=PlacementSolutionSerializer(help_text="A list of placement solutions"),
+ allow_empty=True,
+ required=True)
+
+
+class SolutionSerializer(serializers.Serializer):
+ placementSolutions = ComprehensiveSolutionSerializer(help_text="A list of Placement Solutions",
+ required=True, many=True)
+ licenseSolutions = LicenseSolutionSerializer(help_text="A list of License Solutions",
+ required=True, many=True)
+
+
+class PlaceVnfReqSerializer(serializers.Serializer):
+ requestId = serializers.UUIDField(help_text="ID of Homing Request", required=True)
+ transactionId = serializers.UUIDField(help_text="ID of Homing Transaction", required=True, allow_null=False)
+ statusMessage = serializers.CharField(help_text="Status Message of Request", required=False, allow_null=True)
+ requestStatus = serializers.ChoiceField(
+ help_text="The Status of a Request",
+ choices=["completed", "failed", "pending"],
+ required=True,
+ allow_null=False
+ )
+ solutions = SolutionSerializer(help_text="Request Solutions", required=True, allow_null=False)
diff --git a/lcm/ns/vnfs/urls.py b/lcm/ns/vnfs/urls.py
index 5da83678..40d3230b 100644
--- a/lcm/ns/vnfs/urls.py
+++ b/lcm/ns/vnfs/urls.py
@@ -14,7 +14,7 @@
from django.conf.urls import url
from rest_framework.urlpatterns import format_suffix_patterns
-from lcm.ns.vnfs.views import NfView, NfDetailView, NfGrant
+from lcm.ns.vnfs.views import NfView, NfDetailView, NfGrant, NfPlacement
from lcm.ns.vnfs.views import LcmNotify, NfScaleView, NfVerifyView
from lcm.ns.vnfs.views import NfVnfmInfoView, NfVimInfoView
@@ -22,6 +22,7 @@ urlpatterns = [
url(r'^api/nslcm/v1/ns/vnfs$', NfView.as_view()),
url(r'^api/nslcm/v1/ns/vnfs/(?P<vnfinstid>[0-9a-zA-Z_-]+)$', NfDetailView.as_view()),
url(r'^api/nslcm/v1/ns/grantvnf$', NfGrant.as_view()),
+ url(r'^api/nslcm/v1/ns/placevnf$', NfPlacement.as_view()),
url(r'^api/nslcm/v1/ns/(?P<vnfmid>[0-9a-zA-Z_-]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z_-]+)/Notify$', LcmNotify.as_view()),
url(r'^api/nslcm/v1/ns/vnfs/(?P<vnfinstid>[0-9a-zA-Z_-]+)/scaling$', NfScaleView.as_view()),
url(r'^api/nslcm/v1/vnfonboarding$', NfVerifyView.as_view()),
diff --git a/lcm/ns/vnfs/views.py b/lcm/ns/vnfs/views.py
index 810793fe..c5bc25e1 100644
--- a/lcm/ns/vnfs/views.py
+++ b/lcm/ns/vnfs/views.py
@@ -27,6 +27,7 @@ from lcm.ns.vnfs.get_vnfs import GetVnf
from lcm.ns.vnfs.scale_vnfs import NFManualScaleService
from lcm.ns.vnfs.terminate_nfs import TerminateVnfs
from lcm.ns.vnfs.grant_vnfs import GrantVnfs
+from lcm.ns.vnfs.place_vnfs import PlaceVnfs
from lcm.ns.vnfs.notify_lcm import NotifyLcm
from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi.extsys import get_vnfm_by_id, get_vim_by_id
@@ -46,6 +47,7 @@ from lcm.ns.vnfs.serializers import VerifyVnfReqSerializer
from lcm.ns.vnfs.serializers import VerifyVnfRespSerializer
from lcm.ns.vnfs.serializers import VnfmInfoRespSerializer
from lcm.ns.vnfs.serializers import VimInfoRespSerializer
+from lcm.ns.vnfs.serializers import PlaceVnfReqSerializer
logger = logging.getLogger(__name__)
@@ -179,6 +181,28 @@ class NfGrant(APIView):
return Response(data={'error': '%s' % e.message}, status=status.HTTP_409_CONFLICT)
+class NfPlacement(APIView):
+ @swagger_auto_schema(
+ request_body=PlaceVnfReqSerializer(),
+ response={
+ status.HTTP_201_CREATED: PlaceVnfReqSerializer(),
+ status.HTTP_404_NOT_FOUND: "Placement not found"
+ }
+ )
+ def post(self, request):
+ logger.debug("NfPlacement--post::> %s" % request.data)
+ try:
+ req_serializer = PlaceVnfReqSerializer(data=request.data)
+ if not req_serializer.is_valid():
+ raise Exception(req_serializer.errors)
+ PlaceVnfs(request.data).extract()
+ return Response(data={}, status=status.HTTP_200_OK)
+ except Exception as e:
+ logger.error(e.message)
+ logger.error(traceback.format_exc())
+ return Response(data={'error': '%s' % e.message}, status=status.HTTP_409_CONFLICT)
+
+
class LcmNotify(APIView):
@swagger_auto_schema(
request_body=NotifyLcmReqSerializer(),