diff options
Diffstat (limited to 'lcm')
-rw-r--r-- | lcm/lcm/nf/biz/delete_subscription.py | 31 | ||||
-rw-r--r-- | lcm/lcm/nf/biz/query_subscription.py | 6 | ||||
-rw-r--r-- | lcm/lcm/nf/urls.py | 2 | ||||
-rw-r--r-- | lcm/lcm/nf/views/subscriptions_view.py | 45 | ||||
-rw-r--r-- | lcm/lcm/samples/urls.py | 1 | ||||
-rw-r--r-- | lcm/lcm/samples/views.py | 11 |
6 files changed, 94 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)
diff --git a/lcm/lcm/samples/urls.py b/lcm/lcm/samples/urls.py index a8b37c39..ee9d75c4 100644 --- a/lcm/lcm/samples/urls.py +++ b/lcm/lcm/samples/urls.py @@ -18,5 +18,6 @@ from lcm.samples import views urlpatterns = [ url(r'^api/vnflcm/v1/resources/(?P<action_type>(inst|term)+)$', views.ResourceList.as_view()), url(r'^samples/$', views.SampleList.as_view()), + url(r'^api/vnflcm/v1/callback_sample$', views.CallbackSample.as_view()), url(r'^api/vnflcm/v1/health_check$', views.HealthCheckView.as_view()) ] diff --git a/lcm/lcm/samples/views.py b/lcm/lcm/samples/views.py index 86b4b8ab..b82c5558 100644 --- a/lcm/lcm/samples/views.py +++ b/lcm/lcm/samples/views.py @@ -33,6 +33,17 @@ class SampleList(APIView): return Response({"status": "active"}) +class CallbackSample(APIView): + @swagger_auto_schema( + responses={ + status.HTTP_204_NO_CONTENT: 'Successfully' + } + ) + def get(self, request, format=None): + logger.debug("Callback Sample") + return Response(status=status.HTTP_204_NO_CONTENT) + + class ResourceList(APIView): @swagger_auto_schema( responses={ |