diff options
author | maopengzhang <zhang.maopeng1@zte.com.cn> | 2017-08-30 12:48:56 +0800 |
---|---|---|
committer | maopengzhang <zhang.maopeng1@zte.com.cn> | 2017-08-30 12:48:56 +0800 |
commit | 3d0cf42925377db0d4a30c0cca9a89bf82e29677 (patch) | |
tree | 59122c5c4c488ea1d69f0015c5b8aefd609a82d5 | |
parent | 594b9753db26893801cfe2a45e21d03a63945194 (diff) |
Modify VFC catalog
Modify VFC catalog URL and add sql file
Change-Id: Ie49a0c6aefc4d41cd347d0ad4a955f39ef0970c9
Issue-ID: VFC-152
Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
-rw-r--r-- | catalog/packages/nf_package.py (renamed from catalog/packages/sdc_nf_package.py) | 10 | ||||
-rw-r--r-- | catalog/packages/ns_package.py (renamed from catalog/packages/sdc_ns_package.py) | 18 | ||||
-rw-r--r-- | catalog/packages/tests.py | 29 | ||||
-rw-r--r-- | catalog/packages/urls.py | 8 | ||||
-rw-r--r-- | catalog/packages/views.py | 24 | ||||
-rw-r--r-- | catalog/pub/database/models.py | 18 | ||||
-rw-r--r-- | resources/dbscripts/mysql/vfc-nfvo-catalog-createobj.sql | 70 |
7 files changed, 126 insertions, 51 deletions
diff --git a/catalog/packages/sdc_nf_package.py b/catalog/packages/nf_package.py index 57b60630..494d6e83 100644 --- a/catalog/packages/sdc_nf_package.py +++ b/catalog/packages/nf_package.py @@ -39,7 +39,7 @@ JOB_ERROR = 255 def nf_get_csars(): ret = None try: - ret = SdcNfPackage().get_csars() + ret = NfPackage().get_csars() except NSLCMException as e: return [1, e.message] except: @@ -50,7 +50,7 @@ def nf_get_csars(): def nf_get_csar(csar_id): ret = None try: - ret = SdcNfPackage().get_csar(csar_id) + ret = NfPackage().get_csar(csar_id) except NSLCMException as e: return [1, e.message] except: @@ -60,7 +60,7 @@ def nf_get_csar(csar_id): ##################################################################################### -class SdcNfDistributeThread(threading.Thread): +class NfDistributeThread(threading.Thread): """ Sdc NF Package Distribute """ @@ -139,7 +139,7 @@ class SdcNfDistributeThread(threading.Thread): ###################################################################################################################### -class SdcNfPkgDeleteThread(threading.Thread): +class NfPkgDeleteThread(threading.Thread): """ Sdc NF Package Deleting """ @@ -190,7 +190,7 @@ class SdcNfPkgDeleteThread(threading.Thread): ###################################################################################################################### -class SdcNfPackage(object): +class NfPackage(object): """ Actions for sdc nf package. """ diff --git a/catalog/packages/sdc_ns_package.py b/catalog/packages/ns_package.py index 094e20cd..ce05a814 100644 --- a/catalog/packages/sdc_ns_package.py +++ b/catalog/packages/ns_package.py @@ -40,13 +40,13 @@ def fmt_ns_pkg_rsp(status, desc, error_code="500"): def ns_on_distribute(csar_id): ret = None try: - ret = SdcNsPackage().on_distribute(csar_id) + ret = NsPackage().on_distribute(csar_id) except NSLCMException as e: - SdcNsPackage().delete_catalog(csar_id) + NsPackage().delete_catalog(csar_id) return fmt_ns_pkg_rsp(STATUS_FAILED, e.message) except: logger.error(traceback.format_exc()) - SdcNsPackage().delete_catalog(csar_id) + NsPackage().delete_catalog(csar_id) return fmt_ns_pkg_rsp(STATUS_FAILED, str(sys.exc_info())) return fmt_ns_pkg_rsp(STATUS_SUCCESS, ret[1], "") @@ -54,7 +54,7 @@ def ns_on_distribute(csar_id): def ns_delete_csar(csar_id, force_delete): ret = None try: - ret = SdcNsPackage().delete_csar(csar_id, force_delete) + ret = NsPackage().delete_csar(csar_id, force_delete) except NSLCMException as e: return fmt_ns_pkg_rsp(STATUS_FAILED, e.message) except: @@ -65,7 +65,7 @@ def ns_delete_csar(csar_id, force_delete): def ns_get_csars(): ret = None try: - ret = SdcNsPackage().get_csars() + ret = NsPackage().get_csars() except NSLCMException as e: return [1, e.message] except: @@ -76,7 +76,7 @@ def ns_get_csars(): def ns_get_csar(csar_id): ret = None try: - ret = SdcNsPackage().get_csar(csar_id) + ret = NsPackage().get_csar(csar_id) except NSLCMException as e: return [1, e.message] except: @@ -87,7 +87,7 @@ def ns_get_csar(csar_id): ############################################################################################################### -class SdcNsPackage(object): +class NsPackage(object): """ Actions for sdc ns package. """ @@ -143,10 +143,10 @@ class SdcNsPackage(object): def get_csars(self): - csars = {"csars": []} + csars = [] nss = NSDModel.objects.filter() for ns in nss: - csars["csars"].append({ + csars.append({ "csarId": ns.id, "nsdId": ns.nsd_id }) diff --git a/catalog/packages/tests.py b/catalog/packages/tests.py index ca95c50a..3e689193 100644 --- a/catalog/packages/tests.py +++ b/catalog/packages/tests.py @@ -38,29 +38,42 @@ class PackageTest(unittest.TestCase): def tearDown(self): pass + def test_nspackages_get(self): + response = self.client.get("/api/catalog/v1/nspackages") + print response + self.assertEqual(status.HTTP_200_OK, response.status_code, response.content) + def test_nspackage_get(self): - response = self.client.get("/api/nfvocatalog/v1/nspackages") + #response = self.client.get("/api/catalog/v1/nspackages/1") + #self.assertEqual(status.HTTP_200_OK, response.status_code, response.content) + # to do + pass + + def test_nfpackages_get(self): + response = self.client.get("/api/catalog/v1/vnfpackages") self.assertEqual(status.HTTP_200_OK, response.status_code, response.content) def test_nfpackage_get(self): - response = self.client.get("/api/nfvocatalog/v1/vnfpackages") - self.assertEqual(status.HTTP_200_OK, response.status_code, response.content) + #response = self.client.get("/api/catalog/v1/vnfpackages/1") + #self.assertEqual(status.HTTP_200_OK, response.status_code, response.content) + # to do + pass def test_ns_distribute(self): - response = self.client.post("/api/nfvocatalog/v1/nspackages",self.nsdata) + response = self.client.post("/api/catalog/v1/nspackages",self.nsdata) #self.assertEqual(status.HTTP_200_OK, response.status_code, response.content) def test_nf_distribute(self): - response = self.client.post("/api/nfvocatalog/v1/vnfpackages",self.nfdata) + #response = self.client.post("/api/catalog/v1/vnfpackages",self.nfdata) #self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content) - + pass def test_ns_package_delete(self): - response = self.client.delete("/api/nfvocatalog/v1/nspackages/" + str(self.ns_csarId)) + response = self.client.delete("/api/catalog/v1/nspackages/" + str(self.ns_csarId)) self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content) def test_nf_package_delete(self): - #response = self.client.delete("/api/nfvocatalog/v1/vnfpackages/" + str(self.nf_csarId)) + #response = self.client.delete("/api/catalog/v1/vnfpackages/" + str(self.nf_csarId)) #self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content) pass diff --git a/catalog/packages/urls.py b/catalog/packages/urls.py index 83dfc3fe..70bb8320 100644 --- a/catalog/packages/urls.py +++ b/catalog/packages/urls.py @@ -16,10 +16,10 @@ from django.conf.urls import include, url from catalog.packages import views urlpatterns = [ - url(r'^api/nfvocatalog/v1/nspackages$', views.nspackage_get, name='nspackages_get'), - url(r'^api/nfvocatalog/v1/nspackages/(?P<csarId>[0-9a-zA-Z\-\_]+)$', views.ns_rd_csar, name='nspackage_get'), - url(r'^api/nfvocatalog/v1/vnfpackages$', views.nspackage_get, name='nfpackages_get'), - url(r'^api/nfvocatalog/v1/vnfpackages/(?P<csarId>[0-9a-zA-Z\-\_]+)$', views.nf_rd_csar, name='nfpackage_get'), + url(r'^api/catalog/v1/nspackages$', views.nspackages_rc, name='nspackages_rc'), + url(r'^api/catalog/v1/nspackages/(?P<csarId>[0-9a-zA-Z\-\_]+)$', views.ns_rd_csar, name='nspackage_rd'), + url(r'^api/catalog/v1/vnfpackages$', views.nfpackages_rc, name='nfpackages_rc'), + url(r'^api/catalog/v1/vnfpackages/(?P<csarId>[0-9a-zA-Z\-\_]+)$', views.nf_rd_csar, name='nfpackage_rd'), ] diff --git a/catalog/packages/views.py b/catalog/packages/views.py index 99a49fd5..8d250be2 100644 --- a/catalog/packages/views.py +++ b/catalog/packages/views.py @@ -19,26 +19,26 @@ from rest_framework.response import Response from rest_framework import status from rest_framework.decorators import api_view from catalog.pub.utils.values import ignore_case_get -from catalog.packages import sdc_nf_package -from catalog.packages import sdc_ns_package +from catalog.packages import nf_package +from catalog.packages import ns_package logger = logging.getLogger(__name__) @api_view(http_method_names=['POST', 'GET']) -def nspackage_get(request, *args, **kwargs): +def nspackages_rc(request, *args, **kwargs): logger.debug("Enter %s, method is %s", fun_name(), request.method) ret, normal_status = None, None if request.method == 'GET': # Gets ns package list - ret = sdc_ns_package.SdcNsPackage().get_csars() + ret = ns_package.ns_get_csars(); normal_status = status.HTTP_200_OK elif request.method == 'POST': # Distributes the package accroding to the given csarId 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 = 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: @@ -46,18 +46,18 @@ def nspackage_get(request, *args, **kwargs): return Response(data=ret[1], status=normal_status) @api_view(http_method_names=['POST', 'GET']) -def nfpackage_get(request, *args, **kwargs): +def nfpackages_rc(request, *args, **kwargs): logger.debug("Enter %s%s, method is %s", fun_name(), request.data, request.method) ret, normal_status = None, None if request.method == 'GET': - ret = sdc_nf_package.nf_get_csars() + ret = nf_package.nf_get_csars() normal_status = status.HTTP_200_OK elif request.method == 'POST': csar_id = ignore_case_get(request.data, "csarId") vim_ids = ignore_case_get(request.data, "vimIds") lab_vim_id = ignore_case_get(request.data, "labVimId") job_id = str(uuid.uuid4()) - sdc_nf_package.SdcNfDistributeThread(csar_id, vim_ids, lab_vim_id, job_id).start() + nf_package.NfDistributeThread(csar_id, vim_ids, lab_vim_id, job_id).start() ret = [0, {"jobId": job_id}] normal_status = status.HTTP_202_ACCEPTED logger.debug("Leave %s, Return value is %s", fun_name(), ret) @@ -71,13 +71,13 @@ def ns_rd_csar(request, *args, **kwargs): logger.info("Enter %s, method is %s, csar_id is %s", fun_name(), request.method, csar_id) ret, normal_status = None, None if request.method == 'GET': - ret = sdc_ns_package.ns_get_csar(csar_id) + ret = ns_package.ns_get_csar(csar_id) normal_status = status.HTTP_200_OK elif request.method == 'DELETE': force_delete = csar_id.endswith("force") if force_delete: csar_id = csar_id[:-5] - ret = sdc_ns_package.ns_delete_csar(csar_id, force_delete) + ret = ns_package.ns_delete_csar(csar_id, force_delete) normal_status = status.HTTP_202_ACCEPTED logger.info("Leave %s, Return value is %s", fun_name(), str(ret)) if ret[0] != 0: @@ -90,14 +90,14 @@ def nf_rd_csar(request, *args, **kwargs): logger.info("Enter %s, method is %s, csar_id is %s", fun_name(), request.method, csar_id) ret, normal_status = None, None if request.method == 'GET': - ret = sdc_nf_package.nf_get_csar(csar_id) + ret = nf_package.nf_get_csar(csar_id) normal_status = status.HTTP_200_OK elif request.method == 'DELETE': force_delete = csar_id.endswith("force") if force_delete: csar_id = csar_id[:-5] job_id = str(uuid.uuid4()) - sdc_nf_package.SdcNfPkgDeleteThread(csar_id, job_id, force_delete).start() + nf_package.NfPkgDeleteThread(csar_id, job_id, force_delete).start() ret = [0, {"jobId": job_id}] normal_status = status.HTTP_202_ACCEPTED logger.info("Leave %s, Return value is %s", fun_name(), str(ret)) diff --git a/catalog/pub/database/models.py b/catalog/pub/database/models.py index 403189ee..83379cfb 100644 --- a/catalog/pub/database/models.py +++ b/catalog/pub/database/models.py @@ -15,9 +15,6 @@ from django.db import models class NSDModel(models.Model): - class Meta: - db_table = 'NFVO_NSPACKAGE' - id = models.CharField(db_column='ID', primary_key=True, max_length=200) nsd_id = models.CharField(db_column='NSDID', max_length=200) name = models.CharField(db_column='NAME', max_length=200) @@ -27,6 +24,9 @@ class NSDModel(models.Model): nsd_model = models.TextField(db_column='NSDMODEL', max_length=65535, null=True, blank=True) nsd_path = models.CharField(db_column='NSDPATH', max_length=300, null=True, blank=True) + class Meta: + db_table = 'NFVO_NSPACKAGE' + class NfPackageModel(models.Model): uuid = models.CharField(db_column='UUID', primary_key=True, max_length=255) nfpackageid = models.CharField(db_column='NFPACKAGEID', max_length=200) @@ -58,9 +58,6 @@ class VnfPackageFileModel(models.Model): class JobModel(models.Model): - class Meta: - db_table = 'NFVO_JOB' - jobid = models.CharField(db_column='JOBID', primary_key=True, max_length=255) jobtype = models.CharField(db_column='JOBTYPE', max_length=255) jobaction = models.CharField(db_column='JOBACTION', max_length=255) @@ -73,15 +70,15 @@ class JobModel(models.Model): parentjobid = models.CharField(db_column='PARENTJOBID', max_length=255, null=True, blank=True) resname = models.CharField(db_column='RESNAME', max_length=255, null=True, blank=True) + class Meta: + db_table = 'NFVO_JOB' + def toJSON(self): import json return json.dumps(dict([(attr, getattr(self, attr)) for attr in [f.name for f in self._meta.fields]])) class JobStatusModel(models.Model): - class Meta: - db_table = 'NFVO_JOB_STATUS' - indexid = models.IntegerField(db_column='INDEXID') jobid = models.CharField(db_column='JOBID', max_length=255) status = models.CharField(db_column='STATUS', max_length=255) @@ -90,6 +87,9 @@ class JobStatusModel(models.Model): errcode = models.CharField(db_column='ERRCODE', max_length=255, null=True, blank=True) addtime = models.CharField(db_column='ADDTIME', max_length=255, null=True, blank=True) + class Meta: + db_table = 'NFVO_JOB_STATUS' + def toJSON(self): import json return json.dumps(dict([(attr, getattr(self, attr)) for attr in [f.name for f in self._meta.fields]])) diff --git a/resources/dbscripts/mysql/vfc-nfvo-catalog-createobj.sql b/resources/dbscripts/mysql/vfc-nfvo-catalog-createobj.sql index 53b5b4f0..6aba3eee 100644 --- a/resources/dbscripts/mysql/vfc-nfvo-catalog-createobj.sql +++ b/resources/dbscripts/mysql/vfc-nfvo-catalog-createobj.sql @@ -16,8 +16,70 @@ use nfvocatalog; -DROP TABLE IF EXISTS NFVO_SAMPLE; -CREATE TABLE NFVO_SAMPLE ( - `SAMPLEID` varchar(255) NOT NULL PRIMARY KEY, - `SAMPLENAME` varchar(255) NOT NULL +DROP TABLE IF EXISTS NFVO_JOB; +CREATE TABLE NFVO_JOB ( + `JOBID` varchar(255) NOT NULL PRIMARY KEY, + `JOBTYPE` varchar (255) NOT NULL, + `JOBACTION` varchar(255) NOT NULL, + `RESID` varchar(255) NOT NULL, + `STATUS` integer NULL, + `STARTTIME` varchar(255) NULL, + `ENDTIME` varchar(255) NULL, + `PROGRESS` integer NULL, + `USER` varchar(255) NULL, + `PARENTJOBID` varchar(255) NULL, + `RESNAME` varchar(255) NULL ); + +DROP TABLE IF EXISTS NFVO_JOB_STATUS; +CREATE TABLE NFVO_JOB_STATUS ( + `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, + `INDEXID` integer NOT NULL, + `JOBID` varchar(255) NOT NULL, + `STATUS` varchar(255) NOT NULL, + `PROGRESS` integer NULL, + `DESCP` longtext NOT NULL, + `ERRCODE` varchar(255) NULL, + `ADDTIME` varchar(255) NULL +); + + +DROP TABLE IF EXISTS NFVO_NFPACKAGE; +CREATE TABLE NFVO_NFPACKAGE ( + `UUID` varchar(255) NOT NULL PRIMARY KEY, + `NFPACKAGEID` varchar(200) NOT NULL, + `VNFDID` varchar(255) NOT NULL, + `VENDOR` varchar(255) NOT NULL, + `VNFDVERSION` varchar(255) NOT NULL, + `VNFVERSION` varchar(255) NOT NULL, + `VNFDMODEL` longtext NULL, + `VNFDPATH` varchar(300) NULL +); + +DROP TABLE IF EXISTS NFVO_NSPACKAGE; +CREATE TABLE NFVO_NSPACKAGE ( + `ID` varchar(200) NOT NULL PRIMARY KEY, + `NSDID` varchar(200) NOT NULL, + `NAME` varchar(200) NOT NULL, + `VENDOR` varchar(200) NULL, + `DESCRIPTION` varchar(200) NULL, + `VERSION` varchar(200) NULL, + `NSDMODEL` longtext NULL, + `NSDPATH` varchar(300) NULL +); + + +DROP TABLE IF EXISTS NFVO_NFPACKAGEFILE; +CREATE TABLE NFVO_NFPACKAGEFILE ( + `ID` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, + `NFPACKAGEID` varchar(50) NOT NULL, + `FILENAME` varchar(100) NOT NULL, + `FILETYPE` varchar(2) NOT NULL, + `IMAGEID` varchar(50) NOT NULL, + `VIMID` varchar(50) NOT NULL, + `VIMUSER` varchar(50) NOT NULL, + `TENANT` varchar(50) NOT NULL, + `PURPOSE` varchar(1000) NOT NULL, + `STATUS` varchar(10) NOT NULL +); + |