summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-02-07 09:51:53 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-02-07 09:51:53 +0800
commitbbda034c33755886b4e2e266fd7863a1038b5931 (patch)
tree5d4ddbbd459da8fcfa4bb9da6b66cb8e08456949
parent909d60f4cc068574b058cdc2b955b90b2ce8660d (diff)
Add vfc-ztevnfmdriver scale auto-swagger
Change-Id: I566173110641ec8c50f4ee1c9fd080a073318e37 Issue-ID: VFC-736 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--zte/vmanager/driver/interfaces/urls.py2
-rw-r--r--zte/vmanager/driver/interfaces/views.py87
2 files changed, 47 insertions, 42 deletions
diff --git a/zte/vmanager/driver/interfaces/urls.py b/zte/vmanager/driver/interfaces/urls.py
index 07df352b..814b4990 100644
--- a/zte/vmanager/driver/interfaces/urls.py
+++ b/zte/vmanager/driver/interfaces/urls.py
@@ -27,7 +27,7 @@ urlpatterns = [
url(r'^api/ztevnfmdriver/v1/resource/grant$', views.grantvnf, name='grantvnf'),
url(r'^api/ztevnfmdriver/v1/vnfs/lifecyclechangesnotification$', views.notify, name='notify'),
url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/scale$',
- views.scale, name='scale'),
+ 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')
diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py
index 949949b4..820cd823 100644
--- a/zte/vmanager/driver/interfaces/views.py
+++ b/zte/vmanager/driver/interfaces/views.py
@@ -24,7 +24,7 @@ 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
+from driver.interfaces.serializers import HealReqSerializer, InstScaleHealRespSerializer, ScaleReqSerializer
from driver.pub.config.config import VNF_FTP
from driver.pub.utils import restcall
from driver.pub.utils.restcall import req_by_msb
@@ -393,48 +393,53 @@ def notify(request, *args, **kwargs):
return Response(data=None, status=ret[2])
-@api_view(http_method_names=['POST'])
-def scale(request, *args, **kwargs):
- logger.info("====scale_vnf===")
- try:
- logger.info("request.data = %s", request.data)
- logger.info("requested_url = %s", request.get_full_path())
- vnfm_id = ignorcase_get(kwargs, "vnfmid")
- nf_instance_id = ignorcase_get(kwargs, "vnfInstanceId")
- 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])
- scale_type = ignorcase_get(request.data, "type")
- aspect_id = ignorcase_get(request.data, "aspectId")
- number_of_steps = ignorcase_get(request.data, "numberOfSteps")
- data = {
- 'vnfmid': vnfm_id,
- 'nfvoid': 1,
- 'scaletype': '0' if scale_type == 'SCALE_OUT' else '1',
- 'vmlist': [{'VMNumber': number_of_steps, 'VMFlavor': aspect_id}],
- 'extension': ''
+class Scale(APIView):
+ @swagger_auto_schema(
+ request_body=ScaleReqSerializer(),
+ responses={
+ status.HTTP_202_ACCEPTED: InstScaleHealRespSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
}
+ )
+ def post(self, request, vnfmid, vnfInstanceId):
+ logger.info("====scale_vnf===")
+ try:
+ logger.info("request.data = %s", request.data)
+ logger.info("requested_url = %s", request.get_full_path())
+ ret = get_vnfminfo_from_nslcm(vnfmid)
+ if ret[0] != 0:
+ return Response(data={'error': ret[1]}, status=ret[2])
+ vnfm_info = json.JSONDecoder().decode(ret[1])
+ scale_type = ignorcase_get(request.data, "type")
+ aspect_id = ignorcase_get(request.data, "aspectId")
+ number_of_steps = ignorcase_get(request.data, "numberOfSteps")
+ data = {
+ 'vnfmid': vnfmid,
+ 'nfvoid': 1,
+ 'scaletype': '0' if scale_type == 'SCALE_OUT' else '1',
+ 'vmlist': [{'VMNumber': number_of_steps, 'VMFlavor': aspect_id}],
+ 'extension': ''
+ }
- logger.info("data = %s", data)
- 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/{vnfInstanceID}/scale'.format(vnfInstanceID=nf_instance_id),
- method='put', # POST
- content=json.JSONEncoder().encode(data))
- logger.info("ret=%s", ret)
- if ret[0] != 0:
- return Response(data={'error': 'scale error'}, status=ret[2])
- resp_data = json.JSONDecoder().decode(ret[1])
- logger.info("resp_data=%s", resp_data)
- except Exception as e:
- logger.error("Error occurred when scaling VNF,error:%s", e.message)
- logger.error(traceback.format_exc())
- return Response(data={'error': 'scale expection'}, status='500')
- return Response(data=resp_data, status=ret[2])
+ logger.info("data = %s", data)
+ 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/{vnfInstanceID}/scale'.format(vnfInstanceID=vnfInstanceId),
+ method='put', # POST
+ content=json.JSONEncoder().encode(data))
+ logger.info("ret=%s", ret)
+ if ret[0] != 0:
+ return Response(data={'error': 'scale error'}, status=ret[2])
+ resp_data = json.JSONDecoder().decode(ret[1])
+ logger.info("resp_data=%s", resp_data)
+ return Response(data=resp_data, status=status.HTTP_202_ACCEPTED)
+ except Exception as e:
+ logger.error("Error occurred when scaling VNF,error:%s", e.message)
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'scale expection'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class Heal(APIView):