summaryrefslogtreecommitdiffstats
path: root/zte/vmanager
diff options
context:
space:
mode:
Diffstat (limited to 'zte/vmanager')
-rw-r--r--zte/vmanager/driver/interfaces/serializers.py14
-rw-r--r--zte/vmanager/driver/interfaces/urls.py4
-rw-r--r--zte/vmanager/driver/interfaces/views.py93
-rw-r--r--zte/vmanager/tox.ini2
4 files changed, 67 insertions, 46 deletions
diff --git a/zte/vmanager/driver/interfaces/serializers.py b/zte/vmanager/driver/interfaces/serializers.py
index a19613ca..c9206579 100644
--- a/zte/vmanager/driver/interfaces/serializers.py
+++ b/zte/vmanager/driver/interfaces/serializers.py
@@ -97,6 +97,20 @@ class TerminateVnfRequestSerializer(serializers.Serializer):
required=False)
+class VnfInfoSerializer(serializers.Serializer):
+ vnfStatus = serializers.CharField(
+ help_text="vnfStatus",
+ required=True,
+ max_length=255,
+ allow_null=True)
+
+
+class QueryVnfResponseSerializer(serializers.Serializer):
+ vnfInfo = VnfInfoSerializer(
+ help_text="vnfInfo",
+ required=True)
+
+
class JobHistorySerializer(serializers.Serializer):
status = serializers.CharField(
help_text="Status of job",
diff --git a/zte/vmanager/driver/interfaces/urls.py b/zte/vmanager/driver/interfaces/urls.py
index 182b7478..e32e53ea 100644
--- a/zte/vmanager/driver/interfaces/urls.py
+++ b/zte/vmanager/driver/interfaces/urls.py
@@ -21,7 +21,7 @@ urlpatterns = [
url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/terminate$',
views.TerminateVnf.as_view(), name='terminate_vnf'),
url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)$',
- views.query_vnf, name='query_vnf'),
+ views.QueryVnf.as_view(), name='query_vnf'),
url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/jobs/(?P<jobid>[0-9a-zA-Z\-\_]+)$',
views.JobView.as_view(), name='operation_status'),
url(r'^api/ztevnfmdriver/v1/resource/grant$', views.GrantVnf.as_view(), name='grantvnf'),
@@ -30,5 +30,5 @@ urlpatterns = [
views.Scale.as_view(), name='scale'),
url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/heal$',
views.Heal.as_view(), name='heal'),
- url(r'^samples/$', views.samples, name='samples')
+ url(r'^samples/$', views.SampleList.as_view(), name='samples')
]
diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py
index 1a1976ed..5a978c63 100644
--- a/zte/vmanager/driver/interfaces/views.py
+++ b/zte/vmanager/driver/interfaces/views.py
@@ -21,13 +21,12 @@ import traceback
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
-from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.views import APIView
from driver.interfaces.serializers import HealReqSerializer, InstScaleHealRespSerializer, ScaleReqSerializer, \
NotifyReqSerializer, GrantRespSerializer, GrantReqSerializer, JobQueryRespSerializer, TerminateVnfRequestSerializer, \
- InstantiateVnfRequestSerializer
+ InstantiateVnfRequestSerializer, QueryVnfResponseSerializer
from driver.pub.config.config import VNF_FTP
from driver.pub.utils import restcall
from driver.pub.utils.restcall import req_by_msb
@@ -60,14 +59,6 @@ def ignorcase_get(args, key):
return ""
-def mapping_conv(keyword_map, rest_return):
- resp_data = {}
- for param in keyword_map:
- if keyword_map[param]:
- resp_data[keyword_map[param]] = ignorcase_get(rest_return, param)
- return resp_data
-
-
# Query vnfm_info from nslcm
def get_vnfminfo_from_nslcm(vnfmid):
ret = req_by_msb("api/nslcm/v1/vnfms/%s" % vnfmid, "GET")
@@ -143,11 +134,11 @@ class InstamtiateVnf(APIView):
data["VNFURL"] = data["VNFD"]
- for name, value in ignorcase_get(ignorcase_get(instantiateVnfRequestSerializer.data, "additionalParam"), "inputs").items():
+ additionalParam = ignorcase_get(instantiateVnfRequestSerializer.data, "additionalParam")
+ for name, value in ignorcase_get(additionalParam, "inputs").items():
inputs.append({"name": name, "value": value})
data["extension"]["inputs"] = json.dumps(inputs)
- additionalParam = ignorcase_get(instantiateVnfRequestSerializer.data, "additionalParam")
data["extension"]["extVirtualLinks"] = ignorcase_get(additionalParam, "extVirtualLinks")
data["extension"]["vnfinstancename"] = ignorcase_get(instantiateVnfRequestSerializer.data, "vnfInstanceName")
data["extension"]["vnfid"] = data["VNFD"]
@@ -177,6 +168,7 @@ class InstamtiateVnf(APIView):
if not instRespSerializer.is_valid():
raise Exception(instRespSerializer.errors)
+ logger.debug("[%s] instRespSerializer.data=%s", fun_name(), instRespSerializer.data)
return Response(data=instRespSerializer.data, status=status.HTTP_200_OK)
except Exception as e:
logger.error("Error occurred when instantiating VNF,error:%s", e.message)
@@ -232,34 +224,45 @@ class TerminateVnf(APIView):
return Response(data={'error': 'TerminateVnf expection'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-@api_view(http_method_names=['GET'])
-def query_vnf(request, *args, **kwargs):
- try:
- logger.debug("[%s] request.data=%s", fun_name(), request.data)
- vnfm_id = ignorcase_get(kwargs, "vnfmid")
- ret = get_vnfminfo_from_nslcm(vnfm_id)
- if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
- vnfm_info = json.JSONDecoder().decode(ret[1])
- logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info)
- ret = restcall.call_req(
- base_url=ignorcase_get(vnfm_info, "url"),
- user=ignorcase_get(vnfm_info, "userName"),
- passwd=ignorcase_get(vnfm_info, "password"),
- auth_type=restcall.rest_no_auth,
- resource="v1/vnfs/%s" % (ignorcase_get(kwargs, "vnfInstanceID")),
- method='get',
- content=json.JSONEncoder().encode({}))
- if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
- resp = json.JSONDecoder().decode(ret[1])
- vnf_status = ignorcase_get(resp, "vnfinstancestatus")
- resp_data = {"vnfInfo": {"vnfStatus": vnf_status}}
- logger.debug("[%s]resp_data=%s", fun_name(), resp_data)
- except Exception as e:
- logger.error("Error occurred when querying VNF information.")
- raise e
- return Response(data=resp_data, status=ret[2])
+class QueryVnf(APIView):
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: QueryVnfResponseSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ }
+ )
+ def get(self, request, vnfmid, vnfInstanceId):
+ try:
+ logger.debug("[%s] request.data=%s", fun_name(), request.data)
+ ret = get_vnfminfo_from_nslcm(vnfmid)
+ if ret[0] != 0:
+ raise Exception(ret[1])
+
+ vnfm_info = json.JSONDecoder().decode(ret[1])
+ logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info)
+ ret = restcall.call_req(
+ base_url=ignorcase_get(vnfm_info, "url"),
+ user=ignorcase_get(vnfm_info, "userName"),
+ passwd=ignorcase_get(vnfm_info, "password"),
+ auth_type=restcall.rest_no_auth,
+ resource="v1/vnfs/%s" % vnfInstanceId,
+ method='get',
+ content=json.JSONEncoder().encode({}))
+ if ret[0] != 0:
+ raise Exception(ret[1])
+
+ resp = json.JSONDecoder().decode(ret[1])
+ vnf_status = ignorcase_get(resp, "vnfinstancestatus")
+ resp_data = {"vnfInfo": {"vnfStatus": vnf_status}}
+ logger.debug("[%s]resp_data=%s", fun_name(), resp_data)
+ queryVnfResponseSerializer = QueryVnfResponseSerializer(data=resp_data)
+ if not queryVnfResponseSerializer.is_valid():
+ raise Exception(queryVnfResponseSerializer.errors)
+ return Response(data=queryVnfResponseSerializer.data, status=status.HTTP_200_OK)
+ except Exception as e:
+ logger.error("Error occurred when querying VNF information,error:%s", e.message)
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'QueryVnf expection'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class JobView(APIView):
@@ -608,6 +611,10 @@ def get_vdus(nf_model, aspect_id):
return members
-@api_view(http_method_names=['GET'])
-def samples(request, *args, **kwargs):
- return Response(data={"status": "ok"})
+class SampleList(APIView):
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: 'Successfully'})
+ def get(self, request):
+ logger.debug("get")
+ return Response({"status": "active"})
diff --git a/zte/vmanager/tox.ini b/zte/vmanager/tox.ini
index 2d18a624..3bbe6c8a 100644
--- a/zte/vmanager/tox.ini
+++ b/zte/vmanager/tox.ini
@@ -19,4 +19,4 @@ commands =
{[testenv]commands}
[testenv:cov]
-commands = coverage html --omit="*test_*,*__init__.py,*site-packages*" -d htmlcov \ No newline at end of file
+commands = coverage html --omit="*test*,*__init__.py,*site-packages*" -d htmlcov \ No newline at end of file