aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lcm/packages/nf_package.py30
-rw-r--r--lcm/packages/ns_package.py4
-rw-r--r--lcm/packages/sdc_nf_package.py35
-rw-r--r--lcm/packages/sdc_ns_package.py31
-rw-r--r--lcm/packages/views.py12
5 files changed, 50 insertions, 62 deletions
diff --git a/lcm/packages/nf_package.py b/lcm/packages/nf_package.py
index 6c845d55..17ce388c 100644
--- a/lcm/packages/nf_package.py
+++ b/lcm/packages/nf_package.py
@@ -14,29 +14,28 @@
import json
import logging
-import uuid
import os
-import time
+import sys
import threading
+import time
import traceback
-import sys
+import uuid
+from lcm.pub.config.config import IMAGE_ROOT_PATH, IGNORE_DEL_IMG_WEHN_DEL_CSAR
from lcm.pub.database.models import NfPackageModel, VnfPackageFileModel, NfInstModel
-from lcm.pub.utils.values import ignore_case_get
-from lcm.pub.utils import fileutil
-from lcm.pub.msapi.catalog import STATUS_ONBOARDED, P_STATUS_ENABLED
+from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi.catalog import P_STATUS_DELETEFAILED, P_STATUS_DELETING
from lcm.pub.msapi.catalog import P_STATUS_NORMAL, P_STATUS_ONBOARDING, P_STATUS_ONBOARDFAILED
+from lcm.pub.msapi.catalog import STATUS_ONBOARDED, P_STATUS_ENABLED
+from lcm.pub.msapi.catalog import get_download_url_from_catalog
from lcm.pub.msapi.catalog import query_csar_from_catalog, set_csar_state
from lcm.pub.msapi.catalog import query_rawdata_from_catalog, delete_csar_from_catalog
-from lcm.pub.msapi.catalog import get_download_url_from_catalog
-from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi.extsys import get_vims
-from lcm.pub.config.config import IMAGE_ROOT_PATH, IGNORE_DEL_IMG_WEHN_DEL_CSAR
from lcm.pub.nfvi.vim.vimadaptor import VimAdaptor
-from lcm.pub.nfvi.vim import const
-from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.utils import fileutil
from lcm.pub.utils import toscautil
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.utils.values import ignore_case_get
logger = logging.getLogger(__name__)
@@ -115,7 +114,7 @@ class NfOnBoardingThread(threading.Thread):
JobUtil.add_job_status(self.job_id, 20, "Get model of CSAR(%s) from catalog." % self.csar_id)
raw_data = query_rawdata_from_catalog(self.csar_id)
- self.nfd = toscautil.convert_vnfd_model(raw_data["rawData"]) # convert to inner json
+ self.nfd = toscautil.convert_vnfd_model(raw_data["rawData"]) # convert to inner json
self.nfd = json.JSONDecoder().decode(self.nfd)
self.nfd_id = self.nfd["metadata"]["id"]
if NfPackageModel.objects.filter(vnfdid=self.nfd_id):
@@ -134,7 +133,7 @@ class NfOnBoardingThread(threading.Thread):
vnfdversion=vnfd_ver,
vnfversion=self.nfd["metadata"].get("version", "undefined"),
vnfdmodel=json.JSONEncoder().encode(self.nfd)
- ).save()
+ ).save()
def download_nf_images(self):
nf_images = []
@@ -145,8 +144,7 @@ class NfOnBoardingThread(threading.Thread):
img_desc = image_file.get("description", "")
img_url, img_local_path = get_download_url_from_catalog(self.csar_id, img_relative_path)
JobUtil.add_job_status(self.job_id, 50, "Start to download Image(%s)." % img_name)
- is_download_ok, img_save_full_path = fileutil.download_file_from_http(img_url,
- self.img_save_path, img_name)
+ is_download_ok, img_save_full_path = fileutil.download_file_from_http(img_url, self.img_save_path, img_name)
if not is_download_ok:
raise NSLCMException("Failed to download image from %s" % img_url)
logger.debug("Download Image(%s) to %s successfully.", img_name, img_save_full_path)
@@ -350,7 +348,7 @@ class NfPackage(object):
"vnfdId": nf_pkg.vnfdid
})
return ret
-
+
def get_csar(self, csar_id):
pkg_info = {}
nf_pkg = NfPackageModel.objects.filter(nfpackageid=csar_id)
diff --git a/lcm/packages/ns_package.py b/lcm/packages/ns_package.py
index 4a7fb303..af6f5f29 100644
--- a/lcm/packages/ns_package.py
+++ b/lcm/packages/ns_package.py
@@ -52,6 +52,7 @@ def ns_common_call(fun, csar_id, operation=""):
return fmt_ns_pkg_rsp(STATUS_FAILED, str(sys.exc_info()))
return fmt_ns_pkg_rsp(STATUS_SUCCESS, ret[1], "")
+
def ns_on_boarding(csar_id):
return ns_common_call(NsPackage().on_boarding, csar_id)
@@ -97,7 +98,7 @@ class NsPackage(object):
raise NSLCMException("CSAR(%s) already onBoarded." % csar_id)
raw_data = query_rawdata_from_catalog(csar_id)
- nsd = toscautil.convert_nsd_model(raw_data["rawData"]) # convert to inner json
+ nsd = toscautil.convert_nsd_model(raw_data["rawData"]) # convert to inner json
nsd = json.JSONDecoder().decode(nsd)
nsd_id = nsd["metadata"]["id"]
if NSDModel.objects.filter(nsd_id=nsd_id):
@@ -177,7 +178,6 @@ class NsPackage(object):
return [0, {"csarId": csar_id, "packageInfo": package_info, "nsInstanceInfo": ns_instance_info}]
-
def set_state_csar(self, csar_id, operation):
if not NSDModel.objects.filter(id=csar_id):
raise NSLCMException("CSAR(%s) does not exist." % csar_id)
diff --git a/lcm/packages/sdc_nf_package.py b/lcm/packages/sdc_nf_package.py
index 11f27b34..a7ef3871 100644
--- a/lcm/packages/sdc_nf_package.py
+++ b/lcm/packages/sdc_nf_package.py
@@ -14,27 +14,24 @@
import json
import logging
-import uuid
import os
-import time
+import sys
import threading
import traceback
-import sys
+from lcm.pub.config.config import CATALOG_ROOT_PATH
from lcm.pub.database.models import NfPackageModel, NfInstModel
-from lcm.pub.utils.values import ignore_case_get
-from lcm.pub.utils import fileutil
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.config.config import CATALOG_ROOT_PATH
-from lcm.pub.msapi.extsys import get_vims
-from lcm.pub.utils.jobutil import JobUtil
-from lcm.pub.utils import toscaparser
from lcm.pub.msapi import sdc
+from lcm.pub.utils import fileutil
+from lcm.pub.utils import toscaparser
+from lcm.pub.utils.jobutil import JobUtil
logger = logging.getLogger(__name__)
JOB_ERROR = 255
+
def nf_get_csars():
ret = None
try:
@@ -46,6 +43,7 @@ def nf_get_csars():
return [1, str(sys.exc_info())]
return ret
+
def nf_get_csar(csar_id):
ret = None
try:
@@ -57,8 +55,8 @@ def nf_get_csar(csar_id):
return [1, str(sys.exc_info())]
return ret
-#####################################################################################
+#####################################################################################
class SdcNfDistributeThread(threading.Thread):
"""
Sdc NF Package Distribute
@@ -98,9 +96,10 @@ class SdcNfDistributeThread(threading.Thread):
artifact = sdc.get_artifact(sdc.ASSETTYPE_RESOURCES, self.csar_id)
local_path = os.path.join(CATALOG_ROOT_PATH, self.csar_id)
- local_file_name = sdc.download_artifacts(artifact["toscaModelURL"],
- local_path, "%s.csar" % artifact.get("name", self.csar_id))
-
+ local_file_name = sdc.download_artifacts(artifact["toscaModelURL"],
+ local_path,
+ "%s.csar" % artifact.get("name", self.csar_id))
+
vnfd_json = toscaparser.parse_vnfd(local_file_name)
vnfd = json.JSONDecoder().decode(vnfd_json)
@@ -121,12 +120,10 @@ class SdcNfDistributeThread(threading.Thread):
vnfdversion=vnfd_ver,
vnfversion=vnfd["metadata"].get("version", "undefined"),
vnfdmodel=vnfd_json,
- vnfd_path=local_file_name
- ).save()
+ vnfd_path=local_file_name).save()
JobUtil.add_job_status(self.job_id, 100, "CSAR(%s) distribute successfully." % self.csar_id)
-
def rollback_distribute(self):
try:
NfPackageModel.objects.filter(nfpackageid=self.csar_id).delete()
@@ -205,7 +202,7 @@ class SdcNfPackage(object):
"vnfdId": nf_pkg.vnfdid
})
return [0, csars]
-
+
def get_csar(self, csar_id):
pkg_info = {}
nf_pkg = NfPackageModel.objects.filter(nfpackageid=csar_id)
@@ -215,7 +212,6 @@ class SdcNfPackage(object):
pkg_info["vnfdVersion"] = nf_pkg[0].vnfdversion
pkg_info["vnfVersion"] = nf_pkg[0].vnfversion
-
vnf_insts = NfInstModel.objects.filter(package_id=csar_id)
vnf_inst_info = [{"vnfInstanceId": vnf_inst.nfinstid,
"vnfInstanceName": vnf_inst.nf_name} for vnf_inst in vnf_insts]
@@ -224,6 +220,3 @@ class SdcNfPackage(object):
"packageInfo": pkg_info,
"imageInfo": [],
"vnfInstanceInfo": vnf_inst_info}]
-
-
-
diff --git a/lcm/packages/sdc_ns_package.py b/lcm/packages/sdc_ns_package.py
index 9824b39a..58d85889 100644
--- a/lcm/packages/sdc_ns_package.py
+++ b/lcm/packages/sdc_ns_package.py
@@ -14,18 +14,16 @@
import json
import logging
-
-import traceback
-import sys
import os
+import sys
+import traceback
+from lcm.pub.config.config import CATALOG_ROOT_PATH
from lcm.pub.database.models import NSDModel, NSInstModel, NfPackageModel
-from lcm.pub.utils.values import ignore_case_get
from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi import sdc
-from lcm.pub.config.config import CATALOG_ROOT_PATH
-from lcm.pub.utils import toscaparser
from lcm.pub.utils import fileutil
+from lcm.pub.utils import toscaparser
logger = logging.getLogger(__name__)
@@ -61,6 +59,7 @@ def ns_delete_csar(csar_id, force_delete):
return fmt_ns_pkg_rsp(STATUS_FAILED, str(sys.exc_info()))
return fmt_ns_pkg_rsp(STATUS_SUCCESS, ret[1], "")
+
def ns_get_csars():
ret = None
try:
@@ -72,6 +71,7 @@ def ns_get_csars():
return [1, str(sys.exc_info())]
return ret
+
def ns_get_csar(csar_id):
ret = None
try:
@@ -100,9 +100,10 @@ class SdcNsPackage(object):
artifact = sdc.get_artifact(sdc.ASSETTYPE_SERVICES, csar_id)
local_path = os.path.join(CATALOG_ROOT_PATH, csar_id)
- local_file_name = sdc.download_artifacts(artifact["toscaModelURL"],
- local_path, "%s.csar" % artifact.get("name", csar_id))
-
+ local_file_name = sdc.download_artifacts(artifact["toscaModelURL"],
+ local_path,
+ "%s.csar" % artifact.get("name", csar_id))
+
nsd_json = toscaparser.parse_nsd(local_file_name)
nsd = json.JSONDecoder().decode(nsd_json)
@@ -128,7 +129,6 @@ class SdcNsPackage(object):
return [0, "CSAR(%s) distributed successfully." % csar_id]
-
def delete_csar(self, csar_id, force_delete):
if force_delete:
NSInstModel.objects.filter(nspackage_id=csar_id).delete()
@@ -138,7 +138,6 @@ class SdcNsPackage(object):
NSDModel.objects.filter(id=csar_id).delete()
return [0, "Delete CSAR(%s) successfully." % csar_id]
-
def get_csars(self):
csars = {"csars": []}
nss = NSDModel.objects.filter()
@@ -159,17 +158,11 @@ class SdcNsPackage(object):
nss = NSInstModel.objects.filter(nspackage_id=csar_id)
ns_instance_info = [{
- "nsInstanceId": ns.id,
+ "nsInstanceId": ns.id,
"nsInstanceName": ns.name} for ns in nss]
- return [0, {"csarId": csar_id,
- "packageInfo": package_info,
- "nsInstanceInfo": ns_instance_info}]
+ return [0, {"csarId": csar_id, "packageInfo": package_info, "nsInstanceInfo": ns_instance_info}]
def delete_catalog(self, csar_id):
local_path = os.path.join(CATALOG_ROOT_PATH, csar_id)
fileutil.delete_dirs(local_path)
-
-
-
- \ No newline at end of file
diff --git a/lcm/packages/views.py b/lcm/packages/views.py
index d1c7ef87..cf134a7b 100644
--- a/lcm/packages/views.py
+++ b/lcm/packages/views.py
@@ -25,6 +25,7 @@ from lcm.packages import ns_package, nf_package, sdc_ns_package, sdc_nf_package
logger = logging.getLogger(__name__)
+
@api_view(http_method_names=['POST', 'GET'])
def ns_distribute_get(request, *args, **kwargs):
logger.debug("Enter %s, method is %s", fun_name(), request.method)
@@ -35,13 +36,14 @@ def ns_distribute_get(request, *args, **kwargs):
else:
csar_id = ignore_case_get(request.data, "csarId")
logger.debug("csar_id is %s", csar_id)
- ret = sdc_ns_package.ns_on_distribute(csar_id)
+ ret = sdc_ns_package.ns_on_distribute(csar_id)
normal_status = status.HTTP_202_ACCEPTED
logger.debug("Leave %s, Return value is %s", fun_name(), ret)
if ret[0] != 0:
return Response(data={'error': ret[1]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(data=ret[1], status=normal_status)
+
@api_view(http_method_names=['GET', 'DELETE'])
def ns_rd_csar(request, *args, **kwargs):
csar_id = ignore_case_get(kwargs, "csarId")
@@ -61,8 +63,8 @@ def ns_rd_csar(request, *args, **kwargs):
return Response(data={'error': ret[1]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(data=ret[1], status=normal_status)
-####################################################################################################
+####################################################################################################
@api_view(http_method_names=['POST', 'GET'])
def nf_distribute_get(request, *args, **kwargs):
logger.debug("Enter %s%s, method is %s", fun_name(), request.data, request.method)
@@ -83,6 +85,7 @@ def nf_distribute_get(request, *args, **kwargs):
return Response(data={'error': ret[1]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(data=ret[1], status=normal_status)
+
@api_view(http_method_names=['GET', 'DELETE'])
def nf_rd_csar(request, *args, **kwargs):
csar_id = ignore_case_get(kwargs, "csarId")
@@ -104,8 +107,8 @@ def nf_rd_csar(request, *args, **kwargs):
return Response(data={'error': ret[1]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(data=ret[1], status=normal_status)
-####################################################################################################
+####################################################################################################
@api_view(http_method_names=['POST'])
def ns_on_boarding(request, *args, **kwargs):
csar_id = ignore_case_get(request.data, "csarId")
@@ -156,6 +159,7 @@ def ns_set_state_csar(request, *args, **kwargs):
return Response(data={'error': ret[1]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(data=ret[1], status=status.HTTP_202_ACCEPTED)
+
#################################################################################################################
@api_view(http_method_names=['POST', 'GET'])
def nf_on_boarding(request, *args, **kwargs):
@@ -200,4 +204,4 @@ def nf_delete_pending_csar(request, *args, **kwargs):
nf_package.NfPkgDeletePendingThread(csar_id, job_id).start()
ret = {"jobId": job_id}
logger.info("Leave %s, Return value is %s", fun_name(), str(ret))
- return Response(data=ret, status=status.HTTP_202_ACCEPTED) \ No newline at end of file
+ return Response(data=ret, status=status.HTTP_202_ACCEPTED)