summaryrefslogtreecommitdiffstats
path: root/gvnfmadapter
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-09-22 09:49:41 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-09-22 09:49:41 +0800
commit660501651e8455c0d4cbcfc634d051d45601115f (patch)
tree33a6a99ef24ca2a0d086fd8a388bbd56c5b4738e /gvnfmadapter
parent4f52c498126d28f6d660a73f578d05c1d6d343df (diff)
Modify gvnfmadapter code according to PEP8
Change-Id: Ib279a2fbab173c7ede94ed92f6ecd7369817de65 Issue-ID: VFC-415 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'gvnfmadapter')
-rw-r--r--gvnfmadapter/driver/interfaces/urls.py3
-rw-r--r--gvnfmadapter/driver/interfaces/views.py51
-rw-r--r--gvnfmadapter/driver/pub/config/config.py7
-rw-r--r--gvnfmadapter/driver/pub/database/__init__.py13
-rw-r--r--gvnfmadapter/driver/pub/database/models.py13
-rw-r--r--gvnfmadapter/driver/pub/utils/restcall.py1
-rw-r--r--gvnfmadapter/driver/settings.py14
-rw-r--r--gvnfmadapter/driver/swagger/tests.py3
-rw-r--r--gvnfmadapter/driver/swagger/views.py4
-rw-r--r--gvnfmadapter/driver/urls.py2
-rw-r--r--gvnfmadapter/driver/wsgi.py1
-rwxr-xr-xgvnfmadapter/run.sh1
-rwxr-xr-xgvnfmadapter/stop.sh1
13 files changed, 12 insertions, 102 deletions
diff --git a/gvnfmadapter/driver/interfaces/urls.py b/gvnfmadapter/driver/interfaces/urls.py
index 054572c..71b5608 100644
--- a/gvnfmadapter/driver/interfaces/urls.py
+++ b/gvnfmadapter/driver/interfaces/urls.py
@@ -26,4 +26,5 @@ urlpatterns = [
views.operation_status, name='operation_status'),
url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/vnfpackages$', views.get_vnfpkgs, name='get_vnfpkgs'),
url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/resource/grant$', views.grantvnf, name='grantvnf'),
- url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/vnfs/lifecyclechangesnotification$', views.notify, name='notify'),]
+ url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/vnfs/lifecyclechangesnotification$', views.notify, name='notify')
+]
diff --git a/gvnfmadapter/driver/interfaces/views.py b/gvnfmadapter/driver/interfaces/views.py
index ac3ac27..7d521e8 100644
--- a/gvnfmadapter/driver/interfaces/views.py
+++ b/gvnfmadapter/driver/interfaces/views.py
@@ -81,7 +81,6 @@ def set_createvnf_params(data):
input_data["vnfdId"] = ignorcase_get(data,"vnfDescriptorId")
input_data["vnfInstanceName"] = ignorcase_get(data, "vnfInstanceName")
input_data["vnfInstanceDescription"] = ignorcase_get(data, "vnfInstanceDescription")
-
return input_data
def set_instantvnf_params(data):
@@ -90,23 +89,16 @@ def set_instantvnf_params(data):
input_data["extVirtualLinks"] = ignorcase_get(data, "extVirtualLink")
input_data["additionalParams"] = ignorcase_get(data,"additionalParams")
input_data["flavourId"] = ignorcase_get(data,"flavourId")
-
return input_data
def set_terminatevnf_params(data):
input_data = {}
input_data["terminationType"] = ignorcase_get(data,"terminationType")
input_data["gracefulTerminationTimeout"] = ignorcase_get(data,"gracefulTerminationTimeout")
-
return input_data
-def set_deletevnf_params(data):
- pass
-
-
def get_inst_levelId(vnfdId):
inst_levelId = 0
-
return inst_levelId
# Query vnfm info from nslcm
@@ -127,8 +119,6 @@ def get_vnfm_info(vnfm_id):
logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info)
return 0, vnfm_info
-
-
def call_vnfm_rest(vnfm_info, input_data, res_url, call_method = "post"):
ret = restcall.call_req(
base_url=ignorcase_get(vnfm_info, "url"),
@@ -138,7 +128,6 @@ def call_vnfm_rest(vnfm_info, input_data, res_url, call_method = "post"):
resource=res_url,
method=call_method,
content=json.JSONEncoder().encode(input_data))
-
return ret
def call_vnfm_createvnf(vnfm_info, input_data):
@@ -160,7 +149,6 @@ def call_vnfm_operation_status(vnfm_info, jobId, responseId = None):
return call_vnfm_rest(vnfm_info, None, operation_status_url % (jobId, responseId), "get")
def wait4job(vnfm_id,jobId,gracefulTerminationTimeout):
-
begin_time = time.time()
try:
ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
@@ -187,10 +175,8 @@ def wait4job(vnfm_id,jobId,gracefulTerminationTimeout):
logger.error("Error occurred when do_createvnf")
return 255, Response(data={"error":"Exception caught! Fail to get job status!"}, status=status.HTTP_412_PRECONDITION_FAILED)
-
def do_createvnf(request, data, vnfm_id):
logger.debug("[%s] request.data=%s", fun_name(), request.data)
-
try:
ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
if ret != 0:
@@ -204,12 +190,10 @@ def do_createvnf(request, data, vnfm_id):
except Exception as e:
logger.error("Error occurred when do_createvnf")
raise e
-
return 0, resp
def do_instvnf(vnfInstanceId, request, data, vnfm_id):
logger.debug("[%s] request.data=%s", fun_name(), request.data)
-
try:
ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
if ret != 0:
@@ -223,7 +207,6 @@ def do_instvnf(vnfInstanceId, request, data, vnfm_id):
except Exception as e:
logger.error("Error occurred when do_instvnf")
raise e
-
return 0, resp
def do_terminatevnf(request, data, vnfm_id, vnfInstanceId):
@@ -232,7 +215,6 @@ def do_terminatevnf(request, data, vnfm_id, vnfInstanceId):
ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
if ret != 0:
return ret,vnfm_info
-
ret = call_vnfm_terminatevnf(vnfm_info, data, vnfInstanceId)
if ret[0] != 0:
return 255, Response(data={'error': ret[1]}, status=ret[2])
@@ -241,19 +223,15 @@ def do_terminatevnf(request, data, vnfm_id, vnfInstanceId):
except Exception as e:
logger.error("Error occurred when do_terminatevnf")
raise e
-
return 0, resp_data
def do_deletevnf(request, vnfm_id, vnfInstanceId):
logger.debug("[%s] request.data=%s", fun_name(), request.data)
- input_data = set_deletevnf_params(request.data)
try:
ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
if ret != 0:
return ret, vnfm_info
-
ret = call_vnfm_deletevnf(vnfm_info, vnfInstanceId)
-
if ret[0] != 0:
return 255, Response(data={'error': ret[1]}, status=ret[2])
resp_data = json.JSONDecoder().decode(ret[1])
@@ -269,9 +247,7 @@ def do_queryvnf(request, vnfm_id, vnfInstanceId):
ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
if ret != 0:
return ret, vnfm_info
-
ret = call_vnfm_queryvnf(vnfm_info, vnfInstanceId)
-
if ret[0] != 0:
return 255, Response(data={'error': ret[1]}, status=ret[2])
resp_data = json.JSONDecoder().decode(ret[1])
@@ -289,26 +265,21 @@ def instantiate_vnf(request, *args, **kwargs):
ret, resp = do_createvnf(request, input_data, vnfm_id)
if ret != 0:
return resp
-
logger.info("[%s]resp_data=%s", fun_name(), resp)
vnfInstanceId = resp["vnfInstanceId"]
logger.info("[%s]vnfInstanceId=%s", fun_name(), vnfInstanceId)
-
input_data = set_instantvnf_params(request.data)
ret, resp = do_instvnf(vnfInstanceId, request, input_data, vnfm_id)
if ret != 0:
return resp
-
resp_data = {"jobId":"", "vnfInstanceId":""}
resp_data["vnfInstanceId"] = vnfInstanceId
resp_data["jobId"] = resp["vnfLcOpId"]
except Exception as e:
logger.error("Error occurred when instantiating VNF")
raise e
-
return Response(data=resp_data, status=status.HTTP_201_CREATED)
-
@api_view(http_method_names=['POST'])
def terminate_vnf(request, *args, **kwargs):
vnfm_id = ignorcase_get(kwargs, "vnfmid")
@@ -318,21 +289,17 @@ def terminate_vnf(request, *args, **kwargs):
ret, resp = do_terminatevnf(request, input_data, vnfm_id, vnfInstanceId)
if ret != 0:
return resp
-
jobId = ignorcase_get(resp, "vnfLcOpId")
gracefulTerminationTimeout = ignorcase_get(request.data, "gracefulTerminationTimeout")
ret, response = wait4job(vnfm_id,jobId,gracefulTerminationTimeout)
if ret != 0:
return response
-
ret, resp = do_deletevnf(request, vnfm_id, vnfInstanceId)
if ret != 0:
return resp
-
except Exception as e:
logger.error("Error occurred when terminating VNF")
raise e
-
return Response(data=resp, status=status.HTTP_204_NO_CONTENT)
@api_view(http_method_names=['GET'])
@@ -344,7 +311,6 @@ def query_vnf(request, *args, **kwargs):
ret, resp = do_queryvnf(request, vnfm_id, vnfInstanceId)
if ret != 0:
return resp
-
resp_response_data = mapping_conv(query_vnf_resp_mapping, ignorcase_get(resp, "ResponseInfo"))
resp_data = {
"vnfInfo":resp_response_data
@@ -362,9 +328,6 @@ def query_vnf(request, *args, **kwargs):
raise e
return Response(data=resp_data, status=status.HTTP_200_OK)
-# ==================================================
-
-
@api_view(http_method_names=['GET'])
def operation_status(request, *args, **kwargs):
data = {}
@@ -373,14 +336,11 @@ def operation_status(request, *args, **kwargs):
vnfm_id = ignorcase_get(kwargs, "vnfmid")
jobId = ignorcase_get(kwargs, "jobId")
responseId = ignorcase_get(kwargs, "responseId")
-
ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
if ret != 0:
return Response(data={'error': ret[1]}, status=ret[2])
logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info)
-
ret = call_vnfm_operation_status(vnfm_info, jobId, responseId)
-
if ret[0] != 0:
return Response(data={'error': ret[1]}, status=ret[2])
resp_data = json.JSONDecoder().decode(ret[1])
@@ -395,23 +355,18 @@ def operation_status(request, *args, **kwargs):
operation_data["responseDescriptor"]["errorCode"] = ignorcase_get(ignorcase_get(ResponseInfo, "responseDescriptor"),"errorCode")
operation_data["responseDescriptor"]["responseId"] = ignorcase_get(ignorcase_get(ResponseInfo, "responseDescriptor"),"responseId")
operation_data["responseDescriptor"]["responseHistoryList"] = ignorcase_get(ignorcase_get(ResponseInfo, "responseDescriptor"),"responseHistoryList")
-
except Exception as e:
logger.error("Error occurred when getting operation status information.")
raise e
return Response(data=operation_data, status=status.HTTP_200_OK)
-
-# ==================================================
-grant_vnf_url = 'api/nslcm/v1/grantvnf'
-
@api_view(http_method_names=['PUT'])
def grantvnf(request, *args, **kwargs):
logger.info("=====grantvnf=====")
try:
resp_data = {}
logger.info("req_data = %s", request.data)
- ret = req_by_msb(grant_vnf_url, "POST", content=json.JSONEncoder().encode(request.data))
+ ret = req_by_msb('api/nslcm/v1/grantvnf', "POST", content=json.JSONEncoder().encode(request.data))
logger.info("ret = %s", ret)
if ret[0] != 0:
return Response(data={'error': ret[1]}, status=ret[2])
@@ -424,10 +379,6 @@ def grantvnf(request, *args, **kwargs):
raise e
return Response(data=resp_data, status=ret[2])
-
-# ==================================================
-
-
@api_view(http_method_names=['POST'])
def notify(request, *args, **kwargs):
try:
diff --git a/gvnfmadapter/driver/pub/config/config.py b/gvnfmadapter/driver/pub/config/config.py
index ab143a1..aef1de7 100644
--- a/gvnfmadapter/driver/pub/config/config.py
+++ b/gvnfmadapter/driver/pub/config/config.py
@@ -13,14 +13,9 @@
# limitations under the License.
# [AAI]
-AAI_SERVICE_IP = '127.0.0.1'
-AAI_SERVICE_PORT = '8443'
-AAI_BASE_URL = "https://%s:%s/aai/v11" % (AAI_SERVICE_IP, AAI_SERVICE_PORT)
+AAI_BASE_URL = "https://127.0.0.1:8443/aai/v11"
AAI_USER = "AAI"
AAI_PASSWORD = "AAI"
-CLOUD_OWNER = ""
-CLOUD_REGION_ID = ""
-TENANT_ID = ""
# [MSB]
MSB_SERVICE_IP = '127.0.0.1'
diff --git a/gvnfmadapter/driver/pub/database/__init__.py b/gvnfmadapter/driver/pub/database/__init__.py
deleted file mode 100644
index c7b6818..0000000
--- a/gvnfmadapter/driver/pub/database/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright 2017 ZTE Corporation.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
diff --git a/gvnfmadapter/driver/pub/database/models.py b/gvnfmadapter/driver/pub/database/models.py
deleted file mode 100644
index c7b6818..0000000
--- a/gvnfmadapter/driver/pub/database/models.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright 2017 ZTE Corporation.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
diff --git a/gvnfmadapter/driver/pub/utils/restcall.py b/gvnfmadapter/driver/pub/utils/restcall.py
index 0cb7ed4..4280e73 100644
--- a/gvnfmadapter/driver/pub/utils/restcall.py
+++ b/gvnfmadapter/driver/pub/utils/restcall.py
@@ -94,6 +94,7 @@ def combine_url(base_url, resource):
full_url = base_url + '/' + resource
return full_url
+
def call_req_aai(base_url, user, passwd, auth_type, resource, method, content=''):
callid = str(uuid.uuid1())
logger.debug("[%s]call_req('%s','%s','%s',%s,'%s','%s','%s')" % (
diff --git a/gvnfmadapter/driver/settings.py b/gvnfmadapter/driver/settings.py
index 520fe37..882d28a 100644
--- a/gvnfmadapter/driver/settings.py
+++ b/gvnfmadapter/driver/settings.py
@@ -40,7 +40,6 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
- 'driver.pub.database',
'driver.interfaces'
]
@@ -66,20 +65,9 @@ REST_FRAMEWORK = {
'DEFAULT_PARSER_CLASSES': (
'rest_framework.parsers.MultiPartParser',
- 'rest_framework.parsers.JSONParser')}
-"""
-DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.mysql',
- 'NAME': 'vmanager',
- 'HOST': 'localhost',
- 'USER': 'root',
- 'PASSWORD':'password',
- },
+ 'rest_framework.parsers.JSONParser')
}
-redis_client = redis.StrictRedis(host='127.0.0.1', port=6379, password='', db=1)
-"""
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
diff --git a/gvnfmadapter/driver/swagger/tests.py b/gvnfmadapter/driver/swagger/tests.py
index 3104b18..62251fc 100644
--- a/gvnfmadapter/driver/swagger/tests.py
+++ b/gvnfmadapter/driver/swagger/tests.py
@@ -13,7 +13,7 @@
# limitations under the License.
import unittest
-import json
+
from django.test import Client
from rest_framework import status
@@ -28,4 +28,3 @@ class SwaggerViewTest(unittest.TestCase):
def test_sample(self):
response = self.client.get("/api/gvnfmdriver/v1/swagger.json")
self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
-
diff --git a/gvnfmadapter/driver/swagger/views.py b/gvnfmadapter/driver/swagger/views.py
index e9c9604..e3de4f6 100644
--- a/gvnfmadapter/driver/swagger/views.py
+++ b/gvnfmadapter/driver/swagger/views.py
@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
import os
import json
from rest_framework.views import APIView
@@ -18,9 +19,6 @@ from rest_framework.response import Response
class SwaggerView(APIView):
- """
- Show rest api swagger.
- """
def get(self, request, format=None):
json_file = os.path.join(os.path.dirname(__file__), 'swagger.json')
f = open(json_file)
diff --git a/gvnfmadapter/driver/urls.py b/gvnfmadapter/driver/urls.py
index 86f1fc3..7eb2ce6 100644
--- a/gvnfmadapter/driver/urls.py
+++ b/gvnfmadapter/driver/urls.py
@@ -14,6 +14,8 @@
from driver.pub.config.config import REG_TO_MSB_WHEN_START, REG_TO_MSB_REG_URL, REG_TO_MSB_REG_PARAM
from django.conf.urls import include, url
+
+
urlpatterns = [
url(r'^', include('driver.interfaces.urls')),
url(r'^', include('driver.swagger.urls')),
diff --git a/gvnfmadapter/driver/wsgi.py b/gvnfmadapter/driver/wsgi.py
index 1008e32..713c527 100644
--- a/gvnfmadapter/driver/wsgi.py
+++ b/gvnfmadapter/driver/wsgi.py
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-
import os
from django.core.wsgi import get_wsgi_application
diff --git a/gvnfmadapter/run.sh b/gvnfmadapter/run.sh
index b107ce3..49b574e 100755
--- a/gvnfmadapter/run.sh
+++ b/gvnfmadapter/run.sh
@@ -12,4 +12,5 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
nohup python manage.py runserver 0.0.0.0:8484 > /dev/null &
diff --git a/gvnfmadapter/stop.sh b/gvnfmadapter/stop.sh
index cf34a42..b514403 100755
--- a/gvnfmadapter/stop.sh
+++ b/gvnfmadapter/stop.sh
@@ -12,4 +12,5 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
ps auxww | grep 'manage.py runserver 0.0.0.0:8484' | awk '{print $2}' | xargs kill -9