add catalog api 18/97018/1
authorhewei-cmss <hewei@cmss.chinamobile.com>
Mon, 14 Oct 2019 01:54:51 +0000 (09:54 +0800)
committerhewei-cmss <hewei@cmss.chinamobile.com>
Mon, 14 Oct 2019 01:54:51 +0000 (09:54 +0800)
Add catalog api for lcm to modify package status

Issue-ID: VFC-1549

Signed-off-by: hewei-cmss <hewei@cmss.chinamobile.com>
Change-Id: Ib72ab2e1b616e1a46a1a7e0f33e9e61ae6844bff

catalog/packages/biz/ns_descriptor.py
catalog/packages/urls.py [changed mode: 0755->0644]
catalog/packages/views/ns_descriptor_views.py

index f0e0572..bb6da1e 100644 (file)
@@ -57,6 +57,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)
old mode 100755 (executable)
new mode 100644 (file)
index 776e940..1478349
@@ -68,6 +68,9 @@ urlpatterns = [
 
     # url(r'^api/vnfpkgm/v1/subscriptions/(?P<subscriptionId>[0-9a-zA-Z\-\_]+)$', vnfpkg_subscription.as_view(), name='subscription_rd'),
 
+    # 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 3b8c1f9..d0de5ae 100644 (file)
@@ -137,3 +137,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)