summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog/packages/biz/ns_descriptor.py15
-rw-r--r--catalog/packages/biz/pnf_descriptor.py26
-rw-r--r--catalog/packages/views/ns_descriptor_views.py8
-rw-r--r--catalog/packages/views/pnf_descriptor_views.py9
-rw-r--r--catalog/pub/database/models.py4
5 files changed, 29 insertions, 33 deletions
diff --git a/catalog/packages/biz/ns_descriptor.py b/catalog/packages/biz/ns_descriptor.py
index 2d0b511b..278c071b 100644
--- a/catalog/packages/biz/ns_descriptor.py
+++ b/catalog/packages/biz/ns_descriptor.py
@@ -70,7 +70,7 @@ def delete_single(nsd_info_id):
logger.info('Start to delete NSD(%s)...' % nsd_info_id)
ns_pkgs = NSPackageModel.objects.filter(nsPackageId=nsd_info_id)
if not ns_pkgs.exists():
- logger.info('NSD(%s) is deleted.' % nsd_info_id)
+ logger.info('NSD(%s) has been deleted.' % nsd_info_id)
return
'''
if ns_pkgs[0].operationalState != 'DISABLED':
@@ -93,7 +93,7 @@ def upload(remote_file, nsd_info_id):
logger.info('NSD(%s) does not exist.' % nsd_info_id)
raise CatalogException('NSD(%s) does not exist.' % nsd_info_id)
- ns_pkgs[0].onboardingState = 'UPLOADING' # TODO: if failed, should be set to created
+ ns_pkgs.update(onboardingState='UPLOADING')
local_file_name = remote_file.name
local_file_dir = os.path.join(CATALOG_ROOT_PATH, nsd_info_id)
local_file_name = os.path.join(local_file_dir, local_file_name)
@@ -108,7 +108,7 @@ def upload(remote_file, nsd_info_id):
def process(nsd_info_id, local_file_name):
logger.info('Start to process NSD(%s)...' % nsd_info_id)
ns_pkgs = NSPackageModel.objects.filter(nsPackageId=nsd_info_id)
- ns_pkgs[0].onboardingState = 'PROCESSING' # TODO: if failed, should be set to created
+ ns_pkgs.update(onboardingState='PROCESSING')
nsd_json = toscaparser.parse_nsd(local_file_name)
nsd = json.JSONDecoder().decode(nsd_json)
@@ -124,8 +124,7 @@ def process(nsd_info_id, local_file_name):
logger.error("VNFD is not distributed.")
raise CatalogException("VNF package(%s) is not distributed." % vnfd_id)
- NSPackageModel(
- nsPackageId=nsd_info_id,
+ ns_pkgs.update(
nsdId=nsd_id,
nsdName=nsd["metadata"].get("name", nsd_id),
nsdDesginer=nsd["metadata"].get("vendor", "undefined"),
@@ -135,7 +134,7 @@ def process(nsd_info_id, local_file_name):
sdcCsarId=nsd_info_id,
localFilePath=local_file_name,
nsdModel=nsd_json
- ).save()
+ )
logger.info('NSD(%s) has been processed.' % nsd_info_id)
@@ -149,8 +148,10 @@ def download(nsd_info_id):
logger.error('NSD(%s) is not ONBOARDED.' % nsd_info_id)
raise CatalogException('NSD(%s) is not ONBOARDED.' % nsd_info_id)
local_file_path = ns_pkgs[0].localFilePath
+ local_file_name = local_file_path.split('/')[-1]
+ local_file_name = local_file_name.split('\\')[-1]
logger.info('NSD(%s) has been downloaded.' % nsd_info_id)
- return local_file_path
+ return local_file_path, local_file_name, os.path.getsize(local_file_path)
def fill_resp_data(ns_pkg):
diff --git a/catalog/packages/biz/pnf_descriptor.py b/catalog/packages/biz/pnf_descriptor.py
index 0e2a477d..ebc965bc 100644
--- a/catalog/packages/biz/pnf_descriptor.py
+++ b/catalog/packages/biz/pnf_descriptor.py
@@ -1,4 +1,4 @@
-# Copyright 2017 ZTE Corporation.
+# 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.
@@ -74,7 +74,7 @@ def upload(remote_file, pnfd_info_id):
logger.info('PNFD(%s) does not exist.' % pnfd_info_id)
raise CatalogException('PNFD (%s) does not exist.' % pnfd_info_id)
- pnf_pkgs[0].onboardingState = 'UPLOADING'
+ pnf_pkgs.update(onboardingState='UPLOADING')
local_file_name = remote_file.name # TODO: common method
local_file_dir = os.path.join(CATALOG_ROOT_PATH, pnfd_info_id)
local_file_name = os.path.join(local_file_dir, local_file_name)
@@ -86,10 +86,11 @@ def upload(remote_file, pnfd_info_id):
logger.info('PNFD(%s) content has been uploaded.' % pnfd_info_id)
-def process(pnfd_info_id, local_file_name): # TODO: onboardingState changes
+def process(pnfd_info_id, local_file_name):
logger.info('Start to process PNFD(%s)...' % pnfd_info_id)
pnf_pkgs = PnfPackageModel.objects.filter(pnfPackageId=pnfd_info_id)
- pnf_pkgs[0].onboardingState = 'PROCESSING' # TODO: if failed, should be set to created
+ pnf_pkgs.update(onboardingState='PROCESSING')
+
pnfd_json = toscaparser.parse_pnfd(local_file_name)
pnfd = json.JSONDecoder().decode(pnfd_json)
@@ -98,18 +99,17 @@ def process(pnfd_info_id, local_file_name): # TODO: onboardingState changes
logger.info('PNFD(%s) already exists.' % pnfd_id)
raise CatalogException("PNFD(%s) already exists." % pnfd_id)
- PnfPackageModel(
- pnfPackageId=pnfd_info_id,
+ pnf_pkgs.update(
pnfdId=pnfd_id,
pnfdName=pnfd["metadata"].get("name", pnfd_id),
pnfdDesginer=pnfd["metadata"].get("vendor", "undefined"),
pnfdDescription=pnfd["metadata"].get("description", ""),
pnfdVersion=pnfd["metadata"].get("version", "undefined"),
- nsPackageUri=local_file_name, # TODO
+ pnfPackageUri=local_file_name, # TODO
sdcCsarId=pnfd_info_id,
localFilePath=local_file_name,
pnfdModel=pnfd_json
- ).save()
+ )
logger.info('PNFD(%s) has been processed.' % pnfd_info_id)
@@ -123,15 +123,17 @@ def download(pnfd_info_id):
logger.error('PNFD(%s) is not ONBOARDED.' % pnfd_info_id)
raise CatalogException('PNFD(%s) is not ONBOARDED.' % pnfd_info_id)
local_file_path = pnf_pkgs[0].localFilePath
+ local_file_name = local_file_path.split('/')[-1]
+ local_file_name = local_file_name.split('\\')[-1]
logger.info('PNFD(%s) has been downloaded.' % pnfd_info_id)
- return local_file_path
+ return local_file_path, local_file_name, os.path.getsize(local_file_path)
def delete_single(pnfd_info_id):
logger.info('Start to delete PNFD(%s)...' % pnfd_info_id)
pnf_pkgs = PnfPackageModel.objects.filter(pnfPackageId=pnfd_info_id)
if not pnf_pkgs.exists():
- logger.info('PNFD(%s) is deleted.' % pnfd_info_id)
+ logger.info('PNFD(%s) has been deleted.' % pnfd_info_id)
return
if pnf_pkgs[0].usageState != 'NOT_IN_USE':
@@ -150,8 +152,8 @@ def delete_single(pnfd_info_id):
raise CatalogException('PNFD(%s) is referenced.' % pnfd_info_id)
pnf_pkgs.delete()
- vnf_pkg_path = os.path.join(CATALOG_ROOT_PATH, pnfd_info_id)
- fileutil.delete_dirs(vnf_pkg_path)
+ pnf_pkg_path = os.path.join(CATALOG_ROOT_PATH, pnfd_info_id)
+ fileutil.delete_dirs(pnf_pkg_path)
logger.debug('PNFD(%s) has been deleted.' % pnfd_info_id)
diff --git a/catalog/packages/views/ns_descriptor_views.py b/catalog/packages/views/ns_descriptor_views.py
index 653d161f..97765e64 100644
--- a/catalog/packages/views/ns_descriptor_views.py
+++ b/catalog/packages/views/ns_descriptor_views.py
@@ -13,7 +13,6 @@
# limitations under the License.
import logging
-import os
import traceback
from django.http import StreamingHttpResponse
@@ -170,11 +169,8 @@ def nsd_content_ru(request, *args, **kwargs):
if request.method == 'GET':
try:
- file_path = download(nsd_info_id)
- file_name = file_path.split('/')[-1]
- file_name = file_name.split('\\')[-1]
-
- start, end = 0, os.path.getsize(file_path)
+ file_path, file_name, file_size = download(nsd_info_id)
+ start, end = 0, file_size
file_range = request.META.get('RANGE')
if file_range:
[start, end] = file_range.split('-')
diff --git a/catalog/packages/views/pnf_descriptor_views.py b/catalog/packages/views/pnf_descriptor_views.py
index bf7f1cd2..c489df5f 100644
--- a/catalog/packages/views/pnf_descriptor_views.py
+++ b/catalog/packages/views/pnf_descriptor_views.py
@@ -1,4 +1,4 @@
-# Copyright 2017 ZTE Corporation.
+# 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.
@@ -13,7 +13,6 @@
# limitations under the License.
import logging
-import os
import traceback
from django.http import FileResponse
@@ -165,12 +164,10 @@ def pnfd_content_ru(request, *args, **kwargs):
if request.method == 'GET':
try:
- file_path = download(pnfd_info_id)
- file_name = file_path.split('/')[-1]
- file_name = file_name.split('\\')[-1]
+ file_path, file_name, file_size = download(pnfd_info_id)
response = FileResponse(open(file_path, 'rb'), status=status.HTTP_200_OK)
response['Content-Disposition'] = 'attachment; filename=%s' % file_name.encode('utf-8')
- response['Content-Length'] = os.path.getsize(file_path)
+ response['Content-Length'] = file_size
return response
except Exception as e:
logger.error(e.message)
diff --git a/catalog/pub/database/models.py b/catalog/pub/database/models.py
index 3b9e909a..7d215cc7 100644
--- a/catalog/pub/database/models.py
+++ b/catalog/pub/database/models.py
@@ -1,4 +1,4 @@
-# Copyright 2016 ZTE Corporation.
+# Copyright 2016-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.
@@ -64,7 +64,7 @@ class PnfPackageModel(models.Model):
# uuid = models.CharField(db_column='UUID', primary_key=True, max_length=255)
pnfPackageId = models.CharField(db_column='PNFPACKAGEID', primary_key=True, max_length=50) # onboardedPnfPkgInfoId
pnfPackageUri = models.CharField(db_column='PNFPACKAGEURI', max_length=300, null=True, blank=True) # downloadUri
- SdcCSARUri = models.CharField(db_column='SDCCSARURI', max_length=300, null=True, blank=True) # SdcCSARUri
+ sdcCSARUri = models.CharField(db_column='SDCCSARURI', max_length=300, null=True, blank=True) # sdcCSARUri
checksum = models.CharField(db_column='CHECKSUM', max_length=50, null=True, blank=True) # checksum
onboardingState = models.CharField(db_column='ONBOARDINGSTATE', max_length=20, blank=True, null=True)
usageState = models.CharField(db_column='USAGESTATE', max_length=20, blank=True, null=True) # usageState