Add etsicatalog api 31/104031/4
authoryangyan <yangyanyj@chinamobile.com>
Fri, 20 Mar 2020 06:43:33 +0000 (14:43 +0800)
committerYan Yang <yangyanyj@chinamobile.com>
Fri, 20 Mar 2020 07:20:33 +0000 (07:20 +0000)
Add etsicatalog api for nslcm to modify package status"

Change-Id: Ib54c19f5908540d233a839a36f387832f9278584
Issue-ID: MODELING-346
Signed-off-by: yangyan <yangyanyj@chinamobile.com>
catalog/packages/biz/ns_descriptor.py
catalog/packages/urls.py
catalog/packages/views/ns_descriptor_views.py

index 8b337dc..d14c452 100644 (file)
@@ -19,6 +19,7 @@ import os
 import uuid
 
 from catalog.packages.biz.common import parse_file_range, read, save
+from catalog.packages.const import PKG_STATUS
 from catalog.pub.config.config import CATALOG_ROOT_PATH
 from catalog.pub.database.models import NSPackageModel, PnfPackageModel, VnfPackageModel
 from catalog.pub.exceptions import CatalogException, ResourceNotFoundException
@@ -58,6 +59,10 @@ class NsDescriptor(object):
         logger.info('A NSD(%s) has been created.' % data['id'])
         return data
 
+    def update(self, data, nsd_info_id):
+        usageState = PKG_STATUS.IN_USE if data["usageState"] else PKG_STATUS.NOT_IN_USE
+        NSPackageModel.objects.filter(nsPackageId=nsd_info_id).update(usageState=usageState)
+
     def query_multiple(self, nsdId=None):
         if nsdId:
             ns_pkgs = NSPackageModel.objects.filter(nsdId=nsdId)
index 410df80..6a86252 100644 (file)
@@ -64,6 +64,9 @@ urlpatterns = [
     url(r'^URI-is-provided-by-the-client-when-creating-the-subscription-VnfPackageOnboardingNotification$', PkgOnboardingNotificationView.as_view()),
     url(r'^URI-is-provided-by-the-client-when-creating-the-subscription-VnfPackageChangeNotification$', PkgChangeNotificationView.as_view()),
 
+    # catalog and lcm interaction APIS
+    url(r'^api/catalog/v1/ns_descriptors/(?P<nsdInfoId>[0-9a-zA-Z\-\_]+)$', ns_descriptor_views.ns_descriptors_u, name='ns_descriptors_u'),
+
     # health check
     url(r'^api/vnfpkgm/v1/health_check$', HealthCheckView.as_view()),
     url(r'^api/nsd/v1/health_check$', HealthCheckView.as_view()),
index 2d98628..44e06e4 100644 (file)
@@ -144,3 +144,21 @@ def nsd_content_ru(request, **kwargs):
         file_range = request.META.get('HTTP_RANGE')
         file_iterator = NsDescriptor().download(nsd_info_id, file_range)
         return StreamingHttpResponse(file_iterator, status=status.HTTP_200_OK)
+
+
+@swagger_auto_schema(
+    method='PUT',
+    operation_description="Update a NSD",
+    request_body=no_body,
+    responses={
+        status.HTTP_202_ACCEPTED: "Successfully",
+        status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+    }
+)
+@api_view(http_method_names=['PUT'])
+@view_safe_call_with_log(logger=logger)
+def ns_descriptors_u(request, **kwargs):
+    if request.method == 'PUT':
+        nsd_info_id = kwargs.get("nsdInfoId")
+        NsDescriptor().update(request.data, nsd_info_id)
+        return Response(data=None, status=status.HTTP_202_ACCEPTED)