aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2018-03-06 16:35:02 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2018-03-06 16:44:06 +0800
commit0d5ebba6f8a52fb8afe56976944061e0b26676c0 (patch)
treed1feb1f6d1987695891adbe88c3c3938628fd75b
parent6eb6242f4c2ffca859b83b05b0f4e32282ef73ef (diff)
Add vnf Grant bussiness logic
Change-Id: I15acd9944ff4aa3fb55d189bde70b65302814f2a Issue-ID: VFC-779 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--lcm/v2/grant_vnf.py46
-rw-r--r--lcm/v2/views.py14
2 files changed, 58 insertions, 2 deletions
diff --git a/lcm/v2/grant_vnf.py b/lcm/v2/grant_vnf.py
new file mode 100644
index 00000000..832c7818
--- /dev/null
+++ b/lcm/v2/grant_vnf.py
@@ -0,0 +1,46 @@
+# Copyright 2018 ZTE 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 json
+import logging
+import uuid
+
+logger = logging.getLogger(__name__)
+
+
+class GrantVnf(object):
+ def __init__(self, grant_data):
+ self.data = grant_data
+
+ def exec_grant(self):
+ if isinstance(self.data, (unicode, str)):
+ self.data = json.JSONDecoder().decode(self.data)
+ grant_resp = {
+ "id": str(uuid.uuid4()),
+ "vnfInstanceId": self.data.get("vnfInstanceId"),
+ "vnfLcmOpOccId": self.data.get("vnfLcmOpOccId"),
+ "_links": {
+ "self": {
+ "href": "/grants"
+ },
+ "vnfLcmOpOcc": {
+ "href": self.data.get("_links").get("vnfLcmOpOcc")
+ },
+ "vnfInstance": {
+ "href": self.data.get("_links").get("vnfInstance")
+ }
+ }
+ }
+ logger.debug("grant_resp=%s", grant_resp)
+ return grant_resp
diff --git a/lcm/v2/views.py b/lcm/v2/views.py
index 19f6740a..3fa240d9 100644
--- a/lcm/v2/views.py
+++ b/lcm/v2/views.py
@@ -21,6 +21,7 @@ from drf_yasg.utils import swagger_auto_schema
from lcm.v2.serializers import GrantRequestSerializer
from lcm.v2.serializers import GrantSerializer
+from lcm.v2.grant_vnf import GrantVnf
logger = logging.getLogger(__name__)
@@ -29,7 +30,9 @@ class VnfGrantView(APIView):
@swagger_auto_schema(
request_body=GrantRequestSerializer(),
responses={
- status.HTTP_201_CREATED: GrantSerializer(),
+ status.HTTP_201_CREATED: GrantSerializer(
+ help_text="The grant was created successfully (synchronous mode)."
+ ),
status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
}
)
@@ -39,8 +42,15 @@ class VnfGrantView(APIView):
req_serializer = GrantRequestSerializer(data=request.data)
if not req_serializer.is_valid():
raise Exception(req_serializer.errors)
+
+ grant_resp = GrantVnf(request.data).exec_grant()
+
+ resp_serializer = GrantSerializer(data=grant_resp)
+ if not resp_serializer.is_valid():
+ raise Exception(resp_serializer.errors)
+
+ return Response(data=resp_serializer.data, status=status.HTTP_201_CREATED)
except Exception as e:
logger.error(traceback.format_exc())
logger.error("Exception in VnfGrant: %s", e.message)
return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- return Response(data={}, status=status.HTTP_201_CREATED)