summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-07-16 16:04:45 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-07-16 16:04:45 +0800
commitc2e150a6c3901b664c963b389ee6e9b9e00ed2ab (patch)
treef36a716c7582cb125e0feec595dfa545351775f2
parent89b6e7c193199259cda3f01b46082cc4e8cc9ffd (diff)
Add get and del subscription api
Change-Id: I38957770ca9a92571ecfd8cd44b779324eec0b3b Issue-ID: VFC-1429 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--lcm/lcm/nf/biz/delete_subscription.py31
-rw-r--r--lcm/lcm/nf/biz/query_subscription.py6
-rw-r--r--lcm/lcm/nf/urls.py2
-rw-r--r--lcm/lcm/nf/views/subscriptions_view.py45
4 files changed, 82 insertions, 2 deletions
diff --git a/lcm/lcm/nf/biz/delete_subscription.py b/lcm/lcm/nf/biz/delete_subscription.py
new file mode 100644
index 00000000..387aa5d9
--- /dev/null
+++ b/lcm/lcm/nf/biz/delete_subscription.py
@@ -0,0 +1,31 @@
+# Copyright (C) 2019 ZTE. All Rights Reserved
+#
+# 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
+
+from lcm.pub.database.models import SubscriptionModel
+from lcm.pub.exceptions import NFLCMException
+
+logger = logging.getLogger(__name__)
+
+
+class DeleteSubscription:
+ def __init__(self, subscription_id):
+ self.subscription_id = subscription_id
+
+ def delete_single_subscription(self):
+ subscription = SubscriptionModel.objects.filter(subscription_id=self.subscription_id)
+ if not subscription.exists():
+ raise NFLCMException('Subscription(%s) does not exist' % self.subscription_id)
+ subscription.delete()
diff --git a/lcm/lcm/nf/biz/query_subscription.py b/lcm/lcm/nf/biz/query_subscription.py
index f2270d0a..7702f60b 100644
--- a/lcm/lcm/nf/biz/query_subscription.py
+++ b/lcm/lcm/nf/biz/query_subscription.py
@@ -35,6 +35,12 @@ class QuerySubscription:
self.subscription_id = subscription_id
self.params = data
+ def query_single_subscription(self):
+ subscription = SubscriptionModel.objects.filter(subscription_id=self.subscription_id)
+ if not subscription.exists():
+ raise NFLCMException('Subscription(%s) does not exist' % self.subscription_id)
+ return self.fill_resp_data(subscription)
+
def query_multi_subscriptions(self):
query_data = {}
logger.debug("QueryMultiSubscriptions--get--biz::> Check for filters in query params" % self.params)
diff --git a/lcm/lcm/nf/urls.py b/lcm/lcm/nf/urls.py
index 3fdb3433..5ab32347 100644
--- a/lcm/lcm/nf/urls.py
+++ b/lcm/lcm/nf/urls.py
@@ -18,6 +18,7 @@ from lcm.nf.views.curd_vnf_views import DeleteVnfAndQueryVnf, CreateVnfAndQueryV
from lcm.nf.views.instantiate_vnf_view import InstantiateVnfView
from lcm.nf.views.terminate_vnf_view import TerminateVnfView
from lcm.nf.views.subscriptions_view import SubscriptionsView
+from lcm.nf.views.subscriptions_view import SubscriptionDetailView
from lcm.nf.views.heal_vnf_view import HealVnfView
from lcm.nf.views.operate_vnf_view import OperateVnfView
from lcm.nf.views.scale_vnf_view import ScaleVnfView
@@ -28,6 +29,7 @@ from lcm.nf.views.lcm_op_occs_view import QueryMultiVnfLcmOpOccs, QuerySingleVnf
urlpatterns = [
url(r'^api/vnflcm/v1/subscriptions$', SubscriptionsView.as_view()),
+ url(r'^api/vnflcm/v1/subscriptions/(?P<subscriptionid>[0-9a-zA-Z_-]+)$', SubscriptionDetailView.as_view()),
url(r'^api/vnflcm/v1/vnf_instances$', CreateVnfAndQueryVnfs.as_view()),
url(r'^api/vnflcm/v1/vnf_instances/(?P<instanceid>[0-9a-zA-Z_-]+)/instantiate$', InstantiateVnfView.as_view()),
url(r'^api/vnflcm/v1/vnf_instances/(?P<instanceid>[0-9a-zA-Z_-]+)$', DeleteVnfAndQueryVnf.as_view()),
diff --git a/lcm/lcm/nf/views/subscriptions_view.py b/lcm/lcm/nf/views/subscriptions_view.py
index 95b37725..547e0124 100644
--- a/lcm/lcm/nf/views/subscriptions_view.py
+++ b/lcm/lcm/nf/views/subscriptions_view.py
@@ -17,8 +17,6 @@ import json
import logging
from drf_yasg.utils import swagger_auto_schema
-from lcm.nf.biz.create_subscription import CreateSubscription
-from lcm.nf.biz.query_subscription import QuerySubscription
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
@@ -28,6 +26,9 @@ from lcm.nf.serializers.lccn_subscription import LccnSubscriptionSerializer
from lcm.nf.serializers.lccn_subscriptions import LccnSubscriptionsSerializer
from lcm.nf.serializers.response import ProblemDetailsSerializer
from lcm.pub.exceptions import NFLCMException, NFLCMExceptionBadRequest
+from lcm.nf.biz.create_subscription import CreateSubscription
+from lcm.nf.biz.query_subscription import QuerySubscription
+from lcm.nf.biz.delete_subscription import DeleteSubscription
from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -106,3 +107,43 @@ class SubscriptionsView(APIView):
logger.debug("SubscribeNotification--get::> Remove default fields")
return Response(data=subscriptions_serializer.data, status=status.HTTP_200_OK)
+
+
+class SubscriptionDetailView(APIView):
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: LccnSubscriptionSerializer(),
+ status.HTTP_404_NOT_FOUND: ProblemDetailsSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
+ }
+ )
+ @view_safe_call_with_log(logger=logger)
+ def get(self, request, subscriptionid):
+ logger.debug("SubscriptionDetailView--get::> %s" % subscriptionid)
+
+ resp_data = QuerySubscription(
+ subscription_id=subscriptionid
+ ).query_single_subscription()
+
+ subscription_serializer = LccnSubscriptionSerializer(data=resp_data)
+ if not subscription_serializer.is_valid():
+ raise NFLCMException(subscription_serializer.errors)
+
+ return Response(data=resp_data, status=status.HTTP_200_OK)
+
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_204_NO_CONTENT: "",
+ status.HTTP_404_NOT_FOUND: ProblemDetailsSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
+ }
+ )
+ @view_safe_call_with_log(logger=logger)
+ def delete(self, request, subscriptionid):
+ logger.debug("SubscriptionDetailView--delete::> %s" % subscriptionid)
+
+ DeleteSubscription(
+ subscription_id=subscriptionid
+ ).delete_single_subscription()
+
+ return Response(status=status.HTTP_204_NO_CONTENT)